diff --git a/modules/argument_parser.py b/modules/argument_parser.py index 730d167..00d40d7 100644 --- a/modules/argument_parser.py +++ b/modules/argument_parser.py @@ -29,7 +29,7 @@ def parse(_args): 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("--database", "--db", nargs=1, default="", help="Alternative database for the analysis") - parser.add_argument("--continue", action="store_true", help="Continue the analysis in case of failure") + 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") return parser.parse_args(_args) diff --git a/modules/internal_io.py b/modules/internal_io.py index af1784d..47653b2 100644 --- a/modules/internal_io.py +++ b/modules/internal_io.py @@ -7,7 +7,7 @@ from collections import namedtuple global_status = namedtuple( 'global_status', - 'total_tests, tests_finished, test_success, tests_failed, tests_running, tests_skipped, test_error', + '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)) diff --git a/modules/spidey_test.py b/modules/spidey_test.py index f06b058..1238efc 100644 --- a/modules/spidey_test.py +++ b/modules/spidey_test.py @@ -26,7 +26,7 @@ class SpideyTest(test_template.TestTemplate): :return: Whether any of the index.js is more than one line :rtype: bool """ - + self.set_status("running") self.slowdown() # This function is only used for testing paths = self.get_path() self.is_infected = False @@ -50,9 +50,9 @@ class SpideyTest(test_template.TestTemplate): "is corrupted. We suggest uninstalling discord and deleting all its files before reinstalling.\n" "If you've recently downloaded a .exe directly sent from someone, " "do also consider a clean windows reinstall.") - print("Spidey test finished") + print("Spidey test finished") # TODO : set a status here, explaining and why the test finished - self.finish("success") + return self.finish("success") def get_path(self): """ diff --git a/modules/test_interface.py b/modules/test_interface.py index dca8d48..f769ef3 100644 --- a/modules/test_interface.py +++ b/modules/test_interface.py @@ -2,9 +2,8 @@ import sys import importlib import threading import time -import queue from collections import deque -from modules.internal_io import global_status, test_status, return_code_dict +from modules.internal_io import global_status # , test_status, return_code_dict """ All modules that can be tested @@ -183,12 +182,13 @@ class TestRunner: nb_tests_ran = nb_tests_success + nb_tests_failure + nb_tests_skipped nb_test_running = nb_tests - nb_tests_ran return global_status( - total_tests=nb_test_running, - test_success=nb_tests_success, + tests_total=nb_tests, tests_finished=nb_tests_ran, + test_success=nb_tests_success, tests_failed=nb_tests_failure, tests_running=nb_test_running, tests_skipped=nb_tests_skipped, + tests_error=nb_tests_failure ) @@ -203,8 +203,8 @@ def run_check(args, agnpath): print("Waiting for the end of the tests") while tr.get_exit_code() == -1: - print(tr.get_status()) + 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()) + print(tr.get_status()) # TODO: Print the final status, test still running are actually skipped sys.exit(tr.get_exit_code()) diff --git a/modules/test_template.py b/modules/test_template.py index 9d80065..8294b4f 100644 --- a/modules/test_template.py +++ b/modules/test_template.py @@ -4,12 +4,14 @@ A global template for all tests. from modules import internal_io + class TestDataError(Exception): """ Raised when the data is not valid. """ pass + class TestTemplate: def __init__(self, args, agnpath, test_data, queue, queue_lock): """ @@ -25,6 +27,7 @@ class TestTemplate: :param queue_lock: The lock to use when putting the test status in the queue :type queue_lock: threading.Lock """ + self.args = args self.ptb = args.ptb self.agnostic_path = agnpath self.os_name = agnpath.os @@ -106,6 +109,13 @@ class TestTemplate: self.queue_lock.release() return self.get_status_code() + def __del__(self): + """ + Destructor. + """ + if self.status_code == "running": + return self.finish("skipped") + class TestWalkTemplate(TestTemplate): def __init__(self, args, agnpath, test_data, queue, queue_lock): @@ -124,16 +134,17 @@ class TestWalkTemplate(TestTemplate): self.set_status("problem", "No test data given.") def run_test(self): - - self.finish() - return - if self.test_data is None: + 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.get_status() + 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("sucess", "The test was a success but kinda not a success.") + self.set_status("success", "The test was a success but kinda not a success.") + self.finish() + return def walk(self): """ @@ -160,6 +171,8 @@ class TestWalkTemplate(TestTemplate): try: self.data[path] = function(path, *args, **kwargs) + if not self.test_data: + raise TestDataError("No test data given.") if path not in self.test_data["files"]: raise TestDataError("No entry in test data for path: " + str(path)) if entry_name not in self.test_data["files"][path]: