Skip to content

Commit 8894b9e

Browse files
committed
Add doctests to to_constraints_string()
VersionConstraint.to_constraints_string is not a trivial function, soe some example help a lot Suggested by: @sbs2001 Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
1 parent 2806876 commit 8894b9e

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/univers/version_constraint.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,17 @@ def to_constraints_string(cls, constraints):
210210
VersionConstraints are joined with an "OR" e.g., a "vers" pipe "|" and
211211
the inner sequences of VersionConstraint are each joined with an "AND"
212212
e.g., a "vers" coma ",".
213+
For instance:
214+
>>> from univers.versions import PypiVersion
215+
>>> constraints = [
216+
... [VersionConstraint(comparator="=", version=PypiVersion("2"))],
217+
... [
218+
... VersionConstraint(comparator="=>", version=PypiVersion("3")),
219+
... VersionConstraint(comparator="<", version=PypiVersion("4")),
220+
... ],
221+
... [VersionConstraint(comparator="=", version=PypiVersion("5"))],
222+
... ]
223+
>>> assert VersionConstraint.to_constraints_string(constraints) == "2|=>3,<4|5"
213224
"""
214225
cls.validate(constraints)
215226
anyof_constraints = []

0 commit comments

Comments
 (0)