Skip to content

Commit

Permalink
Make it harder to omit a locator test by mistake
Browse files Browse the repository at this point in the history
The test parametrization zips the input with the expected output. Zip
stops when the shortest iterable ends. That means if the input and
output lists have different lengths, cases can be omitted accidentally.

zip(..., strict=True) would solve this on python>=3.10

We support python 3.9, so instead use zip_longest, which will "pad" the
shorter list with None

Signed-off-by: Adam Cmiel <[email protected]>
  • Loading branch information
chmeliik committed Oct 10, 2023
1 parent 420a38a commit c53b7b2
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tests/unit/package_managers/yarn/test_locators.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
from itertools import zip_longest
from pathlib import Path

import pytest
Expand Down Expand Up @@ -410,7 +411,7 @@
"locator_str, expect_parsed_locator, expect_parsed_reference",
[
(locator_str, parsed_locator, parsed_reference)
for locator_str, (parsed_locator, parsed_reference) in zip(
for locator_str, (parsed_locator, parsed_reference) in zip_longest(
ALL_LOCATORS, PARSED_LOCATORS_AND_REFERENCES
)
],
Expand Down Expand Up @@ -457,7 +458,7 @@ def test_unexpected_reference_format() -> None:


@pytest.mark.parametrize(
"locator_str, expect_locator", zip(SUPPORTED_LOCATORS, PARSED_SUPPORTED_LOCATORS)
"locator_str, expect_locator", zip_longest(SUPPORTED_LOCATORS, PARSED_SUPPORTED_LOCATORS)
)
def test_parse_locator(locator_str: str, expect_locator: Locator) -> None:
assert parse_locator(locator_str) == expect_locator
Expand Down

0 comments on commit c53b7b2

Please sign in to comment.