From bbd545e9177eb59a256d3f68d795c672bda49c3c Mon Sep 17 00:00:00 2001 From: Arun Babu Neelicattu Date: Sun, 31 Jan 2021 16:08:56 +0100 Subject: [PATCH] Ensure dependency string is PEP 508 compliant (#103) --- poetry/core/packages/dependency.py | 8 +------- tests/packages/test_dependency.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/poetry/core/packages/dependency.py b/poetry/core/packages/dependency.py index 5432e8bb3..d678947e2 100644 --- a/poetry/core/packages/dependency.py +++ b/poetry/core/packages/dependency.py @@ -411,13 +411,7 @@ def __hash__(self): # type: () -> int def __str__(self): # type: () -> str if self.is_root: return self._pretty_name - - name = self._pretty_name - - if self._features: - name = "{}[{}]".format(name, ",".join(sorted(self._features))) - - return "{} ({})".format(name, self._pretty_constraint) + return self.base_pep_508_name def __repr__(self): # type: () -> str return "<{} {}>".format(self.__class__.__name__, str(self)) diff --git a/tests/packages/test_dependency.py b/tests/packages/test_dependency.py index 8591e72f5..116c50880 100644 --- a/tests/packages/test_dependency.py +++ b/tests/packages/test_dependency.py @@ -205,3 +205,22 @@ def test_complete_name(): "foo[bar,baz]" == Dependency("foo", ">=1.2.3", extras=["baz", "bar"]).complete_name ) + + +@pytest.mark.parametrize( + "name,constraint,extras,expected", + [ + ("A", ">2.7,<3.0", None, "A (>2.7,<3.0)"), + ("A", ">2.7,<3.0", ["x"], "A[x] (>2.7,<3.0)"), + ("A", ">=1.6.5,<1.8.0 || >1.8.0,<3.1.0", None, "A (>=1.6.5,!=1.8.0,<3.1.0)"), + ( + "A", + ">=1.6.5,<1.8.0 || >1.8.0,<3.1.0", + ["x"], + "A[x] (>=1.6.5,!=1.8.0,<3.1.0)", + ), + ], +) +def test_dependency_string_representation(name, constraint, extras, expected): + dependency = Dependency(name=name, constraint=constraint, extras=extras) + assert str(dependency) == expected