]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/py/tests/test_interpreter.py
unused var warning in Mac build
[wxWidgets.git] / wxPython / wx / py / tests / test_interpreter.py
1 #!/usr/bin/env python
2
3 __author__ = "Patrick K. O'Brien <pobrien@orbtech.com>"
4 __cvsid__ = "$Id$"
5 __revision__ = "$Revision$"[11:-2]
6
7 import unittest
8
9 # Import from this module's parent directory.
10 import os
11 import sys
12 sys.path.insert(0, os.pardir)
13 import interpreter
14 del sys.path[0]
15 del sys
16 del os
17
18
19 """
20 These unittest methods are preferred:
21 -------------------------------------
22 self.assert_(expr, msg=None)
23 self.assertEqual(first, second, msg=None)
24 self.assertRaises(excClass, callableObj, *args, **kwargs)
25 self.fail(msg=None)
26 self.failIf(expr, msg=None)
27 """
28
29
30 class ModuleTestCase(unittest.TestCase):
31
32 def test_module(self):
33 module = interpreter
34 self.assert_(module.__author__)
35 self.assert_(module.__cvsid__)
36 self.assert_(module.__revision__)
37 self.assert_(module.Interpreter)
38 self.assert_(module.Interpreter.push)
39 self.assert_(module.Interpreter.runsource)
40 self.assert_(module.Interpreter.getAutoCompleteList)
41 self.assert_(module.Interpreter.getCallTip)
42 self.assert_(module.InterpreterAlaCarte)
43
44
45 class InterpreterTestCase(unittest.TestCase):
46
47 def setUp(self):
48 self.output = ''
49 self.i = interpreter.Interpreter(stdout=self)
50
51 def write(self, text):
52 """Capture output from self.i.push()."""
53 self.output += text
54
55 def tearDown(self):
56 self.output = ''
57 self.i = None
58 del self.i
59
60 def test_more(self):
61 self.assertEqual(self.i.push('dir()'), 0)
62 self.assertEqual(self.i.push('for n in range(3):'), 1)
63
64 def test_push(self):
65 values = (
66 ('dir', '<built-in function dir>'),
67 ('dir()', "['__builtins__', '__doc__', '__name__']"),
68 ('2 + 2', '4'),
69 ('d = {}', ''),
70 ('d', '{}'),
71 ('del d', ''),
72 ('len([4,5,6])', '3'),
73 )
74 for input, output in values:
75 if output: output += '\n'
76 self.i.push(input)
77 self.assertEqual(self.output, output)
78 self.output = ''
79
80
81 if __name__ == '__main__':
82 unittest.main()