-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_modules.py
More file actions
131 lines (106 loc) Β· 4.35 KB
/
test_modules.py
File metadata and controls
131 lines (106 loc) Β· 4.35 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
#!/usr/bin/env python3
"""
Quick test script to verify all modules can be imported correctly
"""
import sys
import os
# Add project root to path
current_dir = os.path.dirname(os.path.abspath(__file__))
if current_dir not in sys.path:
sys.path.insert(0, current_dir)
def test_imports():
"""Test that all modules can be imported"""
print("π§ͺ Testing module imports...")
modules_to_test = [
'github_protection_agent.utils',
'github_protection_agent.repository_analyzer',
'github_protection_agent.security_scanner',
'github_protection_agent.secret_patterns',
'github_protection_agent.url_processor',
'github_protection_agent.violation_detector',
'github_protection_agent.report_generator',
'github_protection_agent.dmca_generator',
'github_protection_agent.license_generator',
'github_protection_agent.github_scanner',
'github_protection_agent.bounty_system',
'github_protection_agent.enhanced_ipfs_manager',
'github_protection_agent.filecoin_contracts',
'github_protection_agent.blockchain_utilities',
'github_protection_agent.complete_filecoin_agent'
]
success_count = 0
for module_name in modules_to_test:
try:
__import__(module_name)
print(f" β
{module_name}")
success_count += 1
except ImportError as e:
print(f" β {module_name}: {e}")
except Exception as e:
print(f" β οΈ {module_name}: {e}")
print(f"\nπ Import Results: {success_count}/{len(modules_to_test)} modules imported successfully")
if success_count == len(modules_to_test):
print("π All modules imported successfully!")
return True
else:
print("β οΈ Some modules failed to import")
return False
def test_basic_functionality():
"""Test basic functionality of key modules"""
print("\nπ§ Testing basic functionality...")
try:
# Test URLProcessor
from github_protection_agent.url_processor import URLProcessor
# Create a mock LLM
class MockLLM:
def invoke(self, prompt):
class MockResponse:
content = "Mock AI response"
return MockResponse()
url_processor = URLProcessor(MockLLM())
result = url_processor.clean_single_url('https://github.com/octocat/Hello-World')
if result['success']:
print(" β
URLProcessor working")
else:
print(f" β URLProcessor failed: {result['error']}")
# Test SecretPatterns
from github_protection_agent.secret_patterns import SecretPatterns
patterns = SecretPatterns()
pattern_dict = patterns.get_patterns()
if len(pattern_dict) > 0:
print(f" β
SecretPatterns loaded {len(pattern_dict)} patterns")
else:
print(" β SecretPatterns failed to load patterns")
# Test blockchain utilities
from github_protection_agent.blockchain_utilities import BlockchainUtils
utils = BlockchainUtils()
test_data = {'url': 'https://github.com/test/repo', 'name': 'test'}
hash_result = utils.generate_repo_hash(test_data)
if len(hash_result) == 64: # SHA256 hex length
print(" β
BlockchainUtils working")
else:
print(" β BlockchainUtils hash generation failed")
print("β
Basic functionality tests passed!")
return True
except Exception as e:
print(f"β Basic functionality test failed: {e}")
return False
def main():
"""Run all tests"""
print("π‘οΈ FILECOIN GITHUB PROTECTION AGENT - MODULE TESTS")
print("=" * 60)
# Test imports
imports_ok = test_imports()
if imports_ok:
# Test functionality
functionality_ok = test_basic_functionality()
if functionality_ok:
print(f"\nπ ALL TESTS PASSED!")
print("π Ready to run the agent with: python run_agent.py")
else:
print(f"\nβ οΈ Import tests passed but functionality tests failed")
else:
print(f"\nβ Import tests failed - fix missing modules first")
print("=" * 60)
if __name__ == "__main__":
main()