-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More Specifier and SpecifierSet tests
- Loading branch information
1 parent
7865467
commit 6a04147
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import pytest | ||
|
||
from packaging.specifiers import SpecifierSet | ||
from packaging.version import Version | ||
|
||
|
||
class TestSpeicifierSet: | ||
@pytest.mark.parametrize( | ||
("specifier", "specifier_prereleases", "prereleases", "input", "expected"), | ||
[ | ||
# General test of the filter method | ||
("", None, None, ["1.0", "2.0a1"], ["1.0"]), | ||
(">=1.0.dev1", None, None, ["1.0", "2.0a1"], ["1.0", "2.0a1"]), | ||
("", None, None, ["1.0a1"], ["1.0a1"]), | ||
(">=1.2.3", None, None, ["1.2", "1.5a1"], ["1.5a1"]), | ||
(">=1.2.3", None, None, ["1.3", "1.5a1"], ["1.3"]), | ||
("", None, None, ["1.0", Version("2.0")], ["1.0", Version("2.0")]), | ||
(">=1.0", None, None, ["2.0a1"], ["2.0a1"]), | ||
("!=2.0a1", None, None, ["1.0a2", "1.0", "2.0a1"], ["1.0"]), | ||
("==2.0a1", None, None, ["2.0a1"], ["2.0a1"]), | ||
(">2.0a1", None, None, ["2.0a1", "3.0a2", "3.0"], ["3.0a2", "3.0"]), | ||
("<2.0a1", None, None, ["1.0a2", "1.0", "2.0a1"], ["1.0a2", "1.0"]), | ||
("~=2.0a1", None, None, ["1.0", "2.0a1", "3.0a2", "3.0"], ["2.0a1"]), | ||
# Test overriding with the prereleases parameter on filter | ||
("", None, False, ["1.0a1"], []), | ||
(">=1.0.dev1", None, False, ["1.0", "2.0a1"], ["1.0"]), | ||
("", None, True, ["1.0", "2.0a1"], ["1.0", "2.0a1"]), | ||
# Test overriding with the overall specifier | ||
("", True, None, ["1.0", "2.0a1"], ["1.0", "2.0a1"]), | ||
("", False, None, ["1.0", "2.0a1"], ["1.0"]), | ||
(">=1.0.dev1", True, None, ["1.0", "2.0a1"], ["1.0", "2.0a1"]), | ||
(">=1.0.dev1", False, None, ["1.0", "2.0a1"], ["1.0"]), | ||
("", True, None, ["1.0a1"], ["1.0a1"]), | ||
("", False, None, ["1.0a1"], []), | ||
], | ||
) | ||
def test_specifier_filter( | ||
self, specifier_prereleases, specifier, prereleases, input, expected | ||
): | ||
if specifier_prereleases is None: | ||
spec = SpecifierSet(specifier) | ||
else: | ||
spec = SpecifierSet(specifier, prereleases=specifier_prereleases) | ||
|
||
kwargs = {"prereleases": prereleases} if prereleases is not None else {} | ||
|
||
assert list(spec.filter(input, **kwargs)) == expected |