Show More
@@ -1,62 +1,77 b'' | |||||
|
1 | # -*- coding: utf-8 | |||
1 | """Tests for prompt generation.""" |
|
2 | """Tests for prompt generation.""" | |
2 |
|
3 | |||
|
4 | import tempfile | |||
3 | import unittest |
|
5 | import unittest | |
4 |
|
6 | |||
|
7 | import os | |||
5 | import nose.tools as nt |
|
8 | import nose.tools as nt | |
6 |
|
9 | |||
7 | from IPython.testing import tools as tt, decorators as dec |
|
10 | from IPython.testing import tools as tt, decorators as dec | |
8 | from IPython.core.prompts import PromptManager |
|
11 | from IPython.core.prompts import PromptManager | |
9 | from IPython.testing.globalipapp import get_ipython |
|
12 | from IPython.testing.globalipapp import get_ipython | |
10 |
|
13 | |||
11 | ip = get_ipython() |
|
14 | ip = get_ipython() | |
12 |
|
15 | |||
13 |
|
16 | |||
14 | class PromptTests(unittest.TestCase): |
|
17 | class PromptTests(unittest.TestCase): | |
15 | def setUp(self): |
|
18 | def setUp(self): | |
16 | self.pm = PromptManager(shell=ip, config=ip.config) |
|
19 | self.pm = PromptManager(shell=ip, config=ip.config) | |
17 |
|
20 | |||
18 | def test_multiline_prompt(self): |
|
21 | def test_multiline_prompt(self): | |
19 | self.pm.in_template = "[In]\n>>>" |
|
22 | self.pm.in_template = "[In]\n>>>" | |
20 | self.pm.render('in') |
|
23 | self.pm.render('in') | |
21 | self.assertEqual(self.pm.width, 3) |
|
24 | self.assertEqual(self.pm.width, 3) | |
22 | self.assertEqual(self.pm.txtwidth, 3) |
|
25 | self.assertEqual(self.pm.txtwidth, 3) | |
23 |
|
26 | |||
24 | self.pm.in_template = '[In]\n' |
|
27 | self.pm.in_template = '[In]\n' | |
25 | self.pm.render('in') |
|
28 | self.pm.render('in') | |
26 | self.assertEqual(self.pm.width, 0) |
|
29 | self.assertEqual(self.pm.width, 0) | |
27 | self.assertEqual(self.pm.txtwidth, 0) |
|
30 | self.assertEqual(self.pm.txtwidth, 0) | |
28 |
|
31 | |||
29 | def test_translate_abbreviations(self): |
|
32 | def test_translate_abbreviations(self): | |
30 | def do_translate(template): |
|
33 | def do_translate(template): | |
31 | self.pm.in_template = template |
|
34 | self.pm.in_template = template | |
32 | return self.pm.templates['in'] |
|
35 | return self.pm.templates['in'] | |
33 |
|
36 | |||
34 | pairs = [(r'%n>', '{color.number}{count}{color.prompt}>'), |
|
37 | pairs = [(r'%n>', '{color.number}{count}{color.prompt}>'), | |
35 | (r'\T', '{time}'), |
|
38 | (r'\T', '{time}'), | |
36 | (r'\n', '\n') |
|
39 | (r'\n', '\n') | |
37 | ] |
|
40 | ] | |
38 |
|
41 | |||
39 | tt.check_pairs(do_translate, pairs) |
|
42 | tt.check_pairs(do_translate, pairs) | |
40 |
|
43 | |||
41 | def test_user_ns(self): |
|
44 | def test_user_ns(self): | |
42 | self.pm.color_scheme = 'NoColor' |
|
45 | self.pm.color_scheme = 'NoColor' | |
43 | ip.ex("foo='bar'") |
|
46 | ip.ex("foo='bar'") | |
44 | self.pm.in_template = "In [{foo}]" |
|
47 | self.pm.in_template = "In [{foo}]" | |
45 | prompt = self.pm.render('in') |
|
48 | prompt = self.pm.render('in') | |
46 | self.assertEquals(prompt, u'In [bar]') |
|
49 | self.assertEquals(prompt, u'In [bar]') | |
47 |
|
50 | |||
48 | def test_builtins(self): |
|
51 | def test_builtins(self): | |
49 | self.pm.color_scheme = 'NoColor' |
|
52 | self.pm.color_scheme = 'NoColor' | |
50 | self.pm.in_template = "In [{int}]" |
|
53 | self.pm.in_template = "In [{int}]" | |
51 | prompt = self.pm.render('in') |
|
54 | prompt = self.pm.render('in') | |
52 | self.assertEquals(prompt, u"In [%r]" % int) |
|
55 | self.assertEquals(prompt, u"In [%r]" % int) | |
53 |
|
56 | |||
54 | def test_undefined(self): |
|
57 | def test_undefined(self): | |
55 | self.pm.color_scheme = 'NoColor' |
|
58 | self.pm.color_scheme = 'NoColor' | |
56 | self.pm.in_template = "In [{foo_dne}]" |
|
59 | self.pm.in_template = "In [{foo_dne}]" | |
57 | prompt = self.pm.render('in') |
|
60 | prompt = self.pm.render('in') | |
58 | self.assertEquals(prompt, u"In [<ERROR: 'foo_dne' not found>]") |
|
61 | self.assertEquals(prompt, u"In [<ERROR: 'foo_dne' not found>]") | |
59 |
|
62 | |||
60 | def test_render(self): |
|
63 | def test_render(self): | |
61 | self.pm.in_template = r'\#>' |
|
64 | self.pm.in_template = r'\#>' | |
62 | self.assertEqual(self.pm.render('in',color=False), '%d>' % ip.execution_count) |
|
65 | self.assertEqual(self.pm.render('in',color=False), '%d>' % ip.execution_count) | |
|
66 | ||||
|
67 | def test_render_unicode(self): | |||
|
68 | td = tempfile.mkdtemp(u'ünicødé') | |||
|
69 | save = os.getcwdu() | |||
|
70 | os.chdir(td) | |||
|
71 | self.pm.in_template = r'\w [\#]' | |||
|
72 | try: | |||
|
73 | p = self.pm.render('in', color=False) | |||
|
74 | self.assertEquals(p, u"%s [%i]" % (os.getcwdu(), ip.execution_count)) | |||
|
75 | finally: | |||
|
76 | os.chdir(save) | |||
|
77 | os.rmdir(td) |
General Comments 0
You need to be logged in to leave comments.
Login now