-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_basic.py
More file actions
151 lines (116 loc) · 4.57 KB
/
Copy pathtest_basic.py
File metadata and controls
151 lines (116 loc) · 4.57 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
"""
Basic tests for VARIABOT to prevent workflow failures.
This file ensures pytest has tests to run and prevents CI failures.
"""
import pytest
import os
from pathlib import Path
def test_repository_structure():
"""Test that required files exist in the repository."""
required_files = [
'README.md',
'requirements.txt',
'st-Qwen1.5-110B-Chat.py',
'st-Phi3Mini-128k-Chat.py',
'st-Openelm-3B.py',
'st-Qwen1.5-MoE-A2.7B-Chat.py'
]
for file_path in required_files:
assert Path(file_path).exists(), f"Required file {file_path} not found"
def test_requirements_file():
"""Test that requirements.txt is readable and contains dependencies."""
requirements_path = Path('requirements.txt')
assert requirements_path.exists(), "requirements.txt not found"
with open(requirements_path, 'r') as f:
content = f.read().strip()
assert content, "requirements.txt is empty"
assert 'streamlit' in content.lower(), "Streamlit dependency not found"
def test_reference_vault_exists():
"""Test that reference vault directory exists."""
vault_path = Path('reference_vault')
assert vault_path.exists(), "reference_vault directory not found"
assert vault_path.is_dir(), "reference_vault is not a directory"
def test_python_files_syntax():
"""Test that Python files have valid syntax."""
python_files = [
'st-Qwen1.5-110B-Chat.py',
'st-Phi3Mini-128k-Chat.py',
'st-Openelm-3B.py',
'st-Qwen1.5-MoE-A2.7B-Chat.py',
'Qwen110BChat.py'
]
for file_path in python_files:
if Path(file_path).exists():
with open(file_path, 'r', encoding='utf-8') as f:
content = f.read()
# Basic syntax check - try to compile
try:
compile(content, file_path, 'exec')
except SyntaxError as e:
pytest.fail(f"Syntax error in {file_path}: {e}")
def test_import_statements():
"""Test that required imports are available."""
try:
import streamlit
assert streamlit.__version__, "Streamlit version not accessible"
except ImportError:
pytest.skip("Streamlit not installed - skipping import test")
# Test other critical imports
import sys
import os
import time
assert sys.version_info >= (3, 7), "Python version too old"
def test_environment_variables():
"""Test environment variable handling."""
# Test that we can handle missing HF_TOKEN gracefully
original_token = os.environ.get('HF_TOKEN')
# Remove token temporarily
if 'HF_TOKEN' in os.environ:
del os.environ['HF_TOKEN']
# Test graceful handling
token = os.getenv('HF_TOKEN', 'default_token')
assert token == 'default_token', "Default token handling failed"
# Restore original token if it existed
if original_token:
os.environ['HF_TOKEN'] = original_token
def test_file_permissions():
"""Test that Python files are readable."""
python_files = list(Path('.').glob('*.py'))
for file_path in python_files:
assert os.access(file_path, os.R_OK), f"Cannot read {file_path}"
@pytest.mark.parametrize("model_file", [
'st-Qwen1.5-110B-Chat.py',
'st-Phi3Mini-128k-Chat.py',
'st-Openelm-3B.py',
'st-Qwen1.5-MoE-A2.7B-Chat.py'
])
def test_model_files_contain_client(model_file):
"""Test that model files contain Client import and usage."""
if not Path(model_file).exists():
pytest.skip(f"{model_file} not found")
with open(model_file, 'r', encoding='utf-8') as f:
content = f.read()
assert 'from gradio_client import Client' in content, f"{model_file} missing gradio_client import"
assert 'Client(' in content, f"{model_file} missing Client instantiation"
def test_reference_vault_files():
"""Test that reference vault contains expected documentation."""
vault_path = Path('reference_vault')
if not vault_path.exists():
pytest.skip("reference_vault directory not found")
expected_files = [
'README.md',
'standards.md',
'external_sources.md',
'industry_lists.md',
'networking_cheatsheet.md',
'copilot_instructions.md',
'audit_trail.md',
'linux_kali_android.md',
'PRODUCTION_GRADE_STANDARDS.md'
]
for file_name in expected_files:
file_path = vault_path / file_name
if file_path.exists():
assert file_path.stat().st_size > 0, f"{file_name} is empty"
if __name__ == "__main__":
pytest.main([__file__])