mirror of
https://github.com/trustedsec/hate_crack.git
synced 2026-07-28 22:51:14 -07:00
fix: skip ML-dependent tests in CI and mock version in version check test
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
2667b0396c
commit
c87f498c80
@@ -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)
|
||||
|
||||
@@ -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"),
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user