-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest_package.py
More file actions
78 lines (67 loc) · 2.02 KB
/
test_package.py
File metadata and controls
78 lines (67 loc) · 2.02 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
#!/usr/bin/env python3
"""
Simple test to verify the package works correctly.
This is a basic test that can be run by CI/CD.
"""
import sys
import os
def test_import():
"""Test that the package can be imported."""
try:
import twobitreader
print("✅ Package imports successfully")
return True
except ImportError as e:
print(f"❌ Failed to import package: {e}")
return False
def test_version():
"""Test that we can get version information."""
try:
import twobitreader
# Check if __version__ exists
if hasattr(twobitreader, '__version__'):
print(f"✅ Version: {twobitreader.__version__}")
else:
print("⚠️ No __version__ attribute found")
return True
except Exception as e:
print(f"❌ Failed to get version: {e}")
return False
def test_cli():
"""Test that the CLI module can be run."""
try:
import subprocess
result = subprocess.run([sys.executable, '-m', 'twobitreader', '--help'],
capture_output=True, text=True, timeout=10)
if result.returncode == 0:
print("✅ CLI help works")
return True
else:
print(f"⚠️ CLI help returned code {result.returncode}")
return True # Don't fail if help isn't implemented
except Exception as e:
print(f"⚠️ CLI test failed: {e}")
return True # Don't fail if CLI isn't implemented
def main():
"""Run all tests."""
print("Running basic package tests...")
tests = [
test_import,
test_version,
test_cli,
]
passed = 0
total = len(tests)
for test in tests:
if test():
passed += 1
print()
print(f"Tests passed: {passed}/{total}")
if passed == total:
print("🎉 All tests passed!")
return 0
else:
print("❌ Some tests failed!")
return 1
if __name__ == '__main__':
sys.exit(main())