Add support for unittest parameterized tests to be discovered
This commit is contained in:
parent
a0a477698d
commit
2f157ecff6
2 changed files with 41 additions and 4 deletions
|
|
@ -0,0 +1,17 @@
|
|||
import unittest
|
||||
from parameterized import parameterized
|
||||
|
||||
from code_to_optimize.bubble_sort import sorter
|
||||
|
||||
|
||||
class TestPigLatin(unittest.TestCase):
|
||||
@parameterized.expand(
|
||||
[
|
||||
([5, 4, 3, 2, 1, 0], [0, 1, 2, 3, 4, 5]),
|
||||
([5.0, 4.0, 3.0, 2.0, 1.0, 0.0], [0.0, 1.0, 2.0, 3.0, 4.0, 5.0]),
|
||||
(list(reversed(range(50))), list(range(50))),
|
||||
]
|
||||
)
|
||||
def test_sort(self, input, expected_output):
|
||||
output = sorter(input)
|
||||
self.assertEqual(output, expected_output)
|
||||
|
|
@ -146,12 +146,28 @@ def process_test_files(
|
|||
if name.name in test_suites and name.type == "class":
|
||||
for def_name in all_defs:
|
||||
if (
|
||||
def_name.name in functions_to_search
|
||||
and def_name.type == "function"
|
||||
def_name.type == "function"
|
||||
and def_name.full_name is not None
|
||||
and f".{name.name}." in def_name.full_name
|
||||
):
|
||||
test_functions.add(TestFunction(def_name.name, name.name, None))
|
||||
for function in functions_to_search:
|
||||
target_function = function.split("_")
|
||||
def_function = def_name.name.split("_")
|
||||
|
||||
if (
|
||||
len(target_function) == len(def_function) + 1
|
||||
and target_function[:-1] == def_function
|
||||
and target_function[-1].isdigit()
|
||||
):
|
||||
test_functions.add(
|
||||
TestFunction(def_name.name, name.name, target_function[-1])
|
||||
)
|
||||
elif (
|
||||
len(target_function) == len(def_function)
|
||||
and function == def_name.name
|
||||
):
|
||||
test_functions.add(TestFunction(def_name.name, name.name, None))
|
||||
|
||||
test_functions_list = list(test_functions)
|
||||
test_functions_raw = [elem.function_name for elem in test_functions_list]
|
||||
|
||||
|
|
@ -185,7 +201,11 @@ def process_test_files(
|
|||
and definition[0].module_name != name.module_name
|
||||
):
|
||||
if scope_parameters is not None:
|
||||
scope_test_function += "[" + scope_parameters + "]"
|
||||
if test_framework == "pytest":
|
||||
scope_test_function += "[" + scope_parameters + "]"
|
||||
if test_framework == "unittest":
|
||||
scope_test_function += "_" + scope_parameters
|
||||
|
||||
function_to_test_map[definition[0].full_name].append(
|
||||
TestsInFile(test_file, None, scope_test_function, scope_test_suite)
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue