##// END OF EJS Templates
Fix prompt test for Python 3.
Thomas Kluyver -
Show More
@@ -1,62 +1,62 b''
1 """Tests for prompt generation."""
1 """Tests for prompt generation."""
2
2
3 import unittest
3 import unittest
4
4
5 import nose.tools as nt
5 import nose.tools as nt
6
6
7 from IPython.testing import tools as tt, decorators as dec
7 from IPython.testing import tools as tt, decorators as dec
8 from IPython.core.prompts import PromptManager
8 from IPython.core.prompts import PromptManager
9 from IPython.testing.globalipapp import get_ipython
9 from IPython.testing.globalipapp import get_ipython
10
10
11 ip = get_ipython()
11 ip = get_ipython()
12
12
13
13
14 class PromptTests(unittest.TestCase):
14 class PromptTests(unittest.TestCase):
15 def setUp(self):
15 def setUp(self):
16 self.pm = PromptManager(shell=ip, config=ip.config)
16 self.pm = PromptManager(shell=ip, config=ip.config)
17
17
18 def test_multiline_prompt(self):
18 def test_multiline_prompt(self):
19 self.pm.in_template = "[In]\n>>>"
19 self.pm.in_template = "[In]\n>>>"
20 self.pm.render('in')
20 self.pm.render('in')
21 self.assertEqual(self.pm.width, 3)
21 self.assertEqual(self.pm.width, 3)
22 self.assertEqual(self.pm.txtwidth, 3)
22 self.assertEqual(self.pm.txtwidth, 3)
23
23
24 self.pm.in_template = '[In]\n'
24 self.pm.in_template = '[In]\n'
25 self.pm.render('in')
25 self.pm.render('in')
26 self.assertEqual(self.pm.width, 0)
26 self.assertEqual(self.pm.width, 0)
27 self.assertEqual(self.pm.txtwidth, 0)
27 self.assertEqual(self.pm.txtwidth, 0)
28
28
29 def test_translate_abbreviations(self):
29 def test_translate_abbreviations(self):
30 def do_translate(template):
30 def do_translate(template):
31 self.pm.in_template = template
31 self.pm.in_template = template
32 return self.pm.templates['in']
32 return self.pm.templates['in']
33
33
34 pairs = [(r'%n>', '{color.number}{count}{color.prompt}>'),
34 pairs = [(r'%n>', '{color.number}{count}{color.prompt}>'),
35 (r'\T', '{time}'),
35 (r'\T', '{time}'),
36 (r'\n', '\n')
36 (r'\n', '\n')
37 ]
37 ]
38
38
39 tt.check_pairs(do_translate, pairs)
39 tt.check_pairs(do_translate, pairs)
40
40
41 def test_user_ns(self):
41 def test_user_ns(self):
42 self.pm.color_scheme = 'NoColor'
42 self.pm.color_scheme = 'NoColor'
43 ip.ex("foo='bar'")
43 ip.ex("foo='bar'")
44 self.pm.in_template = "In [{foo}]"
44 self.pm.in_template = "In [{foo}]"
45 prompt = self.pm.render('in')
45 prompt = self.pm.render('in')
46 self.assertEquals(prompt, u'In [bar]')
46 self.assertEquals(prompt, u'In [bar]')
47
47
48 def test_builtins(self):
48 def test_builtins(self):
49 self.pm.color_scheme = 'NoColor'
49 self.pm.color_scheme = 'NoColor'
50 self.pm.in_template = "In [{int}]"
50 self.pm.in_template = "In [{int}]"
51 prompt = self.pm.render('in')
51 prompt = self.pm.render('in')
52 self.assertEquals(prompt, u"In [<type 'int'>]")
52 self.assertEquals(prompt, u"In [%r]" % int)
53
53
54 def test_undefined(self):
54 def test_undefined(self):
55 self.pm.color_scheme = 'NoColor'
55 self.pm.color_scheme = 'NoColor'
56 self.pm.in_template = "In [{foo_dne}]"
56 self.pm.in_template = "In [{foo_dne}]"
57 prompt = self.pm.render('in')
57 prompt = self.pm.render('in')
58 self.assertEquals(prompt, u"In [<ERROR: 'foo_dne' not found>]")
58 self.assertEquals(prompt, u"In [<ERROR: 'foo_dne' not found>]")
59
59
60 def test_render(self):
60 def test_render(self):
61 self.pm.in_template = r'\#>'
61 self.pm.in_template = r'\#>'
62 self.assertEqual(self.pm.render('in',color=False), '%d>' % ip.execution_count)
62 self.assertEqual(self.pm.render('in',color=False), '%d>' % ip.execution_count)
General Comments 0
You need to be logged in to leave comments. Login now