summaryrefslogtreecommitdiff
path: root/pystache/tests/test_commands.py
blob: fc11f3058ce4a60f61827cd58c7ffbb0161c4059 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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.assertEqual(actual, u"Hi world\n")

    def tearDown(self):
        sys.stdout = ORIGINAL_STDOUT