Merge pull request #14 from idle-org/feature/refactor_tests
Feature/refactor tests
This commit is contained in:
commit
b7c07e32dd
|
|
@ -5,13 +5,17 @@ Internal interfacting objects.
|
|||
from collections import namedtuple
|
||||
|
||||
|
||||
global_status = namedtuple('global_status', 'total_tests, tests_finished, tests_failed, tests_running, tests_skipped', defaults=(0, 0, 0, 0, 0))
|
||||
global_status = namedtuple(
|
||||
'global_status',
|
||||
'total_tests, tests_finished, test_success, tests_failed, tests_running, tests_skipped',
|
||||
defaults=(0, 0, 0, 0, 0, 0)
|
||||
)
|
||||
test_status = namedtuple('test_status', 'name, status, message', defaults=(None, None, None))
|
||||
return_code_dict = {
|
||||
2: "The test was not run",
|
||||
3: "The test is running",
|
||||
0: "The test is a success",
|
||||
1: "Test has failed",
|
||||
4: "Test found problems",
|
||||
"skipped": "The test was not run",
|
||||
"running": "The test is running",
|
||||
"success": "The test is a success",
|
||||
"failure": "Test has failed",
|
||||
"problems": "Test found problems",
|
||||
"idle": "Test is idle",
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,15 @@ class SpideyTest(test_template.TestTemplate):
|
|||
"""
|
||||
super().__init__(args, agnpath, test_data, queue)
|
||||
|
||||
def slowdown(self):
|
||||
"""
|
||||
This function is only used for testing.
|
||||
:return:
|
||||
"""
|
||||
print("Spidey test is running slowly...")
|
||||
import random, time
|
||||
time.sleep(random.randint(1, 5))
|
||||
|
||||
def run_test(self):
|
||||
"""
|
||||
Counts the number of lines in both index.js files. If it's more than one, it's almost certain your discord
|
||||
|
|
@ -25,26 +34,25 @@ class SpideyTest(test_template.TestTemplate):
|
|||
:return: Whether any of the index.js is more than one line
|
||||
:rtype: bool
|
||||
"""
|
||||
import random, time
|
||||
# Wait a random amount of time to make sure the files are loaded
|
||||
time.sleep(random.randint(1, 5))
|
||||
|
||||
self.slowdown() # This function is only used for testing
|
||||
paths = self.get_path()
|
||||
self.is_infected = False
|
||||
lines = 0
|
||||
with open(os.path.join(paths[0], "index.js")) as f:
|
||||
for line in f:
|
||||
lines += 1
|
||||
lines += 1 # TODO: you don't actually need to count the lines, you can just check if it's more than 1
|
||||
if lines > 1:
|
||||
self.is_infected = True
|
||||
|
||||
lines = 0
|
||||
with open(os.path.join(paths[1], "index.js")) as f:
|
||||
for line in f:
|
||||
lines += 1
|
||||
lines += 1 # TODO: you don't actually need to count the lines, you can just check if it's more than 1
|
||||
if lines > 1:
|
||||
self.is_infected = True
|
||||
|
||||
if self.is_infected:
|
||||
if self.is_infected: # TODO: set a status here, explaining and why the test failed, the scary part will be handled by the main program
|
||||
print("\n!!! WARNING !!!\n"
|
||||
"Unless you've installed a plugin you really trust, chances are your discord install "
|
||||
"is corrupted. We suggest uninstalling discord and deleting all its files before reinstalling.\n"
|
||||
|
|
@ -52,7 +60,7 @@ class SpideyTest(test_template.TestTemplate):
|
|||
"do also consider a clean windows reinstall.")
|
||||
print("Spidey test finished")
|
||||
|
||||
self.set_status(0)
|
||||
self.set_status("success")
|
||||
status = self.get_status()
|
||||
self.queue.append(status)
|
||||
return self.get_status_code()
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ class TestRunner:
|
|||
if self.args.launch:
|
||||
while True:
|
||||
if POST_RUN_ALLOWED:
|
||||
print("Running post test runner")
|
||||
print("Running post test runner...")
|
||||
return 0
|
||||
time.sleep(0.5)
|
||||
return 0
|
||||
|
|
@ -167,17 +167,18 @@ class TestRunner:
|
|||
nb_tests_skipped = 0
|
||||
for test in self.finished_tests:
|
||||
print(f"Test {test.name} finished with status {test.status}")
|
||||
if test.status == 0:
|
||||
if test.status == "success":
|
||||
nb_tests_success += 1
|
||||
elif test.status == 1:
|
||||
elif test.status == "failure":
|
||||
nb_tests_failure += 1
|
||||
elif test.status == 2:
|
||||
elif test.status == "skipped":
|
||||
nb_tests_skipped += 1
|
||||
|
||||
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_finished=nb_tests_ran,
|
||||
tests_failed=nb_tests_failure,
|
||||
tests_running=nb_test_running,
|
||||
|
|
@ -198,5 +199,6 @@ def run_check(args, agnpath):
|
|||
while tr.get_exit_code() == -1:
|
||||
print(tr.get_status())
|
||||
time.sleep(0.5)
|
||||
|
||||
print("The test sequence is now finished")
|
||||
print(tr.get_status())
|
||||
sys.exit(tr.get_exit_code())
|
||||
|
|
|
|||
|
|
@ -22,9 +22,18 @@ class TestTemplate:
|
|||
self.main_path = agnpath.main_path
|
||||
self.test_data = test_data
|
||||
self.is_infected = False
|
||||
self.status_code = 0
|
||||
self.status_code = "idle"
|
||||
self.status = "Test not yet initialized."
|
||||
self.queue = queue
|
||||
self.set_status("idle")
|
||||
|
||||
def run_test(self):
|
||||
"""
|
||||
The main runner function, must be implemented by the child class.
|
||||
During the execution of the test, the status code and status MUST be updated.
|
||||
"""
|
||||
self.set_status("running", "The test will begin shortly, please wait...")
|
||||
self.set_status("sucess", "The test was a success but kinda not a success.")
|
||||
|
||||
def name(self):
|
||||
"""
|
||||
|
|
@ -36,33 +45,39 @@ class TestTemplate:
|
|||
def get_status_code(self):
|
||||
"""
|
||||
:return: Status code at the time of call.
|
||||
:rtype: int
|
||||
:rtype: str
|
||||
"""
|
||||
return self.status_code
|
||||
|
||||
def get_status(self):
|
||||
"""
|
||||
:return: Status at the time of call.
|
||||
:rtype: str
|
||||
:rtype: internal_io.test_status
|
||||
"""
|
||||
return internal_io.test_status(self.name(), self.status_code, self.status)
|
||||
|
||||
@staticmethod
|
||||
def get_status_from_code(code):
|
||||
"""
|
||||
:param code: The status code to get the status from.
|
||||
:type code: str
|
||||
:return: Description of the status code
|
||||
:rtype: str
|
||||
"""
|
||||
return internal_io.return_code_dict[code]
|
||||
|
||||
def set_status(self, statuscode: int):
|
||||
def set_status(self, statuscode: str, message: str = None):
|
||||
"""
|
||||
Sets a new status code.
|
||||
:param statuscode: Status code to set
|
||||
:type statuscode: int
|
||||
:param message: Message to set
|
||||
:type statuscode: str
|
||||
:return: new status code
|
||||
:rtype: int
|
||||
:rtype: str
|
||||
"""
|
||||
self.status_code = statuscode
|
||||
self.status = self.get_status_from_code(statuscode)
|
||||
if message is not None:
|
||||
self.status = message
|
||||
else:
|
||||
self.status = self.get_status_from_code(statuscode)
|
||||
return self.status_code
|
||||
|
|
|
|||
Reference in New Issue