diff --git a/tests/test_passgpt_attack.py b/tests/test_passgpt_attack.py index 517caa0..58d532d 100644 --- a/tests/test_passgpt_attack.py +++ b/tests/test_passgpt_attack.py @@ -1,9 +1,12 @@ +import importlib.util import os import sys from unittest.mock import MagicMock, patch import pytest +_has_transformers = importlib.util.find_spec("transformers") is not None + from hate_crack.passgpt_train import ( _count_lines, _estimate_training_memory_mb, @@ -395,6 +398,7 @@ class TestMemoryPrecheck: device="cpu", ) + @pytest.mark.skipif(not _has_transformers, reason="transformers not installed") def test_skips_when_detection_fails(self, tmp_path): """When memory detection returns None, training proceeds past the pre-check.""" f = tmp_path / "words.txt" @@ -456,6 +460,7 @@ class TestMaxLines: class TestMemoryLimitAutoTune: + @pytest.mark.skipif(not _has_transformers, reason="transformers not installed") def test_auto_tunes_max_lines(self, tmp_path, capsys): f = tmp_path / "words.txt" f.write_text("password\n" * 100) diff --git a/tests/test_ui_menu_options.py b/tests/test_ui_menu_options.py index 98a20a4..db237b9 100644 --- a/tests/test_ui_menu_options.py +++ b/tests/test_ui_menu_options.py @@ -27,7 +27,16 @@ MENU_OPTION_TEST_CASES = [ ("14", CLI_MODULE._attacks, "loopback_attack", "loopback"), ("15", CLI_MODULE._attacks, "ollama_attack", "ollama"), ("16", CLI_MODULE._attacks, "omen_attack", "omen"), - ("17", CLI_MODULE._attacks, "passgpt_attack", "passgpt"), + pytest.param( + "17", + CLI_MODULE._attacks, + "passgpt_attack", + "passgpt", + marks=pytest.mark.skipif( + not getattr(CLI_MODULE, "HAS_ML_DEPS", False), + reason="ML dependencies not installed", + ), + ), ("90", CLI_MODULE, "download_hashmob_rules", "hashmob-rules"), ("91", CLI_MODULE, "weakpass_wordlist_menu", "weakpass-menu"), ("92", CLI_MODULE, "download_hashmob_wordlists", "hashmob-wordlists"), diff --git a/tests/test_version_check.py b/tests/test_version_check.py index 732d407..68b22fb 100644 --- a/tests/test_version_check.py +++ b/tests/test_version_check.py @@ -57,8 +57,10 @@ class TestCheckForUpdates: mock_resp.json.return_value = {"tag_name": "v0.0.1"} mock_resp.raise_for_status = MagicMock() - with patch.object(hc_module, "requests") as mock_requests, patch.object( - hc_module, "REQUESTS_AVAILABLE", True + with ( + patch.object(hc_module, "requests") as mock_requests, + patch.object(hc_module, "REQUESTS_AVAILABLE", True), + patch("hate_crack.__version__", "2.0"), ): mock_requests.get.return_value = mock_resp hc_module.check_for_updates()