Skip to content

Commit

Permalink
Add two more tests for parsing dynamic deps and opt deps
Browse files Browse the repository at this point in the history
  • Loading branch information
zz1874 committed Aug 28, 2023
1 parent 353ab19 commit 7adc708
Showing 1 changed file with 81 additions and 2 deletions.
83 changes: 81 additions & 2 deletions tests/test_extract_declared_dependencies_success.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,8 +564,9 @@ def test_find_and_parse_static_and_dynamic_sources__project_with_pyproject__retu
# but will be included when the dynamic sections in pyproject.toml are parsed.

# If dependencies or optional dependencies are declared dynamic, they can
# no longer be declared static. Therefore, the static sections will not be
# parsed if there are dynamic sections declared.
# no longer be declared static. Therefore, the static [project.dependencies]
# and [project.optional-dependencies] sections will not be parsed since
# "dependencies" and "optional-dependencies" are declared in [project.dynamic].
tmp_path = fake_project(
files_with_declared_deps={
".subdir/requirements.txt": ["pandas"],
Expand Down Expand Up @@ -593,6 +594,84 @@ def test_find_and_parse_static_and_dynamic_sources__project_with_pyproject__retu
assert_unordered_equivalence(actual, expect)


def test_find_and_parse_static_and_dynamic_dependencies__project_with_pyproject__returns_list(
write_tmp_files,
fake_project,
):
# Write requirements files into a place where files should be initially ignored
# but will be included when the dynamic sections in pyproject.toml are parsed.

# If dependencies or optional dependencies are declared dynamic, they can no longer
# be declared as static. As a result, the [project.dependencies] section won't be parsed,
# since "dependencies" is declared in [project.dynamic]. However, the static
# [project.optional-dependencies] section will still be parsed, as "optional-dependencies"
# is not marked as dynamic.
tmp_path = fake_project(
files_with_declared_deps={
".subdir/requirements.txt": ["pandas"],
".subdir/requirements-test.txt": ["pylint >= 2.15.8"],
},
extra_file_contents={
"pyproject.toml": """\
[project]
name = "MyLib"
dynamic = ["dependencies"]
dependencies = ["django"]
optional-dependencies = {"dev" = ["black"]}
[tool.setuptools.dynamic]
dependencies = { file = [".subdir/requirements.txt"] }
optional-dependencies.test = { file = [".subdir/requirements-test.txt"] } """,
},
)
expect = [
"pandas",
"black",
]
settings = Settings(code=set(), deps={tmp_path})
deps_sources = list(find_sources(settings, {DepsSource}))
actual = collect_dep_names(parse_sources(deps_sources))
assert_unordered_equivalence(actual, expect)


def test_find_and_parse_static_and_dynamic_opt_dependencies__project_with_pyproject__returns_list(
write_tmp_files,
fake_project,
):
# Write requirements files into a place where files should be initially ignored
# but will be included when the dynamic sections in pyproject.toml are parsed.

# If dependencies or optional dependencies are declared dynamic, they can no longer
# be declared as static. As a result, the [project.optional-dependencies] section
# won't be parsed, since "optional-dependencies" is declared in [project.dynamic].
# However, the static [project.dependencies] section will still be parsed,
# as "dependencies" is not marked as dynamic.
tmp_path = fake_project(
files_with_declared_deps={
".subdir/requirements.txt": ["pandas"],
".subdir/requirements-test.txt": ["pylint >= 2.15.8"],
},
extra_file_contents={
"pyproject.toml": """\
[project]
name = "MyLib"
dynamic = ["optional-dependencies"]
dependencies = ["django"]
optional-dependencies = {"dev" = ["black"]}
[tool.setuptools.dynamic]
dependencies = { file = [".subdir/requirements.txt"] }
optional-dependencies.test = { file = [".subdir/requirements-test.txt"] } """,
},
)
expect = [
"django",
"pylint",
]
settings = Settings(code=set(), deps={tmp_path})
deps_sources = list(find_sources(settings, {DepsSource}))
actual = collect_dep_names(parse_sources(deps_sources))
assert_unordered_equivalence(actual, expect)


def test_find_and_parse_sources__project_with_setup_cfg__returns_list(fake_project):
tmp_path = fake_project(
files_with_declared_deps={
Expand Down

0 comments on commit 7adc708

Please sign in to comment.