A Python port of the Invisible Internet Project (I2P)
at main 77 lines 2.4 kB view raw
1"""Tests for local system probes — TDD: tests before implementation.""" 2 3import os 4import tempfile 5from unittest.mock import patch 6 7import pytest 8 9from i2p_apps.setup.local_probe import ( 10 LocalProbeResult, 11 measure_crypto_throughput, 12 measure_disk_speed, 13 measure_ram, 14 run_local_probes, 15) 16 17 18class TestCryptoThroughput: 19 def test_returns_positive_int(self): 20 result = measure_crypto_throughput(duration_seconds=0.5) 21 assert isinstance(result, int) 22 assert result > 0 23 24 def test_scales_with_duration(self): 25 short = measure_crypto_throughput(duration_seconds=0.2) 26 # Result is ops/sec, so should be roughly consistent regardless of duration 27 assert short > 0 28 29 30class TestMeasureRam: 31 def test_returns_tuple(self): 32 available, total = measure_ram() 33 assert isinstance(available, int) 34 assert isinstance(total, int) 35 assert available > 0 36 assert total > 0 37 assert available <= total 38 39 40class TestMeasureDiskSpeed: 41 def test_returns_positive_float(self): 42 with tempfile.TemporaryDirectory() as tmpdir: 43 speed = measure_disk_speed(tmpdir, size_mb=1) 44 assert isinstance(speed, float) 45 assert speed > 0 46 47 def test_creates_no_leftover_files(self): 48 with tempfile.TemporaryDirectory() as tmpdir: 49 measure_disk_speed(tmpdir, size_mb=1) 50 assert len(os.listdir(tmpdir)) == 0 51 52 53class TestRunLocalProbes: 54 def test_returns_local_probe_result(self): 55 with tempfile.TemporaryDirectory() as tmpdir: 56 result = run_local_probes(data_dir=tmpdir) 57 assert isinstance(result, LocalProbeResult) 58 assert result.crypto_ops_per_sec > 0 59 assert result.available_ram_bytes > 0 60 assert result.total_ram_bytes > 0 61 assert result.cpu_count >= 1 62 assert result.disk_write_mbps > 0 63 assert result.disk_free_bytes >= 0 64 65 66class TestLocalProbeResultFields: 67 def test_all_fields_present(self): 68 r = LocalProbeResult( 69 crypto_ops_per_sec=10000, 70 available_ram_bytes=8_000_000_000, 71 total_ram_bytes=16_000_000_000, 72 cpu_count=8, 73 disk_write_mbps=200.0, 74 disk_free_bytes=100_000_000_000, 75 ) 76 assert r.crypto_ops_per_sec == 10000 77 assert r.cpu_count == 8