Ejemplo n.º 1
0
 def test_build_a_merged_file_project(self):
     project = a_project()\
         .with_merged_file("foo")\
         .build()
     self.assertEqual(
         LatexProject(TexFile(LatexProjectBuilder.MERGED_FILE, "foo")),
         project)
Ejemplo n.º 2
0
class LatexProjectTests(TestCase):
    def setUp(self):
        self.file = TexFile("main.tex", "blabla")
        self.tex = LatexProject(self.file)

    def test_files_is_exposed(self):
        self.assertEqual(self.file, self.tex.files["main.tex"])

    def test_equals_a_project_with_similar_files(self):
        self.assertEqual(LatexProject(TexFile("main.tex", "blabla")), self.tex)

    def test_differ_when_file_content_differ(self):
        self.assertNotEqual(
            LatexProject(TexFile("main.tex", "THIS IS DIFFERENT!")), self.tex)

    def test_differ_when_file_path_differ(self):
        self.assertNotEqual(
            LatexProject(TexFile("a/different/path.tex", "blabla")), self.tex)

    def test_difference_with_itself(self):
        self.tex.assert_is_equivalent_to(self.tex)

    def test_difference_with_a_project_with_an_missing_file(self):
        try:
            self.tex.assert_is_equivalent_to(LatexProject())
            self.fail("Exception expected")

        except AssertionError as error:
            self.assertEqual(LatexProject.MISSING_FILE.format(file="main.tex"),
                             str(error))

    def test_difference_with_a_project_with_an_extra_file(self):
        try:
            extra_file = TexFile("extra/file.tex", "Extra blabla")
            self.tex.assert_is_equivalent_to(
                LatexProject(self.file, extra_file))
            self.fail("Exception expected")

        except AssertionError as error:
            self.assertEqual(
                LatexProject.UNEXPECTED_FILE.format(file=extra_file.path),
                str(error))

    def test_difference_with_a_project_whose_file_content_differs(self):
        try:
            content = "something different"
            self.tex.assert_is_equivalent_to(
                LatexProject(TexFile("main.tex", content)))
            self.fail("Exception expected")

        except AssertionError as error:
            self.assertEqual(
                LatexProject.CONTENT_MISMATCH.format(file="main.tex",
                                                     actual=content,
                                                     expected="blabla"),
                str(error))
Ejemplo n.º 3
0
    def test_difference_with_a_project_with_an_missing_file(self):
        try:
            self.tex.assert_is_equivalent_to(LatexProject())
            self.fail("Exception expected")

        except AssertionError as error:
            self.assertEqual(LatexProject.MISSING_FILE.format(file="main.tex"),
                             str(error))
Ejemplo n.º 4
0
 def test_build_project_with_image(self):
     project = a_project()\
         .with_image("img/result.pdf")\
         .build()
     self.assertEqual(
         LatexProject(
             TexFile(
                 "img/result.pdf",
                 LatexProjectBuilder.IMAGE_CONTENT.format(
                     key="img_result.pdf"))), project)
Ejemplo n.º 5
0
class LatexProjectTests(TestCase):

    def setUp(self):
        self.file = TexFile("main.tex", "blabla")
        self.tex = LatexProject(self.file)

    def test_files_is_exposed(self):
        self.assertEquals(self.file, self.tex.files["main.tex"])

    def test_equals_a_project_with_similar_files(self):
        self.assertEqual(LatexProject(TexFile("main.tex", "blabla")),
                         self.tex)

    def test_differ_when_file_content_differ(self):
        self.assertNotEqual(LatexProject(TexFile("main.tex", "THIS IS DIFFERENT!")),
                         self.tex)

    def test_differ_when_file_path_differ(self):
        self.assertNotEqual(LatexProject(TexFile("a/different/path.tex", "blabla")),
                         self.tex)

    def test_difference_with_itself(self):
        self.tex.assert_is_equivalent_to(self.tex)

    def test_difference_with_a_project_with_an_missing_file(self):
        try:
            self.tex.assert_is_equivalent_to(LatexProject())
            self.fail("Exception expected")

        except AssertionError as error:
            self.assertEqual(LatexProject.MISSING_FILE.format(file="main.tex"),
                             str(error))

    def test_difference_with_a_project_with_an_extra_file(self):
        try:
            extra_file = TexFile("extra/file.tex", "Extra blabla")
            self.tex.assert_is_equivalent_to(LatexProject(self.file, extra_file))
            self.fail("Exception expected")

        except AssertionError as error:
            self.assertEqual(LatexProject.UNEXPECTED_FILE.format(file=extra_file.path),
                             str(error))

    def test_difference_with_a_project_whose_file_content_differs(self):
        try:
            content = "something different"
            self.tex.assert_is_equivalent_to(LatexProject(TexFile("main.tex", content)))
            self.fail("Exception expected")

        except AssertionError as error:
            self.assertEqual(LatexProject.CONTENT_MISMATCH.format(file="main.tex", expected=content, actual="blabla"),
                             str(error))
Ejemplo n.º 6
0
    def test_difference_with_a_project_with_an_extra_file(self):
        try:
            extra_file = TexFile("extra/file.tex", "Extra blabla")
            self.tex.assert_is_equivalent_to(
                LatexProject(self.file, extra_file))
            self.fail("Exception expected")

        except AssertionError as error:
            self.assertEqual(
                LatexProject.UNEXPECTED_FILE.format(file=extra_file.path),
                str(error))
Ejemplo n.º 7
0
    def test_difference_with_a_project_whose_file_content_differs(self):
        try:
            content = "something different"
            self.tex.assert_is_equivalent_to(
                LatexProject(TexFile("main.tex", content)))
            self.fail("Exception expected")

        except AssertionError as error:
            self.assertEqual(
                LatexProject.CONTENT_MISMATCH.format(file="main.tex",
                                                     actual=content,
                                                     expected="blabla"),
                str(error))
Ejemplo n.º 8
0
 def test_build_single_file_projects(self):
     project = a_project()\
         .with_file("main.tex", "foo")\
         .build()
     self.assertEqual(LatexProject(TexFile("main.tex", "foo")), project)
Ejemplo n.º 9
0
 def _verify_generated_files(self, test_case):
     location = self._file_system.open(Path.fromText("output"))
     actual = LatexProject.extract_from_directory(location)
     actual.assert_is_equivalent_to(test_case._expected)
Ejemplo n.º 10
0
 def setUp(self):
     self.file = TexFile("main.tex", "blabla")
     self.tex = LatexProject(self.file)
Ejemplo n.º 11
0
 def test_differ_when_file_content_differ(self):
     self.assertNotEqual(
         LatexProject(TexFile("main.tex", "THIS IS DIFFERENT!")), self.tex)
Ejemplo n.º 12
0
 def test_differ_when_file_path_differ(self):
     self.assertNotEqual(
         LatexProject(TexFile("a/different/path.tex", "blabla")), self.tex)
Ejemplo n.º 13
0
 def setUp(self):
     self.file = TexFile("main.tex", "blabla")
     self.tex = LatexProject(self.file)
Ejemplo n.º 14
0
 def test_equals_a_project_with_similar_files(self):
     self.assertEqual(LatexProject(TexFile("main.tex", "blabla")), self.tex)
Ejemplo n.º 15
0
 def test_setup_a_two_files_project(self):
     self._do_test_setup(
         LatexProject(TexFile("main.tex", "blabla"),
                      TexFile("result.tex", "Some results")))
Ejemplo n.º 16
0
 def test_setup_a_single_file_project(self):
     self._do_test_setup(LatexProject(TexFile("main.tex", "blabla")))
Ejemplo n.º 17
0
 def test_setup_a_project_with_subdirectories(self):
     self._do_test_setup(
         LatexProject(TexFile("main.tex", "blabla"),
                      TexFile("sections/introduction.tex", "introduction"),
                      TexFile("sections/conclusions.tex", "conclusions"),
                      TexFile("images/results.pdf", "PDF")))
Ejemplo n.º 18
0
 def _extract_latex_project_from(self, project):
     project_files = []
     for each_file in project:
         project_files.append(self._extract_tex_file(each_file))
     return LatexProject(*project_files)
Ejemplo n.º 19
0
    def test_build_empty_project(self):
        project = a_project().build()

        self.assertEqual(LatexProject(), project)
Ejemplo n.º 20
0
 def _expected(self):
     tex_files = []
     for (path, content) in self._files:
         tex_files.append(TexFile(path, content))
     return LatexProject(*tex_files)
Ejemplo n.º 21
0
 def _extract_project(self):
     root = self._file_system.open(Path.fromText(self._directory))
     return LatexProject.extract_from_directory(root)
Ejemplo n.º 22
0
 def _verify_generated_files(self, test_case):
     location = self._file_system.open(Path.fromText("output"))
     actual = LatexProject.extract_from_directory(location)
     test_case._expected.assert_is_equivalent_to(actual)
Ejemplo n.º 23
0
 def _extract_project(self):
     root = self._file_system.open(Path.fromText(self._directory))
     return LatexProject.extract_from_directory(root)