def check_simple(self): @parametrize(x=100, z=300) def function(x=1, y=2, z=3): return x, y, z assert parametrized(function) assert parametrized(function) assert len(function) == 1 all_f = [f for f in function] assert all_f[0].__name__ == "function" assert all_f[0].kwargs == {"x": 100, "z": 300} assert all_f[0]() == (100, 2, 300)
def check_defaults_method(self): class C(object): @defaults(z=[1, 2]) @matrix(x=[1], y=[1, 2]) @parametrize(x=3, y=4) def function(self, x=1, y=2, z=-1): return x, y, z assert parametrized(C.function) injected_args_list = [m.injected_args for m in C.function.marks] assert len(injected_args_list) == 3 context_list = MarkedFunctionExpander(None, function=C.function).expand() assert len(context_list) == 6 expected_output = {(1, 1, 1), (1, 1, 2), (1, 2, 1), (1, 2, 2), (3, 4, 1), (3, 4, 2)} output = set() c = C() for ctx in context_list: f = ctx.function injected_args = ctx.injected_args assert f(c) == (injected_args['x'], injected_args['y'], injected_args['z']) output.add(ctx.function(C())) assert output == expected_output
def check_stacked_method(self): class C(object): @parametrize(x=100, y=200, z=300) @parametrize(x=100, z=300) @parametrize(y=200) @parametrize() def function(self, x=1, y=2, z=3): return x, y, z assert parametrized(C.function) assert len(C.function) == 4 all_f = [func for func in C.function] c = C() assert all_f[0].kwargs == {"x": 100, "y": 200, "z": 300} assert all_f[0](c) == (100, 200, 300) assert all_f[1].kwargs == {"x": 100, "z": 300} assert all_f[1](c) == (100, 2, 300) assert all_f[2].kwargs == {"y": 200} assert all_f[2](c) == (1, 200, 3) assert all_f[3].kwargs == {} assert all_f[3](c) == (1, 2, 3)
def check_defaults_method(self): class C(object): @defaults(z=[1, 2]) @matrix(x=[1], y=[1, 2]) @parametrize(x=3, y=4) def function(self, x=1, y=2, z=-1): return x, y, z assert parametrized(C.function) injected_args_list = [m.injected_args for m in C.function.marks] assert len(injected_args_list) == 3 context_list = MarkedFunctionExpander(None, function=C.function).expand() assert len(context_list) == 6 expected_output = { (1, 1, 1), (1, 1, 2), (1, 2, 1), (1, 2, 2), (3, 4, 1), (3, 4, 2) } output = set() c = C() for ctx in context_list: f = ctx.function injected_args = ctx.injected_args assert f(c) == (injected_args['x'], injected_args['y'], injected_args['z']) output.add(ctx.function(C())) assert output == expected_output
def check_defaults(self): @defaults(z=[1, 2]) @matrix(x=[1], y=[1, 2]) @parametrize(x=3, y=4) def function(x=1, y=2, z=-1): return x, y, z assert parametrized(function) injected_args_list = [m.injected_args for m in function.marks] assert len(injected_args_list) == 3 context_list = MarkedFunctionExpander(None, function=function).expand() assert len(context_list) == 6 expected_output = { (1, 1, 1), (1, 1, 2), (1, 2, 1), (1, 2, 2), (3, 4, 1), (3, 4, 2) } output = set() for ctx in context_list: output.add(ctx.function()) assert output == expected_output
def check_overlap_matrix(self): @defaults(y=[3, 4], z=[1, 2]) @matrix(x=[1, 2], y=[5, 6]) def function(x=20, y=30, z=40): return x, y, z assert parametrized(function) injected_args_list = [m.injected_args for m in function.marks] assert len(injected_args_list) == 2 context_list = MarkedFunctionExpander(None, function=function).expand() assert len(context_list) == 8 expected_output = { (1, 5, 1), (1, 5, 2), (2, 5, 1), (2, 5, 2), (1, 6, 1), (1, 6, 2), (2, 6, 1), (2, 6, 2) } output = set() for ctx in context_list: output.add(ctx.function()) assert output == expected_output
def expand_function(*, func, sess_ctx): """ Inject parameters into function and generate context list. """ assert parametrized(func) assert next(filter(lambda x: isinstance(x, IgniteVersionParametrize), func.marks), None) return MarkedFunctionExpander(session_context=sess_ctx, function=func).expand()
def expand_function(self, t_info): """Assume t_info.function is marked with @parametrize etc.""" assert parametrized(t_info.function) test_info_list = [] for f in t_info.function: test_info_list.append(TestInfo(module=t_info.module, cls=t_info.cls, function=f, injected_args=f.kwargs)) return test_info_list
def is_test_function(self, function): """A test function looks like a test and is callable (or expandable).""" if function is None: return False if not parametrized(function) and not callable(function): return False return re.match(self.test_function_pattern, function.__name__) is not None
def expand_function(self, t_info): """Assume t_info.function is marked with @parametrize etc.""" assert parametrized(t_info.function) test_info_list = [] for f in t_info.function: test_info_list.append( TestInfo(module=t_info.module, cls=t_info.cls, function=f, injected_args=f.kwargs)) return test_info_list
def check_simple_method(self): class C(object): @parametrize(x=100, z=300) def function(self, x=1, y=2, z=3): return x, y, z assert parametrized(C.function) assert len(C.function) == 1 all_f = [f for f in C.function] c = C() assert all_f[0].kwargs == {"x": 100, "z": 300} assert all_f[0](c) == (100, 2, 300)
def check_simple_method(self): class C(object): @parametrize(x=100, z=300) def function(self, x=1, y=2, z=3): return x, y, z assert parametrized(C.function) injected_args_list = [m.injected_args for m in C.function.marks] assert len(injected_args_list) == 1 assert injected_args_list[0] == {"x": 100, "z": 300} context_list = MarkedFunctionExpander(None, function=C.function).expand() all_f = [cxt.function for cxt in context_list] assert all_f[0](C()) == (100, 2, 300)
def check_simple(self): @matrix(x=[1, 2], y=[-1, -2]) def function(x=1, y=2, z=3): return x, y, z assert parametrized(function) injected_args_list = [m.injected_args for m in function.marks] assert len(injected_args_list) == 1 context_list = MarkedFunctionExpander(None, function=function).expand() assert len(context_list) == 4 for ctx in context_list: f = ctx.function injected_args = ctx.injected_args assert f() == (injected_args['x'], injected_args['y'], 3)
def expand_class(self, t_info): """Return a list of TestInfo objects, one object for each method in t_info.cls""" test_methods = [] for f_name in dir(t_info.cls): f = getattr(t_info.cls, f_name) if self.is_test_function(f): test_methods.append(f) test_info_list = [] for f in test_methods: t = TestInfo(module=t_info.module, cls=t_info.cls, function=f) if parametrized(f): test_info_list.extend(self.expand_function(t)) else: test_info_list.append(t) return test_info_list
def check_only_defaults(self): @defaults(x=[3], z=[1, 2]) def function(x=1, y=2, z=-1): return x, y, z assert parametrized(function) injected_args_list = [m.injected_args for m in function.marks] assert len(injected_args_list) == 1 context_list = MarkedFunctionExpander(None, function=function).expand() assert len(context_list) == 2 expected_output = {(3, 2, 1), (3, 2, 2)} output = set() for ctx in context_list: output.add(ctx.function()) assert output == expected_output
def check_stacked(self): @parametrize(x=100, y=200, z=300) @parametrize(x=100, z=300) @parametrize(y=200) @parametrize() def function(x=1, y=2, z=3): return x, y, z assert parametrized(function) injected_args_list = [m.injected_args for m in function.marks] assert len(injected_args_list) == 4 context_list = MarkedFunctionExpander(None, function=function).expand() all_f = [cxt.function for cxt in context_list] assert all_f[0]() == (100, 200, 300) assert all_f[1]() == (100, 2, 300) assert all_f[2]() == (1, 200, 3) assert all_f[3]() == (1, 2, 3)
def check_overlap_param(self): @defaults(y=[3, 4], z=[1, 2]) @parametrize(w=1, x=2, y=3) def function(w=10, x=20, y=30, z=40): return w, x, y, z assert parametrized(function) injected_args_list = [m.injected_args for m in function.marks] assert len(injected_args_list) == 2 context_list = MarkedFunctionExpander(None, function=function).expand() assert len(context_list) == 2 expected_output = {(1, 2, 3, 1), (1, 2, 3, 2)} output = set() for ctx in context_list: output.add(ctx.function()) assert output == expected_output
def check_stacked(self): @matrix(x=[1, 2], y=[0]) @matrix(x=[-1], z=[-10]) def function(x=1, y=2, z=3): return x, y, z assert parametrized(function) injected_args_list = [m.injected_args for m in function.marks] assert len(injected_args_list) == 2 context_list = MarkedFunctionExpander(None, function=function).expand() assert len(context_list) == 3 expected_output = {(1, 0, 3), (2, 0, 3), (-1, 2, -10)} output = set() for c in context_list: output.add(c.function()) assert output == expected_output
def check_overlap_matrix(self): @defaults(y=[3, 4], z=[1, 2]) @matrix(x=[1, 2], y=[5, 6]) def function(x=20, y=30, z=40): return x, y, z assert parametrized(function) injected_args_list = [m.injected_args for m in function.marks] assert len(injected_args_list) == 2 context_list = MarkedFunctionExpander(None, function=function).expand() assert len(context_list) == 8 expected_output = {(1, 5, 1), (1, 5, 2), (2, 5, 1), (2, 5, 2), (1, 6, 1), (1, 6, 2), (2, 6, 1), (2, 6, 2)} output = set() for ctx in context_list: output.add(ctx.function()) assert output == expected_output
def check_stacked(self): @matrix(x=[1, 2]) @matrix(y=[-1, -2]) def function(x=1, y=2, z=3): return x, y, z assert parametrized(function) assert len(function) == 4 all_f = [f for f in function] all_kwargs = [f.kwargs for f in all_f] assert all_f[0].__name__ == "function" assert sorted(all_kwargs) == sorted([ {'x': 1, 'y': -1}, {'x': 1, 'y': -2}, {'x': 2, 'y': -1}, {'x': 2, 'y': -2}]) for f in all_f: assert f() == (f.kwargs['x'], f.kwargs['y'], 3)
def check_defaults(self): @defaults(z=[1, 2]) @matrix(x=[1], y=[1, 2]) @parametrize(x=3, y=4) def function(x=1, y=2, z=-1): return x, y, z assert parametrized(function) injected_args_list = [m.injected_args for m in function.marks] assert len(injected_args_list) == 3 context_list = MarkedFunctionExpander(None, function=function).expand() assert len(context_list) == 6 expected_output = {(1, 1, 1), (1, 1, 2), (1, 2, 1), (1, 2, 2), (3, 4, 1), (3, 4, 2)} output = set() for ctx in context_list: output.add(ctx.function()) assert output == expected_output
def check_simple_method(self): class C(object): @matrix(x=[1, 2], y=[-1, -2]) def function(self, x=1, y=2, z=3): return x, y, z assert parametrized(C.function) assert len(C.function) == 4 all_f = [f for f in C.function] all_kwargs = [f.kwargs for f in all_f] assert all_f[0].__name__ == "function" assert sorted(all_kwargs) == sorted([ {'x': 1, 'y': -1}, {'x': 1, 'y': -2}, {'x': 2, 'y': -1}, {'x': 2, 'y': -2}]) for f in all_f: assert f(C()) == (f.kwargs['x'], f.kwargs['y'], 3)
def check_stacked(self): @parametrize(x=100, y=200, z=300) @parametrize(x=100, z=300) @parametrize(y=200) @parametrize() def function(x=1, y=2, z=3): return x, y, z assert parametrized(function) assert len(function) == 4 all_f = [f for f in function] assert all_f[0].kwargs == {"x": 100, "y": 200, "z": 300} assert all_f[0]() == (100, 200, 300) assert all_f[1].kwargs == {"x": 100, "z": 300} assert all_f[1]() == (100, 2, 300) assert all_f[2].kwargs == {"y": 200} assert all_f[2]() == (1, 200, 3) assert all_f[3].kwargs == {} assert all_f[3]() == (1, 2, 3)