Show More
@@ -1,34 +1,78 b'' | |||
|
1 | # coding: utf-8 | |
|
1 | 2 | """Test suite for our color utilities. |
|
2 | 3 | |
|
3 | 4 | Authors |
|
4 | 5 | ------- |
|
5 | 6 | |
|
6 | 7 | * Min RK |
|
7 | 8 | """ |
|
8 | 9 | #----------------------------------------------------------------------------- |
|
9 | 10 | # Copyright (C) 2011 The IPython Development Team |
|
10 | 11 | # |
|
11 | 12 | # Distributed under the terms of the BSD License. The full license is in |
|
12 | 13 | # the file COPYING.txt, distributed as part of this software. |
|
13 | 14 | #----------------------------------------------------------------------------- |
|
14 | 15 | |
|
15 | 16 | #----------------------------------------------------------------------------- |
|
16 | 17 | # Imports |
|
17 | 18 | #----------------------------------------------------------------------------- |
|
18 | 19 | |
|
19 | 20 | # third party |
|
20 | 21 | import nose.tools as nt |
|
21 | 22 | |
|
22 | 23 | # our own |
|
23 | 24 | from IPython.utils.PyColorize import Parser |
|
25 | import io | |
|
24 | 26 | |
|
25 | 27 | #----------------------------------------------------------------------------- |
|
26 | 28 | # Test functions |
|
27 | 29 | #----------------------------------------------------------------------------- |
|
28 | 30 | |
|
29 | def test_unicode_colorize(): | |
|
30 | p = Parser() | |
|
31 | f1 = p.format('1/0', 'str') | |
|
32 | f2 = p.format(u'1/0', 'str') | |
|
33 | nt.assert_equal(f1, f2) | |
|
31 | sample = u""" | |
|
32 | def function(arg, *args, kwarg=True, **kwargs): | |
|
33 | ''' | |
|
34 | this is docs | |
|
35 | ''' | |
|
36 | pass is True | |
|
37 | False == None | |
|
34 | 38 | |
|
39 | with io.open(ru'unicode'): | |
|
40 | raise ValueError("\n escape \r sequence") | |
|
41 | ||
|
42 | print("wěird ünicoðe") | |
|
43 | ||
|
44 | class Bar(Super): | |
|
45 | ||
|
46 | def __init__(self): | |
|
47 | super(Bar, self).__init__(1**2, 3^4, 5 or 6) | |
|
48 | """ | |
|
49 | ||
|
50 | def test_loop_colors(): | |
|
51 | ||
|
52 | for scheme in ('Linux', 'NoColor','LightBG'): | |
|
53 | ||
|
54 | def test_unicode_colorize(): | |
|
55 | p = Parser() | |
|
56 | f1 = p.format('1/0', 'str', scheme=scheme) | |
|
57 | f2 = p.format(u'1/0', 'str', scheme=scheme) | |
|
58 | nt.assert_equal(f1, f2) | |
|
59 | ||
|
60 | def test_parse_sample(): | |
|
61 | """and test writing to a buffer""" | |
|
62 | buf = io.StringIO() | |
|
63 | p = Parser() | |
|
64 | p.format(sample, buf, scheme=scheme) | |
|
65 | buf.seek(0) | |
|
66 | f1 = buf.read() | |
|
67 | ||
|
68 | nt.assert_not_in('ERROR', f1) | |
|
69 | ||
|
70 | def test_parse_error(): | |
|
71 | p = Parser() | |
|
72 | f1 = p.format(')', 'str', scheme=scheme) | |
|
73 | if scheme != 'NoColor': | |
|
74 | nt.assert_in('ERROR', f1) | |
|
75 | ||
|
76 | yield test_unicode_colorize | |
|
77 | yield test_parse_sample | |
|
78 | yield test_parse_error |
General Comments 0
You need to be logged in to leave comments.
Login now