Skip to content

Commit

Permalink
refactor(tests): correctness and removal of dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
neersighted committed Oct 1, 2022
1 parent 67115b8 commit 779439c
Showing 1 changed file with 13 additions and 22 deletions.
35 changes: 13 additions & 22 deletions tests/test_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from pathlib import Path
from typing import TYPE_CHECKING
from typing import Any
from typing import Iterator

import pytest

Expand Down Expand Up @@ -38,7 +37,6 @@

if TYPE_CHECKING:
from poetry.poetry import Poetry
from pytest_mock import MockerFixture

from tests.conftest import Config
from tests.types import FixtureDirGetter
Expand Down Expand Up @@ -69,15 +67,8 @@ def _get_content_hash(self) -> str:


@pytest.fixture
def working_directory() -> Path:
return Path(__file__).parent.parent


@pytest.fixture(autouse=True)
def mock_path_cwd(
mocker: MockerFixture, working_directory: Path
) -> Iterator[MockerFixture]:
yield mocker.patch("pathlib.Path.cwd", return_value=working_directory)
def plugin_root_uri() -> str:
return Path(__file__).parent.parent.as_uri()


@pytest.fixture()
Expand Down Expand Up @@ -809,7 +800,7 @@ def test_exporter_exports_requirements_txt_with_dev_packages_if_opted_in(
assert content == expected


def test_exporter_exports_requirements_txt_without_groups_if_set_explicity(
def test_exporter_exports_requirements_txt_without_groups_if_set_explicitly(
tmp_path: Path, poetry: Poetry
) -> None:
poetry.locker.mock_lock_data( # type: ignore[attr-defined]
Expand Down Expand Up @@ -1261,7 +1252,7 @@ def test_exporter_can_export_requirements_txt_with_git_packages_and_markers(


def test_exporter_can_export_requirements_txt_with_directory_packages(
tmp_path: Path, poetry: Poetry, working_directory: Path
tmp_path: Path, poetry: Poetry, plugin_root_uri: str
) -> None:
poetry.locker.mock_lock_data( # type: ignore[attr-defined]
{
Expand Down Expand Up @@ -1295,14 +1286,14 @@ def test_exporter_can_export_requirements_txt_with_directory_packages(
content = f.read()

expected = f"""\
foo @ {working_directory.as_uri()}/tests/fixtures/sample_project ; {MARKER_PY}
foo @ {plugin_root_uri}/tests/fixtures/sample_project ; {MARKER_PY}
"""

assert content == expected


def test_exporter_can_export_requirements_txt_with_nested_directory_packages(
tmp_path: Path, poetry: Poetry, working_directory: Path
tmp_path: Path, poetry: Poetry, plugin_root_uri: str
) -> None:
poetry.locker.mock_lock_data( # type: ignore[attr-defined]
{
Expand Down Expand Up @@ -1365,7 +1356,7 @@ def test_exporter_can_export_requirements_txt_with_nested_directory_packages(
with (tmp_path / "requirements.txt").open(encoding="utf-8") as f:
content = f.read()

root_uri = f"{working_directory.as_uri()}/tests/fixtures"
root_uri = f"{plugin_root_uri}/tests/fixtures"
expected = f"""\
bar @ {root_uri}/project_with_nested_local/bar ; {MARKER_PY}
baz @ {root_uri}/project_with_nested_local ; {MARKER_PY}
Expand All @@ -1376,7 +1367,7 @@ def test_exporter_can_export_requirements_txt_with_nested_directory_packages(


def test_exporter_can_export_requirements_txt_with_directory_packages_and_markers(
tmp_path: Path, poetry: Poetry, working_directory: Path
tmp_path: Path, poetry: Poetry, plugin_root_uri: str
) -> None:
poetry.locker.mock_lock_data( # type: ignore[attr-defined]
{
Expand Down Expand Up @@ -1411,15 +1402,15 @@ def test_exporter_can_export_requirements_txt_with_directory_packages_and_marker
content = f.read()

expected = f"""\
foo @ {working_directory.as_uri()}/tests/fixtures/sample_project ;\
foo @ {plugin_root_uri}/tests/fixtures/sample_project ;\
{MARKER_PY27.union(MARKER_PY36_ONLY)}
"""

assert content == expected


def test_exporter_can_export_requirements_txt_with_file_packages(
tmp_path: Path, poetry: Poetry, working_directory: Path
tmp_path: Path, poetry: Poetry, plugin_root_uri: str
) -> None:
poetry.locker.mock_lock_data( # type: ignore[attr-defined]
{
Expand Down Expand Up @@ -1453,15 +1444,15 @@ def test_exporter_can_export_requirements_txt_with_file_packages(
content = f.read()

expected = f"""\
foo @ {working_directory.as_uri()}/tests/fixtures/distributions/demo-0.1.0.tar.gz ;\
foo @ {plugin_root_uri}/tests/fixtures/distributions/demo-0.1.0.tar.gz ;\
{MARKER_PY}
"""

assert content == expected


def test_exporter_can_export_requirements_txt_with_file_packages_and_markers(
tmp_path: Path, poetry: Poetry, working_directory: Path
tmp_path: Path, poetry: Poetry, plugin_root_uri: str
) -> None:
poetry.locker.mock_lock_data( # type: ignore[attr-defined]
{
Expand Down Expand Up @@ -1495,7 +1486,7 @@ def test_exporter_can_export_requirements_txt_with_file_packages_and_markers(
with (tmp_path / "requirements.txt").open(encoding="utf-8") as f:
content = f.read()

uri = f"{working_directory.as_uri()}/tests/fixtures/distributions/demo-0.1.0.tar.gz"
uri = f"{plugin_root_uri}/tests/fixtures/distributions/demo-0.1.0.tar.gz"
expected = f"""\
foo @ {uri} ; {MARKER_PY27.union(MARKER_PY36_ONLY)}
"""
Expand Down

0 comments on commit 779439c

Please sign in to comment.