##// END OF EJS Templates
Fix tests that depended on dictionary order in IPython.core
Thomas Kluyver -
Show More
@@ -1,135 +1,135 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """
2 """
3 Color schemes for exception handling code in IPython.
3 Color schemes for exception handling code in IPython.
4 """
4 """
5
5
6 #*****************************************************************************
6 #*****************************************************************************
7 # Copyright (C) 2005-2006 Fernando Perez <fperez@colorado.edu>
7 # Copyright (C) 2005-2006 Fernando Perez <fperez@colorado.edu>
8 #
8 #
9 # Distributed under the terms of the BSD License. The full license is in
9 # Distributed under the terms of the BSD License. The full license is in
10 # the file COPYING, distributed as part of this software.
10 # the file COPYING, distributed as part of this software.
11 #*****************************************************************************
11 #*****************************************************************************
12
12
13 from IPython.utils.coloransi import ColorSchemeTable, TermColors, ColorScheme
13 from IPython.utils.coloransi import ColorSchemeTable, TermColors, ColorScheme
14
14
15 def exception_colors():
15 def exception_colors():
16 """Return a color table with fields for exception reporting.
16 """Return a color table with fields for exception reporting.
17
17
18 The table is an instance of ColorSchemeTable with schemes added for
18 The table is an instance of ColorSchemeTable with schemes added for
19 'Linux', 'LightBG' and 'NoColor' and fields for exception handling filled
19 'Linux', 'LightBG' and 'NoColor' and fields for exception handling filled
20 in.
20 in.
21
21
22 Examples:
22 Examples:
23
23
24 >>> ec = exception_colors()
24 >>> ec = exception_colors()
25 >>> ec.active_scheme_name
25 >>> ec.active_scheme_name
26 ''
26 ''
27 >>> print ec.active_colors
27 >>> print ec.active_colors
28 None
28 None
29
29
30 Now we activate a color scheme:
30 Now we activate a color scheme:
31 >>> ec.set_active_scheme('NoColor')
31 >>> ec.set_active_scheme('NoColor')
32 >>> ec.active_scheme_name
32 >>> ec.active_scheme_name
33 'NoColor'
33 'NoColor'
34 >>> ec.active_colors.keys()
34 >>> sorted(ec.active_colors.keys())
35 ['em', 'filenameEm', 'excName', 'valEm', 'nameEm', 'line', 'topline',
35 ['Normal', 'caret', 'em', 'excName', 'filename', 'filenameEm', 'line',
36 'name', 'caret', 'val', 'vName', 'Normal', 'filename', 'linenoEm',
36 'lineno', 'linenoEm', 'name', 'nameEm', 'normalEm', 'topline', 'vName',
37 'lineno', 'normalEm']
37 'val', 'valEm']
38 """
38 """
39
39
40 ex_colors = ColorSchemeTable()
40 ex_colors = ColorSchemeTable()
41
41
42 # Populate it with color schemes
42 # Populate it with color schemes
43 C = TermColors # shorthand and local lookup
43 C = TermColors # shorthand and local lookup
44 ex_colors.add_scheme(ColorScheme(
44 ex_colors.add_scheme(ColorScheme(
45 'NoColor',
45 'NoColor',
46 # The color to be used for the top line
46 # The color to be used for the top line
47 topline = C.NoColor,
47 topline = C.NoColor,
48
48
49 # The colors to be used in the traceback
49 # The colors to be used in the traceback
50 filename = C.NoColor,
50 filename = C.NoColor,
51 lineno = C.NoColor,
51 lineno = C.NoColor,
52 name = C.NoColor,
52 name = C.NoColor,
53 vName = C.NoColor,
53 vName = C.NoColor,
54 val = C.NoColor,
54 val = C.NoColor,
55 em = C.NoColor,
55 em = C.NoColor,
56
56
57 # Emphasized colors for the last frame of the traceback
57 # Emphasized colors for the last frame of the traceback
58 normalEm = C.NoColor,
58 normalEm = C.NoColor,
59 filenameEm = C.NoColor,
59 filenameEm = C.NoColor,
60 linenoEm = C.NoColor,
60 linenoEm = C.NoColor,
61 nameEm = C.NoColor,
61 nameEm = C.NoColor,
62 valEm = C.NoColor,
62 valEm = C.NoColor,
63
63
64 # Colors for printing the exception
64 # Colors for printing the exception
65 excName = C.NoColor,
65 excName = C.NoColor,
66 line = C.NoColor,
66 line = C.NoColor,
67 caret = C.NoColor,
67 caret = C.NoColor,
68 Normal = C.NoColor
68 Normal = C.NoColor
69 ))
69 ))
70
70
71 # make some schemes as instances so we can copy them for modification easily
71 # make some schemes as instances so we can copy them for modification easily
72 ex_colors.add_scheme(ColorScheme(
72 ex_colors.add_scheme(ColorScheme(
73 'Linux',
73 'Linux',
74 # The color to be used for the top line
74 # The color to be used for the top line
75 topline = C.LightRed,
75 topline = C.LightRed,
76
76
77 # The colors to be used in the traceback
77 # The colors to be used in the traceback
78 filename = C.Green,
78 filename = C.Green,
79 lineno = C.Green,
79 lineno = C.Green,
80 name = C.Purple,
80 name = C.Purple,
81 vName = C.Cyan,
81 vName = C.Cyan,
82 val = C.Green,
82 val = C.Green,
83 em = C.LightCyan,
83 em = C.LightCyan,
84
84
85 # Emphasized colors for the last frame of the traceback
85 # Emphasized colors for the last frame of the traceback
86 normalEm = C.LightCyan,
86 normalEm = C.LightCyan,
87 filenameEm = C.LightGreen,
87 filenameEm = C.LightGreen,
88 linenoEm = C.LightGreen,
88 linenoEm = C.LightGreen,
89 nameEm = C.LightPurple,
89 nameEm = C.LightPurple,
90 valEm = C.LightBlue,
90 valEm = C.LightBlue,
91
91
92 # Colors for printing the exception
92 # Colors for printing the exception
93 excName = C.LightRed,
93 excName = C.LightRed,
94 line = C.Yellow,
94 line = C.Yellow,
95 caret = C.White,
95 caret = C.White,
96 Normal = C.Normal
96 Normal = C.Normal
97 ))
97 ))
98
98
99 # For light backgrounds, swap dark/light colors
99 # For light backgrounds, swap dark/light colors
100 ex_colors.add_scheme(ColorScheme(
100 ex_colors.add_scheme(ColorScheme(
101 'LightBG',
101 'LightBG',
102 # The color to be used for the top line
102 # The color to be used for the top line
103 topline = C.Red,
103 topline = C.Red,
104
104
105 # The colors to be used in the traceback
105 # The colors to be used in the traceback
106 filename = C.LightGreen,
106 filename = C.LightGreen,
107 lineno = C.LightGreen,
107 lineno = C.LightGreen,
108 name = C.LightPurple,
108 name = C.LightPurple,
109 vName = C.Cyan,
109 vName = C.Cyan,
110 val = C.LightGreen,
110 val = C.LightGreen,
111 em = C.Cyan,
111 em = C.Cyan,
112
112
113 # Emphasized colors for the last frame of the traceback
113 # Emphasized colors for the last frame of the traceback
114 normalEm = C.Cyan,
114 normalEm = C.Cyan,
115 filenameEm = C.Green,
115 filenameEm = C.Green,
116 linenoEm = C.Green,
116 linenoEm = C.Green,
117 nameEm = C.Purple,
117 nameEm = C.Purple,
118 valEm = C.Blue,
118 valEm = C.Blue,
119
119
120 # Colors for printing the exception
120 # Colors for printing the exception
121 excName = C.Red,
121 excName = C.Red,
122 #line = C.Brown, # brown often is displayed as yellow
122 #line = C.Brown, # brown often is displayed as yellow
123 line = C.Red,
123 line = C.Red,
124 caret = C.Normal,
124 caret = C.Normal,
125 Normal = C.Normal,
125 Normal = C.Normal,
126 ))
126 ))
127
127
128 return ex_colors
128 return ex_colors
129
129
130
130
131 # For backwards compatibility, keep around a single global object. Note that
131 # For backwards compatibility, keep around a single global object. Note that
132 # this should NOT be used, the factory function should be used instead, since
132 # this should NOT be used, the factory function should be used instead, since
133 # these objects are stateful and it's very easy to get strange bugs if any code
133 # these objects are stateful and it's very easy to get strange bugs if any code
134 # modifies the module-level object's state.
134 # modifies the module-level object's state.
135 ExceptionColors = exception_colors()
135 ExceptionColors = exception_colors()
General Comments 0
You need to be logged in to leave comments. Login now