From 8765b81f8b8c262b6610eabc89eafd364e4f666b Mon Sep 17 00:00:00 2001 From: Leonardo Schwarz Date: Fri, 8 Nov 2024 15:55:17 +0100 Subject: [PATCH] remove snakemake_invoke tests --- tests/unit/snakemake_invoke/__init__.py | 0 .../unit/snakemake_invoke/invoke/__init__.py | 0 .../invoke/test_invoke_call_function.py | 38 ------------ .../invoke/test_invoke_subprocess.py | 56 ----------------- .../snakemake_invoke/test_snakemake_invoke.py | 60 ------------------- 5 files changed, 154 deletions(-) delete mode 100644 tests/unit/snakemake_invoke/__init__.py delete mode 100644 tests/unit/snakemake_invoke/invoke/__init__.py delete mode 100644 tests/unit/snakemake_invoke/invoke/test_invoke_call_function.py delete mode 100644 tests/unit/snakemake_invoke/invoke/test_invoke_subprocess.py delete mode 100644 tests/unit/snakemake_invoke/test_snakemake_invoke.py diff --git a/tests/unit/snakemake_invoke/__init__.py b/tests/unit/snakemake_invoke/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/unit/snakemake_invoke/invoke/__init__.py b/tests/unit/snakemake_invoke/invoke/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/unit/snakemake_invoke/invoke/test_invoke_call_function.py b/tests/unit/snakemake_invoke/invoke/test_invoke_call_function.py deleted file mode 100644 index 8fc9a1c..0000000 --- a/tests/unit/snakemake_invoke/invoke/test_invoke_call_function.py +++ /dev/null @@ -1,38 +0,0 @@ -import os -import pytest -from snakemake_invoke.config import SnakemakeInvokeConfig -from snakemake_invoke.invoke.invoke_call_function import InvokeCallFunction - - -@pytest.fixture(params=[None]) -def config_env_variables(request) -> dict[str, str]: - return request.param or {} - - -@pytest.fixture -def config(config_env_variables): - return SnakemakeInvokeConfig( - env_variables=config_env_variables, - ) - - -@pytest.fixture() -def invoke(config): - return InvokeCallFunction(config=config) - - -@pytest.mark.parametrize( - "config_env_variables,expected", - [ - ({}, {"a": "1", "b": "2"}), - ({"c": "3"}, {"a": "1", "b": "2", "c": "3"}), - ({"a": "x", "c": "3"}, {"a": "x", "b": "2", "c": "3"}), - ], - indirect=["config_env_variables"], -) -def test_set_env_vars(mocker, invoke, expected): - original_env_vars = {"a": "1", "b": "2"} - mocker.patch("os.environ", original_env_vars) - with invoke._set_env_vars(): - assert dict(os.environ) == expected - assert dict(os.environ) == {"a": "1", "b": "2"} diff --git a/tests/unit/snakemake_invoke/invoke/test_invoke_subprocess.py b/tests/unit/snakemake_invoke/invoke/test_invoke_subprocess.py deleted file mode 100644 index 709b620..0000000 --- a/tests/unit/snakemake_invoke/invoke/test_invoke_subprocess.py +++ /dev/null @@ -1,56 +0,0 @@ -import pytest -import sys -from pathlib import Path -from snakemake_invoke.config import SnakemakeInvokeConfig -from snakemake_invoke.invoke.invoke_subprocess import InvokeSubprocess - - -@pytest.fixture() -def config_snakefile_path() -> Path: - return Path("/tmp/workflow/Snakefile") - - -@pytest.fixture -def config(config_snakefile_path): - return SnakemakeInvokeConfig(snakefile_path=config_snakefile_path) - - -@pytest.fixture -def invoke(config): - return InvokeSubprocess(config=config) - - -@pytest.mark.parametrize( - "input_args,expected", - [ - pytest.param(["a"], "a", id="plain_string"), - pytest.param(["a b"], "'a b'", id="string_with_space"), - pytest.param(['"a b"'], "'\"a b\"'", id="string_with_double_quotes"), - pytest.param(["a'b"], "'a'\"'\"'b'", id="string_with_single_quote"), - pytest.param(['a"b'], "'a\"b'", id="string_with_double_quote"), - pytest.param(["a", "a b", ""], "a 'a b' ''", id="list_of_strings"), - ], -) -def test_args_to_shell_command(input_args, expected): - result = InvokeSubprocess._args_to_shell_command(input_args) - assert result == expected - - -def test_get_base_command(invoke) -> None: - base_command = invoke.get_base_command( - extra_args=["--keep-going"], - work_dir=Path("/tmp/work"), - ) - assert base_command == [ - sys.executable, - "-m", - "snakemake", - "-d", - "/tmp/work", - "--cores", - "1", - "--snakefile", - "/tmp/workflow/Snakefile", - "--rerun-incomplete", - "--keep-going", - ] diff --git a/tests/unit/snakemake_invoke/test_snakemake_invoke.py b/tests/unit/snakemake_invoke/test_snakemake_invoke.py deleted file mode 100644 index 818a96b..0000000 --- a/tests/unit/snakemake_invoke/test_snakemake_invoke.py +++ /dev/null @@ -1,60 +0,0 @@ -import pytest -from pathlib import Path -from snakemake_invoke.config import SnakemakeInvokeConfig, ExecutionModel -from snakemake_invoke.snakemake_invoke import SnakemakeInvoke - - -@pytest.fixture(params=[None]) -def config_execution_model(request) -> ExecutionModel: - return request.param or ExecutionModel.SUBPROCESS - - -@pytest.fixture(params=[None]) -def config_env_variables(request) -> dict[str, str]: - return request.param or {} - - -@pytest.fixture -def config(config_execution_model, config_env_variables): - return SnakemakeInvokeConfig( - execution_model=config_execution_model, - env_variables=config_env_variables, - ) - - -@pytest.fixture -def mock_work_dir(mocker): - return mocker.MagicMock(name="work_dir", spec=Path) - - -@pytest.fixture -def mock_result_files(mocker): - return [mocker.MagicMock(name=f"result_file[{i}]", spec=Path) for i in range(3)] - - -@pytest.fixture -def invoke(config): - return SnakemakeInvoke(config=config) - - -@pytest.mark.parametrize("config_execution_model", [ExecutionModel.SUBPROCESS], indirect=True) -def test_invoke_subprocess(mocker, invoke, mock_work_dir, mock_result_files): - mocked = mocker.patch("snakemake_invoke.snakemake_invoke.InvokeSubprocess") - invoke.invoke(work_dir=mock_work_dir, result_files=mock_result_files) - mocked.assert_called_once_with(config=invoke.config) - mocked.return_value.invoke.assert_called_once_with(work_dir=mock_work_dir, result_files=mock_result_files) - - -@pytest.mark.parametrize("config_execution_model", [ExecutionModel.CALL_FUNCTION], indirect=True) -def test_invoke_call_function(mocker, invoke, mock_work_dir, mock_result_files): - mocked = mocker.patch("snakemake_invoke.snakemake_invoke.InvokeCallFunction") - invoke.invoke(work_dir=mock_work_dir, result_files=mock_result_files) - mocked.assert_called_once_with(config=invoke.config) - mocked.return_value.invoke.assert_called_once_with(work_dir=mock_work_dir, result_files=mock_result_files) - - -def test_invoke_when_unknown(invoke, mock_work_dir, mock_result_files): - invoke.config.execution_model = "unknown" - with pytest.raises(ValueError) as error: - invoke.invoke(work_dir=mock_work_dir, result_files=mock_result_files) - assert str(error.value) == f"Unknown execution model: unknown"