def test_add_function(provide_callables_from_fixtures_modules): config.INSTANCE.object_reuse_probability = 0.0 test_case = dtc.DefaultTestCase() generic_function = gao.GenericFunction( function=provide_callables_from_fixtures_modules["triangle"], inferred_signature=InferredSignature( signature=Signature(parameters=[ Parameter(name="x", kind=Parameter.POSITIONAL_OR_KEYWORD, annotation=int), Parameter(name="y", kind=Parameter.POSITIONAL_OR_KEYWORD, annotation=int), Parameter(name="z", kind=Parameter.POSITIONAL_OR_KEYWORD, annotation=int), ]), return_type=None, parameters={ "x": int, "y": int, "z": int }, ), ) cluster = MagicMock(TestCluster) cluster.select_concrete_type.side_effect = lambda x: x factory = tf.TestFactory(cluster) result = factory.add_function(test_case, generic_function, position=0) assert isinstance(result.variable_type, type(None)) assert test_case.size() <= 4
def _get_test_for_nested_branch_fixture(module) -> tcc.TestCaseChromosome: test_case = dtc.DefaultTestCase() int_stmt = prim_stmt.IntPrimitiveStatement(test_case, -50) function_call = param_stmt.FunctionStatement( test_case, gao.GenericFunction( module.nested_branches, InferredSignature(signature=MagicMock(), parameters={}, return_type=int), ), [int_stmt.ret_val], ) test_case.add_statement(int_stmt) test_case.add_statement(function_call) return tcc.TestCaseChromosome(test_case=test_case)
def _get_test_for_single_branch_else_branch_fixture( module) -> tcc.TestCaseChromosome: test_case = dtc.DefaultTestCase() int_stmt = prim_stmt.IntPrimitiveStatement(test_case, -5) function_call = param_stmt.FunctionStatement( test_case, gao.GenericFunction( module.first, InferredSignature( signature=inspect.signature(module.first), parameters={"a": int}, return_type=int, ), ), {"a": int_stmt.ret_val}, ) test_case.add_statement(int_stmt) test_case.add_statement(function_call) return tcc.TestCaseChromosome(test_case=test_case)
def _get_test_for_no_branches_fixture(module) -> tcc.TestCaseChromosome: test_case = dtc.DefaultTestCase() int_stmt = prim_stmt.IntPrimitiveStatement(test_case, 5) function_call = param_stmt.FunctionStatement( test_case, gao.GenericFunction( module.identity, InferredSignature( signature=inspect.signature(module.identity), parameters={"a": int}, return_type=int, ), ), {"a": int_stmt.ret_val}, ) constructor_call = param_stmt.ConstructorStatement( test_case, gao.GenericConstructor( module.DummyClass, InferredSignature( signature=inspect.signature(module.DummyClass.__init__), parameters={"x": int}, return_type=module.DummyClass, ), ), {"x": function_call.ret_val}, ) method_call = param_stmt.MethodStatement( test_case, gao.GenericMethod( module.DummyClass, module.DummyClass.get_x, InferredSignature(signature=MagicMock(), parameters={}, return_type=int), ), constructor_call.ret_val, ) test_case.add_statement(int_stmt) test_case.add_statement(function_call) test_case.add_statement(constructor_call) test_case.add_statement(method_call) return tcc.TestCaseChromosome(test_case=test_case)