-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_basic.py
More file actions
64 lines (44 loc) · 1.64 KB
/
Copy pathtest_basic.py
File metadata and controls
64 lines (44 loc) · 1.64 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
#!/usr/bin/env python3
"""
Basic test script for Code Translator application
"""
import sys
from pathlib import Path
# Add src to path for imports
sys.path.insert(0, str(Path(__file__).parent / "src"))
from translator.offline_translator import OfflineTranslator
from config.settings import Settings
def test_offline_translation():
"""Test offline translation capabilities"""
print("Testing offline translation...")
offline = OfflineTranslator()
# Test Python to JavaScript
python_code = """def greet(name):
return f"Hello, {name}!"
print(greet("World"))"""
js_result = offline.translate(python_code, "Python", "JavaScript")
print(f"\nPython to JavaScript:\nOriginal:\n{python_code}\n\nTranslated:\n{js_result}")
# Test JavaScript to Python
js_code = """function add(a, b) {
return a + b;
}
console.log(add(5, 3));"""
py_result = offline.translate(js_code, "JavaScript", "Python")
print(f"\nJavaScript to Python:\nOriginal:\n{js_code}\n\nTranslated:\n{py_result}")
def test_settings():
"""Test settings management"""
print("\nTesting settings...")
settings = Settings()
# Test setting and getting values
settings.set("test_value", "hello")
assert settings.get("test_value") == "hello", "Failed to set/get value"
# Test defaults
assert settings.get("window_opacity") == 0.95, "Default value not applied"
print("Settings tests passed!")
if __name__ == "__main__":
print("Code Translator Test Suite")
print("=" * 50)
test_offline_translation()
test_settings()
print("\n" + "=" * 50)
print("All tests completed!")