From 7c7a89943e25c0d8cce95857fb1e92dc35c9ecf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20=E2=80=9CCLOVIS=E2=80=9D=20Canet?= Date: Thu, 16 Jun 2022 08:56:58 +0200 Subject: [PATCH] Do not crash test_all if parametrized is missing --- test/test_all.py | 94 ++++++++++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 46 deletions(-) diff --git a/test/test_all.py b/test/test_all.py index 2d078bf12..ab2b4a766 100755 --- a/test/test_all.py +++ b/test/test_all.py @@ -13,8 +13,6 @@ from builtins import map from builtins import range -from parameterized import parameterized - from utils import cosmetics, multithread from utils.test import Test from utils.testset import TestSet @@ -852,50 +850,54 @@ class ExampleJitterNoPython(ExampleJitter): # region Unittest compatibility - -class TestSequence(unittest.TestCase): - # Compatibility layer for Python's unittest module - # Instead of calling the '__main__' defined below, we parameterize a single test with all the tests selected in - # testset, and run them as we would have. - - tests = testset.tests - tests_without_shellcodes = (t for t in tests if "shellcode.py" not in t.command_line[0]) - - @staticmethod - def run_process(t): - """ - @type t: Test - """ - print("Base dir:", t.base_dir) - print("Command: ", t.command_line) - print("Depends: ", [t.command_line for t in t.depends]) - print("Tags: ", t.tags) - print("Products:", t.products) - executable = t.executable if t.executable else sys.executable - print("Exec: ", executable, "(explicit)" if t.executable else "(default)") - - for t in t.depends: - assert "shellcode.py" in t.command_line[0], "At the moment, only dependencies on 'shellcode.py' are handled" - - subprocess.check_call( - [executable] + t.command_line, - cwd=testset.base_dir + t.base_dir, - ) - - print("Done") - - @classmethod - def setUpClass(cls): - for t in testset.tests: - if "shellcode.py" in t.command_line[0]: - print("\n*** Shellcode generation ***") - cls.run_process(t) - - @parameterized.expand(("_".join(test.command_line), test) for test in tests_without_shellcodes) - def test(self, name, t): - print("***", name, "***") - TestSequence.run_process(t) - +try: + from parameterized import parameterized + + class TestSequence(unittest.TestCase): + # Compatibility layer for Python's unittest module + # Instead of calling the '__main__' defined below, we parameterize a single test with all the tests selected in + # testset, and run them as we would have. + + tests = testset.tests + tests_without_shellcodes = (t for t in tests if "shellcode.py" not in t.command_line[0]) + + @staticmethod + def run_process(t): + """ + @type t: Test + """ + print("Base dir:", t.base_dir) + print("Command: ", t.command_line) + print("Depends: ", [t.command_line for t in t.depends]) + print("Tags: ", t.tags) + print("Products:", t.products) + executable = t.executable if t.executable else sys.executable + print("Exec: ", executable, "(explicit)" if t.executable else "(default)") + + for t in t.depends: + assert "shellcode.py" in t.command_line[0], "At the moment, only dependencies on 'shellcode.py' are handled" + + subprocess.check_call( + [executable] + t.command_line, + cwd=testset.base_dir + t.base_dir, + ) + + print("Done") + + @classmethod + def setUpClass(cls): + for t in testset.tests: + if "shellcode.py" in t.command_line[0]: + print("\n*** Shellcode generation ***") + cls.run_process(t) + + @parameterized.expand(("_".join(test.command_line), test) for test in tests_without_shellcodes) + def test(self, name, t): + print("***", name, "***") + TestSequence.run_process(t) + +except ImportError as e: + print("unittest/pytest support is disabled:", e) # endregion