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