|
20 | 20 | default_environment,
|
21 | 21 | format_full_version,
|
22 | 22 | )
|
23 |
| -from packaging.version import InvalidVersion |
24 | 23 |
|
25 | 24 | VARIABLES = [
|
26 | 25 | "extra",
|
@@ -388,12 +387,38 @@ def test_extra_str_normalization(self):
|
388 | 387 | assert str(Marker(rhs)) == f'extra == "{normalized_name}"'
|
389 | 388 |
|
390 | 389 | def test_python_full_version_untagged_user_provided(self):
|
391 |
| - """A user-provided python_full_version ending with a + fails to parse.""" |
392 |
| - with pytest.raises(InvalidVersion): |
393 |
| - Marker("python_full_version < '3.12'").evaluate( |
394 |
| - {"python_full_version": "3.11.1+"} |
395 |
| - ) |
| 390 | + """A user-provided python_full_version ending with a + uses Python behaviour.""" |
| 391 | + env = {"python_full_version": "3.11.1+"} |
| 392 | + assert Marker("python_full_version < '3.12'").evaluate(env) |
396 | 393 |
|
397 | 394 | def test_python_full_version_untagged(self):
|
398 | 395 | with mock.patch("platform.python_version", return_value="3.11.1+"):
|
399 | 396 | assert Marker("python_full_version < '3.12'").evaluate()
|
| 397 | + |
| 398 | + @pytest.mark.parametrize( |
| 399 | + ("marker_string", "environment", "expected"), |
| 400 | + [ |
| 401 | + ("platform_release >= '20.0'", {"platform_release": "21-foobar"}, True), |
| 402 | + ("platform_release >= '8'", {"platform_release": "6.7.0-gentoo"}, False), |
| 403 | + ("platform_version == '27'", {"platform_version": "weird string"}, False), |
| 404 | + ( |
| 405 | + "implementation_version == '3.*'", |
| 406 | + {"implementation_version": "2_private"}, |
| 407 | + False, |
| 408 | + ), |
| 409 | + ( |
| 410 | + "implementation_version == '3.*'", |
| 411 | + {"implementation_version": "3.*"}, |
| 412 | + True, |
| 413 | + ), |
| 414 | + ], |
| 415 | + ) |
| 416 | + def test_valid_specifier_invalid_version_fallback_to_python( |
| 417 | + self, marker_string: str, environment: dict, expected: bool |
| 418 | + ): |
| 419 | + """If the right operand is a valid version specifier, but the |
| 420 | + left operand is not a valid version, fallback to Python string |
| 421 | + comparison behaviour. |
| 422 | + """ |
| 423 | + args = [] if environment is None else [environment] |
| 424 | + assert Marker(marker_string).evaluate(*args) == expected |
0 commit comments