From 36ad3bff6282707c71481f41e2e5979bc4e723e2 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 8 Jun 2024 09:42:01 +0200 Subject: [PATCH] Fix /tmp usage in tests --- pyproject.toml | 1 - tests/test_directory_operations.py | 24 ++++++++++-------------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 704a271f0..55ff28db6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -165,7 +165,6 @@ max-complexity = 12 ] "tests/**/*.py" = [ "S101", # allow assert in tests - "S108", # temp usage ... "S104", # Possible binding to all interfaces "S311", # Standard pseudo-random generators are not suitable for cryptographic purposes "S105", # Possible hardcoded password assigned to: "secret" diff --git a/tests/test_directory_operations.py b/tests/test_directory_operations.py index 03c1d25cb..a6216f7a6 100644 --- a/tests/test_directory_operations.py +++ b/tests/test_directory_operations.py @@ -62,14 +62,12 @@ def test_create_userdata_dir_exists(mocker, tmp_path) -> None: assert md.call_count == 0 -def test_create_userdata_dir_exists_exception(mocker, default_conf, caplog) -> None: +def test_create_userdata_dir_exists_exception(mocker, tmp_path) -> None: mocker.patch.object(Path, "is_dir", MagicMock(return_value=False)) md = mocker.patch.object(Path, "mkdir", MagicMock()) - with pytest.raises( - OperationalException, match=r"Directory `.{1,2}tmp.{1,2}bar` does not exist.*" - ): - create_userdata_dir("/tmp/bar", create_dir=False) + with pytest.raises(OperationalException, match=r"Directory `.*.{1,2}bar` does not exist.*"): + create_userdata_dir(f"{tmp_path}/bar", create_dir=False) assert md.call_count == 0 @@ -89,26 +87,24 @@ def test_copy_sample_files(mocker, tmp_path) -> None: ) -def test_copy_sample_files_errors(mocker, default_conf, caplog) -> None: +def test_copy_sample_files_errors(mocker, tmp_path, caplog) -> None: mocker.patch.object(Path, "is_dir", MagicMock(return_value=False)) mocker.patch.object(Path, "exists", MagicMock(return_value=False)) mocker.patch("shutil.copy", MagicMock()) - with pytest.raises( - OperationalException, match=r"Directory `.{1,2}tmp.{1,2}bar` does not exist\." - ): - copy_sample_files(Path("/tmp/bar")) + with pytest.raises(OperationalException, match=r"Directory `.*.{1,2}bar` does not exist\."): + copy_sample_files(Path(f"{tmp_path}/bar")) mocker.patch.object(Path, "is_dir", MagicMock(side_effect=[True, False])) with pytest.raises( OperationalException, - match=r"Directory `.{1,2}tmp.{1,2}bar.{1,2}strategies` does not exist\.", + match=r"Directory `.*.{1,2}bar.{1,2}strategies` does not exist\.", ): - copy_sample_files(Path("/tmp/bar")) + copy_sample_files(Path(f"{tmp_path}/bar")) mocker.patch.object(Path, "is_dir", MagicMock(return_value=True)) mocker.patch.object(Path, "exists", MagicMock(return_value=True)) - copy_sample_files(Path("/tmp/bar")) + copy_sample_files(Path(f"{tmp_path}/bar")) assert log_has_re(r"File `.*` exists already, not deploying sample file\.", caplog) caplog.clear() - copy_sample_files(Path("/tmp/bar"), overwrite=True) + copy_sample_files(Path(f"{tmp_path}/bar"), overwrite=True) assert log_has_re(r"File `.*` exists already, overwriting\.", caplog)