Skip to content

Commit

Permalink
馃И test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
juftin committed Feb 1, 2024
1 parent b44d9e9 commit 655b16c
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 14 deletions.
17 changes: 17 additions & 0 deletions tests/data/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ path = ".venv/hatch-pip-compile-test"
pip-compile-constraint = "default"
type = "pip-compile"

[tool.hatch.envs.docs]
dependencies = [
"mkdocs"
]
dev-mode = false
lock-filename = "requirements/{env_name}.lock"
path = ".venv/docs"
pip-compile-constraint = "misc"
pip-compile-hashes = true

[tool.hatch.envs.lint]
dependencies = [
"mypy>=1.6.1",
Expand All @@ -30,6 +40,13 @@ detached = true
path = ".venv/lint"
type = "pip-compile"

[tool.hatch.envs.misc]
dependencies = []
detached = true
path = ".venv/misc"
skip-install = true
type = "pip-compile"

[tool.hatch.envs.test]
dependencies = [
"pytest",
Expand Down
11 changes: 7 additions & 4 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def test_cli_bad_env(pip_compile: PipCompileFixture) -> None:
assert "error" in result.output.lower()
assert (
"The following environments are not supported or unknown: bad_env. "
"Supported environments are: default, lint, test"
"Supported environments are: default, docs, lint, misc, test"
) in result.output


Expand All @@ -99,7 +99,10 @@ def test_cli_all(pip_compile: PipCompileFixture) -> None:
with runner.isolated_filesystem(temp_dir=pip_compile.isolation):
result = runner.invoke(cli=cli, args=["--all"])
assert result.exit_code == 0
assert "hatch-pip-compile: Targeting environments: default, lint, test" in result.output
assert (
"hatch-pip-compile: Targeting environments: default, docs, lint, misc, test"
in result.output
)


def test_cli_upgrade(pip_compile: PipCompileFixture) -> None:
Expand Down Expand Up @@ -149,7 +152,7 @@ def test_command_runner_supported_environments(
upgrade=True,
upgrade_packages=[],
)
assert command_runner.supported_environments == {"default", "test", "lint"}
assert command_runner.supported_environments == {"default", "test", "lint", "docs", "misc"}


def test_command_runner_non_supported_environments(
Expand All @@ -164,7 +167,7 @@ def test_command_runner_non_supported_environments(
click.BadParameter,
match=(
"The following environments are not supported or unknown: bad_env. "
"Supported environments are: default, lint, test"
"Supported environments are: default, docs, lint, misc, test"
),
):
_ = HatchCommandRunner(
Expand Down
4 changes: 3 additions & 1 deletion tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_new_dependency(
"""
Test adding a new dependency
"""
if installer == "pip-sync" and sys.platform == "win32":
if installer == "pip-sync" and sys.platform == "win32": # pragma: no cover
pytest.skip("Flaky test on Windows")
original_requirements = pip_compile.default_environment.piptools_lock.read_header_requirements()
assert original_requirements == [packaging.requirements.Requirement("hatch")]
Expand Down Expand Up @@ -59,6 +59,8 @@ def test_delete_dependencies(
"""
Test deleting all dependencies also deletes the lockfile
"""
if installer == "pip-sync" and sys.platform == "win32": # pragma: no cover
pytest.skip("Flaky test on Windows")
pip_compile.toml_doc["tool"]["hatch"]["envs"]["default"]["pip-compile-installer"] = installer
pip_compile.toml_doc["project"]["dependencies"] = []
pip_compile.update_pyproject()
Expand Down
11 changes: 7 additions & 4 deletions tests/test_integration_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
from tests.conftest import PipCompileFixture


def test_invoke_environment_creates_env(pip_compile: PipCompileFixture) -> None:
@pytest.mark.parametrize("environment_name", ["default", "test", "lint", "docs", "misc"])
def test_invoke_environment_creates_env(
pip_compile: PipCompileFixture, environment_name: str
) -> None:
"""
Test using the CLI runner
"""
runner = CliRunner()
environment = pip_compile.test_environment
environment = pip_compile.reload_environment(environment=environment_name)
venv = environment.virtual_env.directory
assert not venv.exists()
with runner.isolated_filesystem(pip_compile.isolation):
Expand Down Expand Up @@ -129,5 +132,5 @@ def test_prune_removes_all_environments(pip_compile: PipCompileFixture) -> None:
args=["env", "prune"],
)
assert result.exit_code == 0
if venv_dir.exists():
assert len(list(venv_dir.iterdir())) == 0
venv_dir.mkdir(exist_ok=True)
assert len(list(venv_dir.iterdir())) == 0
33 changes: 28 additions & 5 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,34 @@ def test_env_var_disabled(pip_compile: PipCompileFixture, monkeypatch: pytest.Mo
pip_compile.default_environment.pip_compile_cli()


def test_constraint_env_self(pip_compile: PipCompileFixture) -> None:
@pytest.mark.parametrize("environment_name", ["default", "misc", "docs"])
def test_constraint_env_self(pip_compile: PipCompileFixture, environment_name: str) -> None:
"""
Test the value of the constraint env b/w the default and test environments
"""
assert (
pip_compile.default_environment.constraint_env.name == pip_compile.default_environment.name
)
assert pip_compile.test_environment.constraint_env.name == pip_compile.default_environment.name
environment = pip_compile.reload_environment(environment=environment_name)
assert environment.constraint_env is environment


@pytest.mark.parametrize("environment_name", ["test"])
def test_constraint_env_other(pip_compile: PipCompileFixture, environment_name: str) -> None:
"""
Test the value of the constraint env b/w the default and test environments
"""
environment = pip_compile.reload_environment(environment=environment_name)
assert environment.constraint_env.name == pip_compile.default_environment.name


@pytest.mark.parametrize("environment_name", ["default", "docs", "misc"])
def test_prepare_environment(pip_compile: PipCompileFixture, environment_name: str) -> None:
"""
Test the `prepare_environment` method
"""
environment = pip_compile.reload_environment(environment=environment_name)
environment.prepare_environment()
if environment.dependencies:
assert environment.piptools_lock_file.exists()
else:
assert not environment.piptools_lock_file.exists()
assert environment.dependencies_in_sync() is True
assert environment.lockfile_up_to_date is True

0 comments on commit 655b16c

Please sign in to comment.