##// END OF EJS Templates
Fix test that got broken under Python 2
Thomas Kluyver -
Show More
@@ -1,66 +1,66 b''
1 # encoding: utf-8
1 # encoding: utf-8
2 """
2 """
3 Utilities for warnings. Shoudn't we just use the built in warnings module.
3 Utilities for warnings. Shoudn't we just use the built in warnings module.
4 """
4 """
5
5
6 #-----------------------------------------------------------------------------
6 #-----------------------------------------------------------------------------
7 # Copyright (C) 2008-2009 The IPython Development Team
7 # Copyright (C) 2008-2009 The IPython Development Team
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 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14 # Imports
14 # Imports
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16
16
17 import sys
17 import sys
18
18
19 from IPython.utils import io
19 from IPython.utils import io
20
20
21 #-----------------------------------------------------------------------------
21 #-----------------------------------------------------------------------------
22 # Code
22 # Code
23 #-----------------------------------------------------------------------------
23 #-----------------------------------------------------------------------------
24
24
25 def warn(msg,level=2,exit_val=1):
25 def warn(msg,level=2,exit_val=1):
26 """Standard warning printer. Gives formatting consistency.
26 """Standard warning printer. Gives formatting consistency.
27
27
28 Output is sent to io.stderr (sys.stderr by default).
28 Output is sent to io.stderr (sys.stderr by default).
29
29
30 Options:
30 Options:
31
31
32 -level(2): allows finer control:
32 -level(2): allows finer control:
33 0 -> Do nothing, dummy function.
33 0 -> Do nothing, dummy function.
34 1 -> Print message.
34 1 -> Print message.
35 2 -> Print 'WARNING:' + message. (Default level).
35 2 -> Print 'WARNING:' + message. (Default level).
36 3 -> Print 'ERROR:' + message.
36 3 -> Print 'ERROR:' + message.
37 4 -> Print 'FATAL ERROR:' + message and trigger a sys.exit(exit_val).
37 4 -> Print 'FATAL ERROR:' + message and trigger a sys.exit(exit_val).
38
38
39 -exit_val (1): exit value returned by sys.exit() for a level 4
39 -exit_val (1): exit value returned by sys.exit() for a level 4
40 warning. Ignored for all other levels."""
40 warning. Ignored for all other levels."""
41
41
42 if level>0:
42 if level>0:
43 header = ['','','WARNING: ','ERROR: ','FATAL ERROR: ']
43 header = ['','','WARNING: ','ERROR: ','FATAL ERROR: ']
44 print >> io.stderr, '%s%s' % (header[level],msg)
44 io.stderr.write('%s%s' % (header[level],msg))
45 if level == 4:
45 if level == 4:
46 print >> io.stderr,'Exiting.\n'
46 print >> io.stderr,'Exiting.\n'
47 sys.exit(exit_val)
47 sys.exit(exit_val)
48
48
49
49
50 def info(msg):
50 def info(msg):
51 """Equivalent to warn(msg,level=1)."""
51 """Equivalent to warn(msg,level=1)."""
52
52
53 warn(msg,level=1)
53 warn(msg,level=1)
54
54
55
55
56 def error(msg):
56 def error(msg):
57 """Equivalent to warn(msg,level=3)."""
57 """Equivalent to warn(msg,level=3)."""
58
58
59 warn(msg,level=3)
59 warn(msg,level=3)
60
60
61
61
62 def fatal(msg,exit_val=1):
62 def fatal(msg,exit_val=1):
63 """Equivalent to warn(msg,exit_val=exit_val,level=4)."""
63 """Equivalent to warn(msg,exit_val=exit_val,level=4)."""
64
64
65 warn(msg,exit_val=exit_val,level=4)
65 warn(msg,exit_val=exit_val,level=4)
66
66
General Comments 0
You need to be logged in to leave comments. Login now