Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: Empty and Any markers saved to lockfile #1650

Merged
merged 3 commits into from
Dec 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion poetry/version/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,15 @@ def __hash__(self):
return h

def __str__(self):
return " or ".join(str(m) for m in self._markers)
return " or ".join(
str(m) for m in self._markers if not m.is_any() and not m.is_empty()
)

def is_any(self):
return any(m.is_any() for m in self._markers)

def is_empty(self):
return all(m.is_empty() for m in self._markers)


def parse_marker(marker):
Expand Down
40 changes: 40 additions & 0 deletions tests/version/test_markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,46 @@ def test_marker_union_union_duplicates():
)


def test_marker_union_all_any():
union = MarkerUnion(parse_marker(""), parse_marker(""))

assert union.is_any()


def test_marker_union_not_all_any():
union = MarkerUnion(parse_marker(""), parse_marker(""), parse_marker("<empty>"))

assert union.is_any()


def test_marker_union_all_empty():
union = MarkerUnion(parse_marker("<empty>"), parse_marker("<empty>"))

assert union.is_empty()


def test_marker_union_not_all_empty():
union = MarkerUnion(
parse_marker("<empty>"), parse_marker("<empty>"), parse_marker("")
)

assert not union.is_empty()


def test_marker_str_conversion_skips_empty_and_any():
union = MarkerUnion(
parse_marker("<empty>"),
parse_marker(
'sys_platform == "darwin" or python_version <= "3.6" or os_name == "Windows"'
),
parse_marker(""),
)

assert str(union) == (
'sys_platform == "darwin" or python_version <= "3.6" or os_name == "Windows"'
)


def test_intersect_compacts_constraints():
m = parse_marker('python_version < "4.0"')

Expand Down