diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-05-29 18:18:04 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-05-31 14:03:02 -0400 |
commit | fb7f0437323ba836c68947d38f3604c3336e3a9b (patch) | |
tree | 756512a2b68f1c7270f028b487228fd0e3f13778 /test/test_cmd.py | |
parent | db498f217e03d772e0c0c37a526226d48ed790e2 (diff) | |
download | external_python_mako-fb7f0437323ba836c68947d38f3604c3336e3a9b.tar.gz external_python_mako-fb7f0437323ba836c68947d38f3604c3336e3a9b.tar.bz2 external_python_mako-fb7f0437323ba836c68947d38f3604c3336e3a9b.zip |
Use tox / zimports
Change-Id: Ia047c7052a6d242c2cf1c7a83981f1e38ea4d928
Diffstat (limited to 'test/test_cmd.py')
-rw-r--r-- | test/test_cmd.py | 56 |
1 files changed, 38 insertions, 18 deletions
diff --git a/test/test_cmd.py b/test/test_cmd.py index a2adbf9..ac0db25 100644 --- a/test/test_cmd.py +++ b/test/test_cmd.py @@ -1,8 +1,15 @@ from __future__ import with_statement + from contextlib import contextmanager -from test import TemplateTest, eq_, raises, template_base, mock import os + from mako.cmd import cmdline +from test import eq_ +from test import mock +from test import raises +from test import template_base +from test import TemplateTest + class CmdTest(TemplateTest): @contextmanager @@ -12,27 +19,31 @@ class CmdTest(TemplateTest): 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}"))): + 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") def test_stdin_syntax_err(self): - with mock.patch("sys.stdin", mock.Mock( - read=mock.Mock(return_value="${x"))): + 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 ( + "SyntaxException: Expected" in stderr.write.mock_calls[0][1][0] + ) assert "Traceback" in stderr.write.mock_calls[0][1][0] - def test_stdin_rt_err(self): - with mock.patch("sys.stdin", mock.Mock( - read=mock.Mock(return_value="${q}"))): + 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", "-"]) @@ -42,16 +53,22 @@ class CmdTest(TemplateTest): def test_file_success(self): with self._capture_output_fixture() as stdout: - cmdline(["--var", "x=5", - os.path.join(template_base, "cmd_good.mako")]) + cmdline( + ["--var", "x=5", os.path.join(template_base, "cmd_good.mako")] + ) eq_(stdout.write.mock_calls[0][1][0], "hello world 5") 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")]) + 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] @@ -59,14 +76,17 @@ class CmdTest(TemplateTest): 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")]) + 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] - def test_file_notfound(self): with raises(SystemExit, "error: can't find fake.lalala"): cmdline(["--var", "x=5", "fake.lalala"]) - |