Add setup_fingerprint_check/tests/test_core.py
This commit is contained in:
parent
0805c7a27f
commit
488c7c4be0
1 changed files with 38 additions and 0 deletions
38
setup_fingerprint_check/tests/test_core.py
Normal file
38
setup_fingerprint_check/tests/test_core.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import pytest
|
||||
|
||||
import hashlib
|
||||
import os
|
||||
from setup_fingerprint_check import core
|
||||
|
||||
def generate_mock_fingerprint(env_data: str) -> str:
|
||||
return hashlib.sha256(env_data.encode()).hexdigest()
|
||||
|
||||
@pytest.fixture
|
||||
def valid_env(monkeypatch):
|
||||
# Simulate a deterministic environment for hashing
|
||||
mock_env = {
|
||||
'KERNEL_VERSION': '5.15.0-91-generic',
|
||||
'PYTHON_VERSION': '3.11.2',
|
||||
'RUNNER': 'CI-Linux'
|
||||
}
|
||||
for key, value in mock_env.items():
|
||||
monkeypatch.setenv(key, value)
|
||||
env_str = '|'.join(f"{k}={v}" for k, v in sorted(mock_env.items()))
|
||||
expected = generate_mock_fingerprint(env_str)
|
||||
return expected, mock_env
|
||||
|
||||
def test_check_setup_fingerprint_valid(monkeypatch, valid_env):
|
||||
expected_fingerprint, mock_env = valid_env
|
||||
# Patch os.environ to simulate runtime environment
|
||||
monkeypatch.setattr(os, 'environ', mock_env)
|
||||
assert core.check_setup_fingerprint(expected_fingerprint) is True
|
||||
|
||||
def test_check_setup_fingerprint_mismatch(monkeypatch, valid_env):
|
||||
expected_fingerprint, mock_env = valid_env
|
||||
monkeypatch.setattr(os, 'environ', {**mock_env, 'PYTHON_VERSION': '3.10.9'})
|
||||
assert core.check_setup_fingerprint(expected_fingerprint) is False
|
||||
|
||||
def test_check_setup_fingerprint_type_validation():
|
||||
with pytest.raises(AssertionError):
|
||||
# Non-string input to test assertion from ci_ready input-validation requirement
|
||||
core.check_setup_fingerprint(12345) # type: ignore
|
||||
Loading…
Reference in a new issue