def test_parameter_mapping_roundtrip(testcase_seed, tmp_path): testcase_seed = ( """# Automatically generated by Pynguin. import tests.fixtures.grammar.parameters as module0 def test_case_0(): """ + testcase_seed ) test_cluster = TestClusterGenerator( "tests.fixtures.grammar.parameters" ).generate_cluster() transformer = _TestTransformer(test_cluster) transformer.visit(ast.parse(testcase_seed)) export_path = tmp_path / "export.py" ExportProvider.get_exporter().export_sequences(export_path, transformer.testcases) with open(export_path) as f: content = f.read() assert content == testcase_seed
def _export_test_cases( test_cases: List[tc.TestCase], suffix: str = "", wrap_code: bool = False ) -> str: """Export the given test cases. :param test_cases: A list of test cases to export :param suffix: Suffix that can be added to the file name to distinguish between different results e.g., failing and succeeding test cases. :param wrap_code: Whether or not the generated code shall be wrapped """ exporter = ExportProvider.get_exporter(wrap_code=wrap_code) target_file = os.path.join( config.INSTANCE.output_path, "test_" + config.INSTANCE.module_name.replace(".", "_") + suffix + ".py", ) exporter.export_sequences(target_file, test_cases) return target_file
def test_unknown_strategy(): config.INSTANCE.export_strategy = MagicMock(config.ExportStrategy) with pytest.raises(Exception): ExportProvider.get_exporter()
def test_get_exporter(conf, instance): config.INSTANCE.export_strategy = conf exporter = ExportProvider.get_exporter() assert isinstance(exporter, instance)