|
|
|
@ -1,7 +1,6 @@
|
|
|
|
|
# This file is dual licensed under the terms of the Apache License, Version |
|
|
|
|
# 2.0, and the BSD License. See the LICENSE file in the root of this repository |
|
|
|
|
# for complete details. |
|
|
|
|
from __future__ import absolute_import, division, print_function |
|
|
|
|
|
|
|
|
|
import collections |
|
|
|
|
import itertools |
|
|
|
@ -9,7 +8,6 @@ import os
|
|
|
|
|
import platform |
|
|
|
|
import sys |
|
|
|
|
|
|
|
|
|
import pretend |
|
|
|
|
import pytest |
|
|
|
|
|
|
|
|
|
from packaging.markers import ( |
|
|
|
@ -70,7 +68,7 @@ class TestNode:
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("value", ["one", "two", None, 3, 5, []]) |
|
|
|
|
def test_repr(self, value): |
|
|
|
|
assert repr(Node(value)) == "<Node({0!r})>".format(str(value)) |
|
|
|
|
assert repr(Node(value)) == "<Node({!r})>".format(str(value)) |
|
|
|
|
|
|
|
|
|
def test_base_class(self): |
|
|
|
|
with pytest.raises(NotImplementedError): |
|
|
|
@ -95,51 +93,6 @@ FakeVersionInfo = collections.namedtuple(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestDefaultEnvironment: |
|
|
|
|
@pytest.mark.skipif( |
|
|
|
|
hasattr(sys, "implementation"), reason="sys.implementation does exist" |
|
|
|
|
) |
|
|
|
|
def test_matches_expected_no_sys_implementation(self): |
|
|
|
|
environment = default_environment() |
|
|
|
|
|
|
|
|
|
assert environment == { |
|
|
|
|
"implementation_name": "", |
|
|
|
|
"implementation_version": "0", |
|
|
|
|
"os_name": os.name, |
|
|
|
|
"platform_machine": platform.machine(), |
|
|
|
|
"platform_release": platform.release(), |
|
|
|
|
"platform_system": platform.system(), |
|
|
|
|
"platform_version": platform.version(), |
|
|
|
|
"python_full_version": platform.python_version(), |
|
|
|
|
"platform_python_implementation": platform.python_implementation(), |
|
|
|
|
"python_version": ".".join(platform.python_version_tuple()[:2]), |
|
|
|
|
"sys_platform": sys.platform, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@pytest.mark.skipif( |
|
|
|
|
not hasattr(sys, "implementation"), reason="sys.implementation does not exist" |
|
|
|
|
) |
|
|
|
|
def test_matches_expected_deleted_sys_implementation(self, monkeypatch): |
|
|
|
|
monkeypatch.delattr(sys, "implementation") |
|
|
|
|
|
|
|
|
|
environment = default_environment() |
|
|
|
|
|
|
|
|
|
assert environment == { |
|
|
|
|
"implementation_name": "", |
|
|
|
|
"implementation_version": "0", |
|
|
|
|
"os_name": os.name, |
|
|
|
|
"platform_machine": platform.machine(), |
|
|
|
|
"platform_release": platform.release(), |
|
|
|
|
"platform_system": platform.system(), |
|
|
|
|
"platform_version": platform.version(), |
|
|
|
|
"python_full_version": platform.python_version(), |
|
|
|
|
"platform_python_implementation": platform.python_implementation(), |
|
|
|
|
"python_version": ".".join(platform.python_version_tuple()[:2]), |
|
|
|
|
"sys_platform": sys.platform, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@pytest.mark.skipif( |
|
|
|
|
not hasattr(sys, "implementation"), reason="sys.implementation does not exist" |
|
|
|
|
) |
|
|
|
|
def test_matches_expected(self): |
|
|
|
|
environment = default_environment() |
|
|
|
|
|
|
|
|
@ -165,32 +118,6 @@ class TestDefaultEnvironment:
|
|
|
|
|
"sys_platform": sys.platform, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@pytest.mark.skipif( |
|
|
|
|
hasattr(sys, "implementation"), reason="sys.implementation does exist" |
|
|
|
|
) |
|
|
|
|
def test_monkeypatch_sys_implementation(self, monkeypatch): |
|
|
|
|
monkeypatch.setattr( |
|
|
|
|
sys, |
|
|
|
|
"implementation", |
|
|
|
|
pretend.stub(version=FakeVersionInfo(3, 4, 2, "final", 0), name="linux"), |
|
|
|
|
raising=False, |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
environment = default_environment() |
|
|
|
|
assert environment == { |
|
|
|
|
"implementation_name": "linux", |
|
|
|
|
"implementation_version": "3.4.2", |
|
|
|
|
"os_name": os.name, |
|
|
|
|
"platform_machine": platform.machine(), |
|
|
|
|
"platform_release": platform.release(), |
|
|
|
|
"platform_system": platform.system(), |
|
|
|
|
"platform_version": platform.version(), |
|
|
|
|
"python_full_version": platform.python_version(), |
|
|
|
|
"platform_python_implementation": platform.python_implementation(), |
|
|
|
|
"python_version": ".".join(platform.python_version_tuple()[:2]), |
|
|
|
|
"sys_platform": sys.platform, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
def test_multidigit_minor_version(self, monkeypatch): |
|
|
|
|
version_info = (3, 10, 0, "final", 0) |
|
|
|
|
monkeypatch.setattr(sys, "version_info", version_info, raising=False) |
|
|
|
@ -216,7 +143,7 @@ class TestMarker:
|
|
|
|
|
@pytest.mark.parametrize( |
|
|
|
|
"marker_string", |
|
|
|
|
[ |
|
|
|
|
"{0} {1} {2!r}".format(*i) |
|
|
|
|
"{} {} {!r}".format(*i) |
|
|
|
|
for i in itertools.product(VARIABLES, OPERATORS, VALUES) |
|
|
|
|
] |
|
|
|
|
+ [ |
|
|
|
@ -278,7 +205,7 @@ class TestMarker:
|
|
|
|
|
def test_str_and_repr(self, marker_string, expected): |
|
|
|
|
m = Marker(marker_string) |
|
|
|
|
assert str(m) == expected |
|
|
|
|
assert repr(m) == "<Marker({0!r})>".format(str(m)) |
|
|
|
|
assert repr(m) == "<Marker({!r})>".format(str(m)) |
|
|
|
|
|
|
|
|
|
def test_extra_with_no_extra_in_environment(self): |
|
|
|
|
# We can't evaluate an extra if no extra is passed into the environment |
|
|
|
@ -289,7 +216,7 @@ class TestMarker:
|
|
|
|
|
@pytest.mark.parametrize( |
|
|
|
|
("marker_string", "environment", "expected"), |
|
|
|
|
[ |
|
|
|
|
("os_name == '{0}'".format(os.name), None, True), |
|
|
|
|
(f"os_name == '{os.name}'", None, True), |
|
|
|
|
("os_name == 'foo'", {"os_name": "foo"}, True), |
|
|
|
|
("os_name == 'foo'", {"os_name": "bar"}, False), |
|
|
|
|
("'2.7' in python_version", {"python_version": "2.7.5"}, True), |
|
|
|
@ -328,7 +255,7 @@ class TestMarker:
|
|
|
|
|
@pytest.mark.parametrize( |
|
|
|
|
"marker_string", |
|
|
|
|
[ |
|
|
|
|
"{0} {1} {2!r}".format(*i) |
|
|
|
|
"{} {} {!r}".format(*i) |
|
|
|
|
for i in itertools.product(PEP_345_VARIABLES, OPERATORS, VALUES) |
|
|