First draft of the windows executable

This commit is contained in:
Maximilien Rigaut 2022-06-23 19:56:18 +02:00
parent 0b062bc26b
commit 5c0749c2a0
No known key found for this signature in database
GPG Key ID: 4F14B23709ADA5B1
6 changed files with 77 additions and 11 deletions

View File

@ -6,8 +6,16 @@ from modules import test_interface, agnostic_paths, argument_parser
import sys
def main(argm):
"""
Main program
:param argm: List of arguments
:type argm: argparse.Namespace
"""
agnostic_path = agnostic_paths.AgnosticPaths(argm.ptb, argm.force_path)
test_runner = test_interface.TestRunner(argm, agnostic_path)
if __name__ == "__main__":
args = argument_parser.parse(sys.argv[1:])
agnostic_path = agnostic_paths.AgnosticPaths(ptb=args.ptb, force_path=args.force_path)
test_interface.run_check(args, agnostic_path)
main(args)

19
discordHelperWin.py Normal file
View File

@ -0,0 +1,19 @@
"""
A windows executable for the discordHelper.py script.
"""
import sys
import discordHelper
# All modules must be loaded before the main program is run.
from modules import spidey_test, test_template
if __name__ == "__main__":
argv = sys.argv[1:]
if len(argv) <= 1:
argv += "--spidey --launch --test-walk --continue --gen-data new.yaml".split(" ")
args = discordHelper.argument_parser.parse(argv)
discordHelper.main(args)

View File

@ -26,8 +26,7 @@ def parse(_args):
parser.add_argument("--only-known-paths", "--fast", action='store_true', help="Only run the check on the known paths")
parser.add_argument("--no-eval", action="store_true", help="Check for the eval function wich is a HUGE red flag")
parser.add_argument("--const-abuse", "--no-const", action="store_true", help="Check for the abuse of the const: keyword, wich is massively used for obfucation")
parser.add_argument("--gen-data", "--generate-data", "--gen", action="store_true", help="Generate data for the analysis")
parser.add_argument("--gen-data-path", "--generate-data-path", "--gen-path", nargs=1, default="", help="Path to generate the data in")
parser.add_argument("--gen-data", "--generate-data", "--gen", nargs=1, default="", help="Generate data for the analysis")
parser.add_argument("--database", "--db", nargs=1, default="", help="Alternative database for the analysis")
parser.add_argument("--continue_on_error", "--continue", action="store_true", help="Continue the analysis in case of failure")
parser.add_argument("--test-walk", action="store_true", help="Test walk function")

View File

@ -10,7 +10,7 @@ global_status = namedtuple(
'tests_total, tests_finished, test_success, tests_failed, tests_running, tests_skipped, tests_error',
defaults=(0, 0, 0, 0, 0, 0, 0)
)
test_status = namedtuple('test_status', 'name, status, message', defaults=(None, None, None))
test_status = namedtuple('test_status', 'name, status, message, failure_dict, data', defaults=(None, None, None, {}, {}))
return_code_dict = {
"skipped": "The test was not run",
"running": "The test is running",

View File

@ -191,6 +191,18 @@ class TestRunner:
tests_error=nb_tests_failure
)
def get_test_data(self):
"""
Gets the test data
:return: The test data
:rtype: dict
"""
data = {}
queue_lock.acquire()
for test in self.finished_tests:
data[test.name] = test.data
queue_lock.release()
return data
def run_check(args, agnpath):
"""
@ -206,5 +218,10 @@ def run_check(args, agnpath):
print(tr.get_status()) # TODO : Print status in a more readable way
time.sleep(0.5)
print("The test sequence is now finished")
print(tr.get_status()) # TODO: Print the final status, test still running are actually skipped
if args.gen_data:
print("Generating data...")
# print(tr.get_test_data()) # TODO: Transorm the data into a yaml or json file
time.sleep(2)
sys.exit(tr.get_exit_code())

View File

@ -39,6 +39,8 @@ class TestTemplate:
self.queue = queue
self.set_status("idle")
self.queue_lock = queue_lock
self.failure_dict = {}
self.data = {}
def run_test(self):
"""
@ -67,7 +69,7 @@ class TestTemplate:
:return: Status at the time of call.
:rtype: internal_io.test_status
"""
return internal_io.test_status(self.name(), self.status_code, self.status)
return internal_io.test_status(self.name(), self.status_code, self.status, self.failure_dict, self.data)
@staticmethod
def get_status_from_code(code):
@ -109,6 +111,16 @@ class TestTemplate:
self.queue_lock.release()
return self.get_status_code()
def add_failure(self, path, message):
"""
Adds a failure to the failure dictionary.
:param path: Path to the file that failed
:type path: str
:param message: Message to add
:type message: str
"""
self.failure_dict[path] = message
def __del__(self):
"""
Destructor.
@ -135,16 +147,25 @@ class TestWalkTemplate(TestTemplate):
def run_test(self):
self.set_status("running", "The test will begin shortly, please wait...")
if self.test_data is None and not self.args.continue_on_error:
self.set_status("problem", "No test data given.")
return self.finish()
self.set_status("running", "The test will begin shortly, please wait...")
for path in self.walk():
self.compare(path, "test", lambda x: True, [], {})
self.set_status("success", "The test was a success but kinda not a success.")
self.finish()
return
if not self.compare(path, "test", lambda x: True, [], {}):
self.add_failure(path, f"Test {self.name()} failed on {path}")
if not self.args.continue_on_error:
self.set_status("failure", f"Test {self.name()} failed on {path}")
return self.finish()
if len(self.failure_dict) > 0:
self.set_status("failure", f"Test {self.name()} failed on {len(self.failure_dict)} files.")
else:
self.set_status("success", f"Test {self.name()} passed.")
return self.finish()
def walk(self):
"""
@ -186,3 +207,5 @@ class TestWalkTemplate(TestTemplate):
if not self.args.continue_on_error:
self.set_status("error", "Error: " + str(e))
raise e
finally:
return False