-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathtest_benchmark.py
More file actions
77 lines (62 loc) · 2.15 KB
/
test_benchmark.py
File metadata and controls
77 lines (62 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import os
import pytest
from unittest.mock import patch
from benchmark import get_package_subset, run_benchmark, run_benchmarks
def test_get_package_subset(tmp_path):
# Create mock packages directory
packages_dir = tmp_path / "packages"
packages_dir.mkdir()
for i in range(10):
(packages_dir / f"pkg_{i}").mkdir()
# Test getting a subset of 5
subset = get_package_subset(str(packages_dir), 5)
assert len(subset) == 5
for pkg in subset:
assert pkg.startswith("pkg_")
def test_get_package_subset_all(tmp_path):
packages_dir = tmp_path / "packages"
packages_dir.mkdir()
for i in range(5):
(packages_dir / f"pkg_{i}").mkdir()
# Test getting all
subset = get_package_subset(str(packages_dir), 10) # Request more than available
assert len(subset) == 5 # Should return all available
def test_run_benchmark(tmp_path):
# Create a dummy package file
package_file = tmp_path / "packages.txt"
package_file.write_text("pkg1\n")
# Create dummy package directory
packages_dir = tmp_path / "packages"
packages_dir.mkdir()
(packages_dir / "pkg1").mkdir()
(packages_dir / "pkg1" / "test.py").write_text("version = '3.7'\n")
scanner_path = "version_scanner.py"
duration = run_benchmark(
scanner_path=scanner_path,
root_path=str(tmp_path),
package_file=str(package_file),
dependency="python",
version="3.7"
)
assert isinstance(duration, float)
assert duration >= 0
# Test run_benchmarks
@patch('benchmark.run_benchmark')
def test_run_benchmarks(mock_run, tmp_path):
mock_run.return_value = 1.5
packages_dir = tmp_path / "packages"
packages_dir.mkdir()
for i in range(5):
(packages_dir / f"pkg_{i}").mkdir()
results = run_benchmarks(
scanner_path="dummy.py",
root_path=str(tmp_path),
packages_dir=str(packages_dir),
counts=[1, 3],
dependency="python",
version="3.7"
)
assert len(results) == 2
assert results[1] == 1.5
assert results[3] == 1.5
assert mock_run.call_count == 2