Exemplo n.º 1
0
    def test_template_error_context(self):
        source = (
            "\\documentclass{article}\n"
            "\n"
            "\n"
            "\n"
            "\n"
            "\\begin{document}\n"
            "\\unknown{command}\n"
            "\n"
            "\n"
            "\\end{document}\n"
        )

        with self.assertRaises(TexError) as cm:
            run_tex(source)

        message = cm.exception.message

        expected_context = (
            " 2 \n"
            " 3 \n"
            " 4 \n"
            " 5 \n"
            " 6 \\begin{document}\n"
            " 7 \\unknown{command}\n"
            " 8 \n"
            " 9 \n"
            "10 \\end{document}"
        )

        self.assertIn(expected_context, message)
Exemplo n.º 2
0
    def test_wrong_latex_interpreter(self):
        source = "\
        \\documentclass{article}\n\
        \\begin{document}\n\
        This is a test!\n\
        \\end{document}"

        with self.assertRaises(Exception):
            run_tex(source)  # should raise
Exemplo n.º 3
0
    def test_exception_unknown_command(self):
        source = "\
        \\documentclass{article}\n\
        \\begin{document}\n\
        \\unknown{command}\n\
        \\end{document}\n"

        with self.assertRaises(TexError) as cm:
            run_tex(source)

        self.assertRegex(cm.exception.log, r"^This is LuaTeX")
        self.assertRegex(cm.exception.message, r"^! Undefined control sequence")
        self.assertRegex(cm.exception.message, r"l\.3")
Exemplo n.º 4
0
    def test_pdflatex_exceptions(self):
        source = "\
        \\documentclass{article}\n\
        \\begin{document}\n\
        This is a test!\n"

        with self.assertRaises(TexError) as cm:
            run_tex(source)

        self.assertRegex(cm.exception.log, r"^This is pdfTeX")
        self.assertRegex(cm.exception.message, r"^! Emergency stop")
        self.assertRegex(
            cm.exception.message,
            r"(End of file on the terminal\!$)|(job aborted, no legal \\end found)",
        )  # First alternative applies
Exemplo n.º 5
0
    def test_template_debug(self):
        source = (
            "\\documentclass{article}\n"
            "\\begin{document}\n"
            "\\unknown{command}\n"
            "\\end{document}\n"
        )

        with self.assertRaises(TexError) as cm:
            run_tex(source)

        template_debug = cm.exception.template_debug

        self.assertEqual(template_debug["during"], "\\unknown{command}")
        self.assertEqual(template_debug["line"], 3)
Exemplo n.º 6
0
    def test_tex_error(self):
        source = "\
        \\documentclass{article}\n\
        \\begin{document}\n\
        This is a test!\n"

        with self.assertRaises(TexError):
            pdf = run_tex(source)
Exemplo n.º 7
0
    def test_latexmk_test(self):
        source = "\
        \\documentclass{article}\n\
        \\begin{document}\n\
        This is a test!\n\
        \\end{document}"

        pdf = run_tex(source)
        self.assertIsNotNone(pdf)
Exemplo n.º 8
0
    def test_different_latex_interpreter(self):
        '''The default interpreter is lualatex'''
        source = "\
        \\documentclass{article}\n\
        \\begin{document}\n\
        This is a test!\n\
        \\end{document}"

        pdf = run_tex(source)
        self.assertIsNotNone(pdf)
Exemplo n.º 9
0
    def test_exception_emergency_stop(self):
        source = "\
        \\documentclass{article}\n\
        \\begin{document}\n\
        This is a test!\n"

        with self.assertRaises(TexError) as cm:
            pdf = run_tex(source)

        self.assertEqual(source, cm.exception.source)
        self.assertRegex(cm.exception.log, r'^This is LuaTeX')
        self.assertRegex(cm.exception.message, r'^! Emergency stop')
        self.assertRegex(cm.exception.message,
                         r'(End of file on the terminal\!$)|(job aborted, no legal \\end found)')  # First alternative applies