forked from yusufkaraaslan/Skill_Seekers
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_estimate_pages.py
More file actions
187 lines (142 loc) · 6.48 KB
/
test_estimate_pages.py
File metadata and controls
187 lines (142 loc) · 6.48 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/env python3
"""
Tests for cli/estimate_pages.py functionality
"""
import json
import unittest
from pathlib import Path
from skill_seekers.cli.estimate_pages import estimate_pages
class TestEstimatePages(unittest.TestCase):
"""Test estimate_pages function"""
def test_estimate_pages_with_minimal_config(self):
"""Test estimation with minimal configuration"""
config = {"name": "test", "base_url": "https://example.com/", "rate_limit": 0.1}
# This will make real HTTP request to example.com
# We use low max_discovery to keep test fast
result = estimate_pages(config, max_discovery=2, timeout=5)
# Check result structure
self.assertIsInstance(result, dict)
self.assertIn("discovered", result)
self.assertIn("estimated_total", result)
# Actual key is elapsed_seconds, not time_elapsed
self.assertIn("elapsed_seconds", result)
def test_estimate_pages_returns_discovered_count(self):
"""Test that result contains discovered page count"""
config = {"name": "test", "base_url": "https://example.com/", "rate_limit": 0.1}
result = estimate_pages(config, max_discovery=1, timeout=5)
self.assertGreaterEqual(result["discovered"], 0)
self.assertIsInstance(result["discovered"], int)
def test_estimate_pages_respects_max_discovery(self):
"""Test that estimation respects max_discovery limit"""
config = {"name": "test", "base_url": "https://example.com/", "rate_limit": 0.1}
result = estimate_pages(config, max_discovery=3, timeout=5)
# Should not discover more than max_discovery
self.assertLessEqual(result["discovered"], 3)
def test_estimate_pages_with_start_urls(self):
"""Test estimation with custom start_urls"""
config = {
"name": "test",
"base_url": "https://example.com/",
"start_urls": ["https://example.com/"],
"rate_limit": 0.1,
}
result = estimate_pages(config, max_discovery=2, timeout=5)
self.assertIsInstance(result, dict)
self.assertIn("discovered", result)
class TestEstimatePagesCLI(unittest.TestCase):
"""Test estimate_pages command-line interface (via entry point)"""
def test_cli_help_output(self):
"""Test that skill-seekers estimate --help works"""
import subprocess
try:
result = subprocess.run(
["skill-seekers", "estimate", "--help"], capture_output=True, text=True, timeout=5
)
# Should return successfully (0 or 2 for argparse)
self.assertIn(result.returncode, [0, 2])
output = result.stdout + result.stderr
self.assertTrue("usage:" in output.lower() or "estimate" in output.lower())
except FileNotFoundError:
self.skipTest("skill-seekers command not installed")
def test_cli_executes_with_help_flag(self):
"""Test that skill-seekers-estimate entry point works"""
import subprocess
try:
result = subprocess.run(
["skill-seekers-estimate", "--help"], capture_output=True, text=True, timeout=5
)
# Should return successfully
self.assertIn(result.returncode, [0, 2])
except FileNotFoundError:
self.skipTest("skill-seekers-estimate command not installed")
def test_cli_requires_config_argument(self):
"""Test that CLI requires config file argument"""
import subprocess
try:
# Run without config argument
result = subprocess.run(
["skill-seekers", "estimate"], capture_output=True, text=True, timeout=5
)
# Should fail (non-zero exit code) or show usage
self.assertTrue(
result.returncode != 0
or "usage" in result.stderr.lower()
or "usage" in result.stdout.lower()
)
except FileNotFoundError:
self.skipTest("skill-seekers command not installed")
def test_cli_all_flag_lists_configs(self):
"""Test that --all flag lists all available configs"""
import subprocess
try:
# Run with --all flag
result = subprocess.run(
["skill-seekers", "estimate", "--all"], capture_output=True, text=True, timeout=10
)
# Should succeed
self.assertEqual(result.returncode, 0)
# Should contain expected output
output = result.stdout
self.assertIn("AVAILABLE CONFIGS", output)
self.assertIn("Total:", output)
self.assertIn("configs found", output)
# Should list some known configs
# (these should exist in api/configs_repo/official/)
self.assertTrue(
"react" in output.lower()
or "django" in output.lower()
or "godot" in output.lower(),
"Expected at least one known config name in output",
)
except FileNotFoundError:
self.skipTest("skill-seekers command not installed")
def test_cli_all_flag_with_direct_entry_point(self):
"""Test --all flag works with skill-seekers-estimate entry point"""
import subprocess
try:
result = subprocess.run(
["skill-seekers-estimate", "--all"], capture_output=True, text=True, timeout=10
)
# Should succeed
self.assertEqual(result.returncode, 0)
# Should show available configs
output = result.stdout
self.assertIn("AVAILABLE CONFIGS", output)
except FileNotFoundError:
self.skipTest("skill-seekers-estimate command not installed")
class TestEstimatePagesWithRealConfig(unittest.TestCase):
"""Test estimation with real config files (if available)"""
def test_estimate_with_real_config_file(self):
"""Test estimation using a real config file (if exists)"""
config_path = Path("configs/react.json")
if not config_path.exists():
self.skipTest("configs/react.json not found")
with open(config_path) as f:
config = json.load(f)
# Use very low max_discovery to keep test fast
result = estimate_pages(config, max_discovery=3, timeout=5)
self.assertIsInstance(result, dict)
self.assertIn("discovered", result)
self.assertGreater(result["discovered"], 0)
if __name__ == "__main__":
unittest.main()