示例#1
0
    def test_file_success(self):
        with self._capture_output_fixture() as stdout:
            cmdline(
                ["--var", "x=5", os.path.join(template_base, "cmd_good.mako")]
            )

        eq_(stdout.write.mock_calls[0][1][0], "hello world 5")
示例#2
0
    def test_double_brace_stdin_success(self):
        with self._capture_output_fixture() as stdout:
            with mock.patch("sys.stdin", mock.Mock(
                            read=mock.Mock(return_value="hello world {{x}}"))):
                cmdline(["--double-brace", "--var", "x=5", "-"])

        eq_(stdout.write.mock_calls[0][1][0], "hello world 5")
示例#3
0
    def test_file_rt_err(self):
        with self._capture_output_fixture("stderr") as stderr:
            with raises(SystemExit):
                cmdline(["--var", "x=5",
                            os.path.join(template_base, "cmd_runtime.mako")])

        assert "NameError: Undefined" in stderr.write.mock_calls[0][1][0]
        assert "Traceback" in stderr.write.mock_calls[0][1][0]
示例#4
0
    def test_file_syntax_err(self):
        with self._capture_output_fixture("stderr") as stderr:
            with raises(SystemExit):
                cmdline(["--var", "x=5",
                            os.path.join(template_base, "cmd_syntax.mako")])

        assert "SyntaxException: Expected" in stderr.write.mock_calls[0][1][0]
        assert "Traceback" in stderr.write.mock_calls[0][1][0]
示例#5
0
    def test_stdin_success(self):
        with self._capture_output_fixture() as stdout:
            with mock.patch(
                "sys.stdin",
                mock.Mock(read=mock.Mock(return_value="hello world ${x}")),
            ):
                cmdline(["--var", "x=5", "-"])

        eq_(stdout.write.mock_calls[0][1][0], "hello world 5")
示例#6
0
    def test_stdin_rt_err(self):
        with mock.patch("sys.stdin",
                        mock.Mock(read=mock.Mock(return_value="${q}"))):
            with self._capture_output_fixture("stderr") as stderr:
                with raises(SystemExit):
                    cmdline(["--var", "x=5", "-"])

            assert "NameError: Undefined" in stderr.write.mock_calls[0][1][0]
            assert "Traceback" in stderr.write.mock_calls[0][1][0]
示例#7
0
    def test_stdin_rt_err(self):
        with mock.patch("sys.stdin", mock.Mock(
                            read=mock.Mock(return_value="${q}"))):
            with self._capture_output_fixture("stderr") as stderr:
                with raises(SystemExit):
                    cmdline(["--var", "x=5", "-"])

            assert "NameError: Undefined" in stderr.write.mock_calls[0][1][0]
            assert "Traceback" in stderr.write.mock_calls[0][1][0]
示例#8
0
    def test_file_rt_err(self):
        with self._capture_output_fixture("stderr") as stderr:
            with raises(SystemExit):
                cmdline([
                    "--var", "x=5",
                    os.path.join(template_base, "cmd_runtime.mako")
                ])

        assert "NameError: Undefined" in stderr.write.mock_calls[0][1][0]
        assert "Traceback" in stderr.write.mock_calls[0][1][0]
示例#9
0
    def test_file_syntax_err(self):
        with self._capture_output_fixture("stderr") as stderr:
            with raises(SystemExit):
                cmdline([
                    "--var", "x=5",
                    os.path.join(template_base, "cmd_syntax.mako")
                ])

        assert "SyntaxException: Expected" in stderr.write.mock_calls[0][1][0]
        assert "Traceback" in stderr.write.mock_calls[0][1][0]
示例#10
0
    def test_stdin_syntax_err(self):
        with mock.patch("sys.stdin",
                        mock.Mock(read=mock.Mock(return_value="${x"))):
            with self._capture_output_fixture("stderr") as stderr:
                with raises(SystemExit):
                    cmdline(["--var", "x=5", "-"])

            assert "SyntaxException: Expected" in \
                        stderr.write.mock_calls[0][1][0]
            assert "Traceback" in stderr.write.mock_calls[0][1][0]
示例#11
0
    def test_stdin_syntax_err(self):
        with mock.patch("sys.stdin", mock.Mock(
                            read=mock.Mock(return_value="${x"))):
            with self._capture_output_fixture("stderr") as stderr:
                with raises(SystemExit):
                    cmdline(["--var", "x=5", "-"])

            assert "SyntaxException: Expected" in \
                        stderr.write.mock_calls[0][1][0]
            assert "Traceback" in stderr.write.mock_calls[0][1][0]
示例#12
0
 def test_file_notfound(self):
     with raises(SystemExit, "error: can't find fake.lalala"):
         cmdline(["--var", "x=5", "fake.lalala"])
# -*- coding: utf-8 -*-
import re
import sys

from mako.cmd import cmdline

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(cmdline())
示例#14
0
 def test_file_notfound(self):
     with raises(SystemExit, "error: can't find fake.lalala"):
         cmdline(["--var", "x=5", "fake.lalala"])
示例#15
0
    def test_file_success(self):
        with self._capture_output_fixture() as stdout:
            cmdline(["--var", "x=5",
                            os.path.join(template_base, "cmd_good.mako")])

        eq_(stdout.write.mock_calls[0][1][0], "hello world 5")