Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not crash test_all if parametrized is missing #1432

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 48 additions & 46 deletions test/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down