def load_tests(loader, tests, pattern): file_system = OSFileSystem() repository = FileBasedTestRepository( file_system, Path.fromText("tests/acceptance/scenarios"), YamlCodec()) runner = EndToEndRunner(file_system) generate = Generator(repository, runner) suite = TestSuite() tests = loader.loadTestsFromTestCase(generate.test_class()) suite.addTests(tests) return suite
def setUp(self): self.file_system = InMemoryFileSystem() self.repository = FileBasedTestRepository( self.file_system, Path.fromText("tests"), YamlCodec())
def setUp(self): self._codec = YamlCodec()
class TestYamlCodec(TestCase): def setUp(self): self._codec = YamlCodec() @staticmethod def _create_file(content): file = MagicMock() file.content.return_value = content return file def test_loading_test_case_with_latex_code(self): yaml_file = self._create_file(YamlTest.with_latex_code()) test_case = self._read_test_case_from(yaml_file) expected = FlapTestCase( "test 1", a_project().with_main_file( ("\\documentclass{article}\n" "\\begin{document}\n" " This is a simple \\LaTeX document!\n" "\\end{document}")).build(), a_project().with_merged_file( "\\documentclass{article}\n" "\\begin{document}\n" " This is a simple \\LaTeX document!\n" "\\end{document}").build()) self.assertEqual(expected, test_case) def test_parsing_a_skipped_yaml_code(self): yaml_file = self._create_file(YamlTest.that_is_skipped("Test 1")) test_case = self._read_test_case_from(yaml_file) expected = FlapTestCase( "Test 1", a_project().with_main_file("blabla").build(), a_project().with_merged_file("blabla").build(), skipped=True) self.assertEqual(expected, test_case) def test_parsing_a_test_case_with_invocation(self): yaml_file = self._create_file( YamlTest.that_includes_invocation("Test 1")) test_case = self._read_test_case_from(yaml_file) expected = FlapTestCase( "Test 1", a_project().with_main_file("blabla").build(), a_project().with_merged_file("blabla").build(), Invocation(tex_file="foo.tex"), skipped=False) self.assertEqual(expected, test_case) def test_parsing_a_test_case_with_expected_outputs(self): yaml_file = self._create_file( YamlTest.that_includes_expected_outputs("Test 1")) test_case = self._read_test_case_from(yaml_file) expected = FlapTestCase( "Test 1", a_project().with_main_file("blabla").build(), a_project().with_merged_file("blabla").build(), None, False, [Fragment("main.tex", 1, 1, "\\input{result}")]) self.assertEqual(expected, test_case) def test_parsing_invalid_yaml_code(self): yaml_file = self._create_file("This is not a valid YAML content!") with self.assertRaises(InvalidYamlTestCase): self._read_test_case_from(yaml_file) def test_wrong_project_key(self): yaml_file = self._create_file(YamlTest.with_misspelled_project_key()) with self.assertRaises(InvalidYamlTestCase): self._read_test_case_from(yaml_file) def test_wrong_name_key(self): yaml_file = self._create_file(YamlTest.with_misspelled_name_key()) with self.assertRaises(InvalidYamlTestCase): self._read_test_case_from(yaml_file) def test_wrong_path_key(self): yaml_file = self._create_file(YamlTest.with_misspelled_path_key()) with self.assertRaises(InvalidYamlTestCase): self._read_test_case_from(yaml_file) def test_wrong_content_key(self): yaml_file = self._create_file(YamlTest.with_misspelled_content_key()) with self.assertRaises(InvalidYamlTestCase): self._read_test_case_from(yaml_file) def test_wrong_expected_key(self): yaml_file = self._create_file(YamlTest.with_misspelled_expected_key()) with self.assertRaises(InvalidYamlTestCase): self._read_test_case_from(yaml_file) def _read_test_case_from(self, file): return self._codec.extract_from(file)
class TestYamlCodec(TestCase): def setUp(self): self._codec = YamlCodec() def _create_file(self, content): file = MagicMock() file.content.return_value = content return file def test_loading_test_case_with_latex_code(self): yaml_file = self._create_file(YamlTest.with_latex_code()) test_case = self._read_test_case_from(yaml_file) expected = FlapTestCase( "test 1", a_project().with_main_file("\\documentclass{article}\n\\begin{document}\n This is a simple \\LaTeX document!\n\\end{document}").build(), a_project().with_merged_file("\\documentclass{article}\n\\begin{document}\n This is a simple \\LaTeX document!\n\\end{document}").build()) self.assertEqual(expected, test_case) def test_parsing_a_skipped_yaml_code(self): yaml_file = self._create_file(YamlTest.that_is_skipped("Test 1")) test_case = self._read_test_case_from(yaml_file) expected = FlapTestCase( "Test 1", a_project().with_main_file("blabla").build(), a_project().with_merged_file("blabla").build(), True) self.assertEqual(expected, test_case) def test_parsing_a_test_case_with_expected_outputs(self): yaml_file = self._create_file(YamlTest.that_includes_expected_outputs("Test 1")) test_case = self._read_test_case_from(yaml_file) expected = FlapTestCase( "Test 1", a_project().with_main_file("blabla").build(), a_project().with_merged_file("blabla").build(), False, [Fragment("main.tex", 1, 1, "\\input{result}")]) self.assertEqual(expected, test_case) def test_parsing_invalid_yaml_code(self): yaml_file = self._create_file("This is not a valid YAML content!") with self.assertRaises(InvalidYamlTestCase): self._read_test_case_from(yaml_file) def test_wrong_project_key(self): yaml_file = self._create_file(YamlTest.with_misspelled_project_key()) with self.assertRaises(InvalidYamlTestCase): self._read_test_case_from(yaml_file) def test_wrong_name_key(self): yaml_file = self._create_file(YamlTest.with_misspelled_name_key()) with self.assertRaises(InvalidYamlTestCase): self._read_test_case_from(yaml_file) def test_wrong_path_key(self): yaml_file = self._create_file(YamlTest.with_misspelled_path_key()) with self.assertRaises(InvalidYamlTestCase): self._read_test_case_from(yaml_file) def test_wrong_content_key(self): yaml_file = self._create_file(YamlTest.with_misspelled_content_key()) with self.assertRaises(InvalidYamlTestCase): self._read_test_case_from(yaml_file) def test_wrong_expected_key(self): yaml_file = self._create_file(YamlTest.with_misspelled_expected_key()) with self.assertRaises(InvalidYamlTestCase): self._read_test_case_from(yaml_file) def _read_test_case_from(self, file): return self._codec.extract_from(file)