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

tests: update tests that are based on old lock files (prior Poetry 1.1) #279

Merged
merged 1 commit into from
May 9, 2024
Merged
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
44 changes: 28 additions & 16 deletions tests/test_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ def poetry(fixture_root: Path, locker: Locker) -> Poetry:


def set_package_requires(
poetry: Poetry, skip: set[str] | None = None, dev: set[str] | None = None
poetry: Poetry,
skip: set[str] | None = None,
dev: set[str] | None = None,
markers: dict[str, str] | None = None,
) -> None:
skip = skip or set()
dev = dev or set()
Expand All @@ -93,6 +96,8 @@ def set_package_requires(
dep = pkg.to_dependency()
if pkg.name in dev:
dep._groups = frozenset(["dev"])
if markers and pkg.name in markers:
dep._marker = parse_marker(markers[pkg.name])
package.add_dependency(dep)

poetry._package = package
Expand Down Expand Up @@ -151,21 +156,18 @@ def test_exporter_can_export_requirements_txt_with_standard_packages_and_markers
"version": "1.2.3",
"optional": False,
"python-versions": "*",
"marker": "python_version < '3.7'",
},
{
"name": "bar",
"version": "4.5.6",
"optional": False,
"python-versions": "*",
"marker": "extra =='foo'",
},
{
"name": "baz",
"version": "7.8.9",
"optional": False,
"python-versions": "*",
"marker": "sys_platform == 'win32'",
},
],
"metadata": {
Expand All @@ -175,7 +177,12 @@ def test_exporter_can_export_requirements_txt_with_standard_packages_and_markers
},
}
)
set_package_requires(poetry)
markers = {
"foo": "python_version < '3.7'",
"bar": "extra =='foo'",
"baz": "sys_platform == 'win32'",
}
set_package_requires(poetry, markers=markers)

exporter = Exporter(poetry, NullIO())
exporter.export("requirements.txt", tmp_path, "requirements.txt")
Expand Down Expand Up @@ -397,23 +404,29 @@ def test_exporter_can_export_requirements_txt_with_nested_packages_and_markers(
"version": "1.2.3",
"optional": False,
"python-versions": "*",
"marker": "python_version < '3.7'",
"dependencies": {"b": ">=0.0.0", "c": ">=0.0.0"},
"dependencies": {
"b": {
"version": ">=0.0.0",
"markers": "platform_system == 'Windows'",
},
"c": {
"version": ">=0.0.0",
"markers": "sys_platform == 'win32'",
},
},
},
{
"name": "b",
"version": "4.5.6",
"optional": False,
"python-versions": "*",
"marker": "platform_system == 'Windows'",
"dependencies": {"d": ">=0.0.0"},
},
{
"name": "c",
"version": "7.8.9",
"optional": False,
"python-versions": "*",
"marker": "sys_platform == 'win32'",
"dependencies": {"d": ">=0.0.0"},
},
{
Expand All @@ -430,7 +443,9 @@ def test_exporter_can_export_requirements_txt_with_nested_packages_and_markers(
},
}
)
set_package_requires(poetry, skip={"b", "c", "d"})
set_package_requires(
poetry, skip={"b", "c", "d"}, markers={"a": "python_version < '3.7'"}
)

exporter = Exporter(poetry, NullIO())
exporter.export("requirements.txt", tmp_path, "requirements.txt")
Expand Down Expand Up @@ -1196,7 +1211,6 @@ def test_exporter_can_export_requirements_txt_with_git_packages_and_markers(
"version": "1.2.3",
"optional": False,
"python-versions": "*",
"marker": "python_version < '3.7'",
"source": {
"type": "git",
"url": "https://github.com/foo/foo.git",
Expand All @@ -1212,7 +1226,7 @@ def test_exporter_can_export_requirements_txt_with_git_packages_and_markers(
},
}
)
set_package_requires(poetry)
set_package_requires(poetry, markers={"foo": "python_version < '3.7'"})

exporter = Exporter(poetry, NullIO())
exporter.export("requirements.txt", tmp_path, "requirements.txt")
Expand Down Expand Up @@ -1383,7 +1397,6 @@ def test_exporter_can_export_requirements_txt_with_directory_packages_and_marker
"version": "1.2.3",
"optional": False,
"python-versions": "*",
"marker": "python_version < '3.7'",
"source": {
"type": "directory",
"url": "sample_project",
Expand All @@ -1398,7 +1411,7 @@ def test_exporter_can_export_requirements_txt_with_directory_packages_and_marker
},
}
)
set_package_requires(poetry)
set_package_requires(poetry, markers={"foo": "python_version < '3.7'"})

exporter = Exporter(poetry, NullIO())
exporter.export("requirements.txt", tmp_path, "requirements.txt")
Expand Down Expand Up @@ -1466,7 +1479,6 @@ def test_exporter_can_export_requirements_txt_with_file_packages_and_markers(
"version": "1.2.3",
"optional": False,
"python-versions": "*",
"marker": "python_version < '3.7'",
"source": {
"type": "file",
"url": "distributions/demo-0.1.0.tar.gz",
Expand All @@ -1481,7 +1493,7 @@ def test_exporter_can_export_requirements_txt_with_file_packages_and_markers(
},
}
)
set_package_requires(poetry)
set_package_requires(poetry, markers={"foo": "python_version < '3.7'"})

exporter = Exporter(poetry, NullIO())
exporter.export("requirements.txt", tmp_path, "requirements.txt")
Expand Down
Loading