diff options
author | Chris Jerdonek <chris.jerdonek@gmail.com> | 2011-12-13 19:25:13 -0800 |
---|---|---|
committer | Chris Jerdonek <chris.jerdonek@gmail.com> | 2011-12-13 19:25:13 -0800 |
commit | b735548f64cbbd5a7f1444ff1584ccc639c955d3 (patch) | |
tree | 15d8e51011188683e8f702de8adc2636c5147c74 | |
parent | d7dde61179494bf821d0f5df80421b8661b87013 (diff) | |
download | pystache-b735548f64cbbd5a7f1444ff1584ccc639c955d3.tar.gz |
Added a working unit test of commands.main().
-rw-r--r-- | tests/test_commands.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/test_commands.py b/tests/test_commands.py new file mode 100644 index 0000000..f1817e7 --- /dev/null +++ b/tests/test_commands.py @@ -0,0 +1,45 @@ +# coding: utf-8 + +""" +Unit tests of commands.py. + +""" + +import sys +import unittest + +from pystache.commands import main + + +ORIGINAL_STDOUT = sys.stdout + + +class MockStdout(object): + + def __init__(self): + self.output = "" + + def write(self, str): + self.output += str + + +class CommandsTestCase(unittest.TestCase): + + def setUp(self): + sys.stdout = MockStdout() + + def callScript(self, template, context): + argv = ['pystache', template, context] + main(argv) + return sys.stdout.output + + def testMainSimple(self): + """ + Test a simple command-line case. + + """ + actual = self.callScript("Hi {{thing}}", '{"thing": "world"}') + self.assertEquals(actual, u"Hi world\n") + + def tearDown(self): + sys.stdout = ORIGINAL_STDOUT |