This repository has been archived on 2026-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
SpideyDetector/modules/test_interface.py

77 lines
2.2 KiB
Python

import os
import re
import sys
import importlib
_TEST_MODULES = { # argparse argument : [module_name, class_name]
"spidey": ["spidey_test", "SpideyTest"],
}
class SpideyDetector:
def __init__(self, args, agnpath):
"""
Main spidey runner
:param args: List of arguments
:type args: argparse.Namespace
:param agnpath: The path to the discord folder
:type agnpath: agnostic_path.AgnosticPath
"""
self.ptb = args.ptb
self.args = args
self.agnostic_path = agnpath
self.os_name = agnpath.os
self.main_path = agnpath.main_path
self.version = agnpath.version
# self.is_windows = self.check_os()
self.is_infected = 0
self.detections = 0
self.test_run = {}
self.loaded_test_modules = {}
self.loaded_test_classes = {}
self.update_module_list()
self.exec_all_tests()
def update_module_list(self):
"""
Gets the list of modules to be loaded (in accordance to the config)
:return: List of modules
:rtype: list
"""
modules = {}
classes = {}
try:
for module_name, values in _TEST_MODULES.items():
print(values[0])
if self.args.__getattribute__(module_name):
modules[values[0]] = importlib.import_module(f"modules.{values[0]}")
classes[values[0]] = getattr(modules[values[0]], values[1])
except AttributeError:
print(f"The module {module_name} was not loaded because it was not specified in the config.")
self.loaded_test_modules.update(modules)
self.loaded_test_classes.update(classes)
def exec_all_tests(self):
"""
Executes all the tests
:return:
"""
for module_name, test_class in self.loaded_test_classes.items():
tc = test_class(self.args, self.agnostic_path, None)
tc.run_test()
print(tc)
def run_check(args, agnpath):
spd = SpideyDetector(args, agnpath)
if not spd.is_infected:
return 0
else:
return 1
if __name__ == "__main__":
pass