Good first attempt at size test, still a lot of nightmare to cleanup
This commit is contained in:
parent
b83e1a8f78
commit
d33d146224
File diff suppressed because it is too large
Load Diff
|
|
@ -25,8 +25,8 @@ if __name__ == "__main__":
|
|||
# print(" > No user database was found, the bundled one will be used.")
|
||||
|
||||
# Will always try to load discordHelper/discordHelper.json # TODO : Document this feature.
|
||||
run_db = os.path.join(directory_path, "discordHelper_last_run.json")
|
||||
argv = rf"--all --autodetect --launch --continue --timeout 10 {db_path}--gen-data {run_db} --db discordHelper/discordHelper.json".split(" ")
|
||||
run_db = os.path.join(directory_path, "test_results_found.json")
|
||||
argv = rf"--all --autodetect --launch --continue --timeout 10 {db_path}--gen-data {run_db} --db discordHelper/test_results.json".split(" ")
|
||||
|
||||
# print(" > Starting the discordHelper with the following arguments:")
|
||||
# print(" > " + " ".join(argv))
|
||||
|
|
|
|||
|
|
@ -174,7 +174,16 @@ class AgnosticPaths:
|
|||
return [os.path.join(dirpath, filename)
|
||||
for dirpath, dirnames, filenames in os.walk(self(*args))
|
||||
for filename in filenames]
|
||||
|
||||
|
||||
def get_short_path(self, path):
|
||||
"""
|
||||
Get the short path of the given path
|
||||
:param path: The path
|
||||
:return: The short path
|
||||
:rtype: str
|
||||
"""
|
||||
return os.path.relpath(path, self.main_path)
|
||||
|
||||
def __repr__(self):
|
||||
"""
|
||||
:return: A representation of the AgnosticPath
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ def parse(_args):
|
|||
parser.add_argument("--pollrate", "--poll", default=0.1, type=float, help="Refresh rate of the status, 0.1 is the default")
|
||||
parser.add_argument("--printrate", "-refresh", default=5, type=int, help="Print the tests every X seconds")
|
||||
parser.add_argument("--size", "--window-size", default=120, type=int, help="Size of the message window")
|
||||
parser.add_argument("--max-shown", default=5, type=int, help="Maximum number of errors shown")
|
||||
|
||||
# Tests
|
||||
parser.add_argument('--spidey', action='store_true', help='Runs the spidey test')
|
||||
parser.add_argument('--line-count', action='store_true', help='Test all known files for line count')
|
||||
|
|
@ -43,5 +45,6 @@ def parse(_args):
|
|||
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("--test-walk", action="store_true", help="Test walk function")
|
||||
parser.add_argument("--max-errors", default=5, type=int, help="Maximum number of errors before the analysis is stopped")
|
||||
|
||||
return parser.parse_args(_args)
|
||||
|
|
|
|||
|
|
@ -96,20 +96,24 @@ class TestRunner:
|
|||
"""
|
||||
Opens the base data file
|
||||
"""
|
||||
|
||||
default_database = resource_path(self.agnostic_path.default_database)
|
||||
if not self.args.database:
|
||||
self.args.database = default_database
|
||||
|
||||
if os.path.exists(self.args.database):
|
||||
print(colored(f" > Opening specified database {self.args.database}", "green")) # TODO : Only if verbose
|
||||
with open(resource_path(self.args.database), "r") as f:
|
||||
self.base_data = json.load(f)
|
||||
|
||||
elif os.path.exists(default_database): # Try opening the default database
|
||||
# print(colored(
|
||||
# "\n > The database file specified does not exist, "
|
||||
# "trying to open the default one for your os...\n", "yellow"
|
||||
# ))
|
||||
return self.base_data
|
||||
elif os.path.exists(resource_path(default_database)): # Try opening the default database
|
||||
print(colored(
|
||||
"\n > The database file specified does not exist, "
|
||||
"trying to open the default one for your os...\n", "yellow"
|
||||
))
|
||||
with open(resource_path(default_database), "r") as f:
|
||||
self.base_data = json.load(f)
|
||||
return self.base_data
|
||||
|
||||
else:
|
||||
print(colored(
|
||||
|
|
@ -117,6 +121,7 @@ class TestRunner:
|
|||
"one for your os does not exist either.\n", "red"
|
||||
))
|
||||
self.base_data = {}
|
||||
return self.base_data
|
||||
|
||||
def update_module_list(self):
|
||||
"""
|
||||
|
|
@ -150,7 +155,7 @@ class TestRunner:
|
|||
tc = test_class(
|
||||
self.args,
|
||||
self.agnostic_path,
|
||||
None,
|
||||
self.base_data,
|
||||
self.finished_tests,
|
||||
queue_lock,
|
||||
self.dict_of_processes,
|
||||
|
|
@ -178,7 +183,6 @@ class TestRunner:
|
|||
tc.daemon = True
|
||||
tc.start()
|
||||
|
||||
|
||||
def controller_test(self):
|
||||
"""
|
||||
Kills the tests if the user press enter
|
||||
|
|
@ -441,9 +445,13 @@ def print_final_status(testrunner, start_time, args):
|
|||
print(colored(f" > {fill_it(SIZE,test,'SUCCESS')}", "green"))
|
||||
elif test_object.status_code == "failure":
|
||||
print(colored(f" > {fill_it(SIZE,test,'FAILURE')}", "red"))
|
||||
print(colored(f"{fit_it_under(test_object.status ,SIZE-3, ' > ')}", "red"))
|
||||
error_message = fit_it_under(test_object.status ,SIZE-3, ' > ')
|
||||
if args.max_shown != -1: # TODO : Correct this abomination
|
||||
table = error_message.split("\n")
|
||||
error_message = "\n".join(table[:args.max_shown] + [f" > ... {len(table) - args.max_shown} more lines"])
|
||||
print(colored(f"{error_message}", "red"))
|
||||
else:
|
||||
print(colored(f" > {test} {fill_it(SIZE,test,test_object.status_code.upper())}", "yellow"))
|
||||
print(colored(f" > {fill_it(SIZE,test,test_object.status_code.upper())}", "yellow"))
|
||||
msg_error = "sucessfully" if status.tests_failed == 0 else f"with {status.tests_error} errors"
|
||||
print(colored(f"\nThe program executed {msg_error}, exiting in {args.timeout} seconds...", color))
|
||||
|
||||
|
|
|
|||
|
|
@ -21,15 +21,17 @@ class SizeTest(test_template.TestWalkTemplate):
|
|||
self.set_status("running")
|
||||
size = len(self.walk())
|
||||
error_msg = ""
|
||||
for path in self.walk():
|
||||
for i, path in enumerate(self.walk()):
|
||||
self.progress = int(100*i/size)
|
||||
short_path = self.agnostic_path.get_short_path(path)
|
||||
if os.path.isfile(path):
|
||||
if not self.compare(path, "size", os.path.getsize, (), {}):
|
||||
self.add_failure(path, f"Test {self.name()} failed on {path}")
|
||||
error_msg += f"{path} is " \
|
||||
f"({self.get_expected_result(path, 'size')} b) not ({os.path.getsize(path)} b).\n"
|
||||
self.add_failure(path, f"Test {self.name()} failed on {short_path}")
|
||||
error_msg += f"{short_path} is " \
|
||||
f"({os.path.getsize(path)} b) not ({self.get_expected_result(path, 'size')} b).\n"
|
||||
self.is_infected = True
|
||||
if not self.args.continue_on_error:
|
||||
return self.finish("failure", f"{path} is supposed to be {self.get_expected_result(path, 'size')} bytes, but it is {os.path.getsize(path)} bytes.")
|
||||
return self.finish("failure", f"{short_path} is supposed to be {self.get_expected_result(path, 'size')} bytes, but it is {os.path.getsize(path)} bytes.")
|
||||
|
||||
if self.is_infected:
|
||||
return self.finish(
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ class TestTemplate:
|
|||
:param agnpath: The path to the discord folder
|
||||
:type agnpath: agnostic_path.AgnosticPath
|
||||
:param test_data: The data to be tested
|
||||
:type test_data: str
|
||||
:type test_data: dict
|
||||
:param queue: The queue to put the test status in
|
||||
:type queue: queue.deque
|
||||
:param queue_lock: The lock to use when putting the test status in the queue
|
||||
|
|
@ -179,6 +179,7 @@ class TestWalkTemplate(TestTemplate):
|
|||
:type result: any
|
||||
"""
|
||||
|
||||
path = self.agnostic_path.get_short_path(path)
|
||||
if path not in self.new_data:
|
||||
self.new_data[path] = {}
|
||||
self.new_data[path][testname] = result
|
||||
|
|
@ -194,6 +195,7 @@ class TestWalkTemplate(TestTemplate):
|
|||
:return: Test data
|
||||
:rtype: any
|
||||
"""
|
||||
path = self.agnostic_path.get_short_path(path)
|
||||
if path in self.new_data:
|
||||
if testname in self.new_data[path]:
|
||||
return self.new_data[path][testname]
|
||||
|
|
@ -210,9 +212,11 @@ class TestWalkTemplate(TestTemplate):
|
|||
:rtype: any
|
||||
"""
|
||||
if self.test_data:
|
||||
if path in self.test_data:
|
||||
if testname in self.test_data[path]:
|
||||
return self.test_data[path][testname]
|
||||
path = self.agnostic_path.get_short_path(path)
|
||||
if "tests" in self.test_data:
|
||||
if path in self.test_data["tests"]:
|
||||
if testname in self.test_data["tests"][path]:
|
||||
return self.test_data["tests"][path][testname]
|
||||
return None
|
||||
|
||||
def run_test(self):
|
||||
|
|
|
|||
Reference in New Issue