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 refactor: small fix to deduplicate dependencies factory. #245

Merged
merged 3 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
31 changes: 11 additions & 20 deletions tests/test_extract_declared_dependencies_success.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Test that dependencies are parsed from requirements files."""
from pathlib import Path
from textwrap import dedent
from typing import List

import pytest

Expand All @@ -11,13 +9,8 @@
parse_setup_cfg,
parse_setup_py,
)
from fawltydeps.types import DeclaredDependency, Location

from .utils import assert_unordered_equivalence, collect_dep_names


def dependency_factory(data: List[str], path: str) -> List[DeclaredDependency]:
return [DeclaredDependency(d, Location(Path(path))) for d in data]
from .utils import assert_unordered_equivalence, collect_dep_names, deps_factory


@pytest.mark.parametrize(
Expand Down Expand Up @@ -85,7 +78,7 @@ def test_parse_requirements_txt(write_tmp_files, file_content, expect_deps):
tmp_path = write_tmp_files({"requirements.txt": file_content})
path = tmp_path / "requirements.txt"

expected = dependency_factory(expect_deps, path)
expected = deps_factory(*expect_deps, path=path)
result = list(parse_requirements_txt(path))
assert_unordered_equivalence(result, expected)

Expand Down Expand Up @@ -290,7 +283,7 @@ def test_parse_setup_py(write_tmp_files, file_content, expect_deps):
tmp_path = write_tmp_files({"setup.py": file_content})
path = tmp_path / "setup.py"

expected = dependency_factory(expect_deps, path)
expected = deps_factory(*expect_deps, path=path)
result = list(parse_setup_py(path))
assert_unordered_equivalence(result, expected)

Expand Down Expand Up @@ -378,7 +371,7 @@ def test_parse_setup_cfg(write_tmp_files, file_content, expect_deps):
tmp_path = write_tmp_files({"setup.cfg": file_content})
path = tmp_path / "setup.cfg"

expected = dependency_factory(expect_deps, path)
expected = deps_factory(*expect_deps, path=path)
result = list(parse_setup_cfg(path))
assert_unordered_equivalence(result, expected)

Expand Down Expand Up @@ -408,15 +401,13 @@ def test_parse_setup_py__multiple_entries_in_extras_require__returns_list(
)
path = tmp_path / "setup.py"

expected = dependency_factory(
[
"abc",
"bert-serving-server",
"bert-serving-client",
"pytorch-transformer",
"flair",
],
path,
expected = deps_factory(
"abc",
"bert-serving-server",
"bert-serving-client",
"pytorch-transformer",
"flair",
path=path,
)
result = list(parse_setup_py(path))
assert_unordered_equivalence(result, expected)
Expand Down
5 changes: 3 additions & 2 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ def imports_factory(*imports: str) -> List[ParsedImport]:
return [ParsedImport(imp, Location("<stdin>")) for imp in imports]


def deps_factory(*deps: str) -> List[DeclaredDependency]:
return [DeclaredDependency(name=dep, source=Location(Path("foo"))) for dep in deps]
def deps_factory(*deps: str, path: str = "foo") -> List[DeclaredDependency]:
"Dependency generator with a common path for all dependencies"
return [DeclaredDependency(name=dep, source=Location(Path(path))) for dep in deps]


def resolved_factory(*deps: str) -> Dict[str, Package]:
Expand Down