##// END OF EJS Templates
Fix another win32 test failure....
Fernando Perez -
Show More
@@ -1,97 +1,101 b''
1 1 #!/usr/bin/env python
2 2 # encoding: utf-8
3 3 """
4 4 Simple tests for :mod:`IPython.extensions.pretty`.
5 5 """
6 6
7 7 #-----------------------------------------------------------------------------
8 8 # Copyright (C) 2008-2009 The IPython Development Team
9 9 #
10 10 # Distributed under the terms of the BSD License. The full license is in
11 11 # the file COPYING, distributed as part of this software.
12 12 #-----------------------------------------------------------------------------
13 13
14 14 #-----------------------------------------------------------------------------
15 15 # Imports
16 16 #-----------------------------------------------------------------------------
17 17
18 18 from unittest import TestCase
19 19
20 20 from IPython.core.component import Component, masquerade_as
21 21 from IPython.core.iplib import InteractiveShell
22 22 from IPython.extensions import pretty as pretty_ext
23 23 from IPython.external import pretty
24 from IPython.testing import decorators as dec
24 25 from IPython.testing import tools as tt
25 26 from IPython.utils.traitlets import Bool
26 27
27 28 #-----------------------------------------------------------------------------
28 29 # Tests
29 30 #-----------------------------------------------------------------------------
30 31
31
32 32 class InteractiveShellStub(Component):
33 33 pprint = Bool(True)
34 34
35 35 class A(object):
36 36 pass
37 37
38 38 def a_pprinter(o, p, c):
39 39 return p.text("<A>")
40 40
41 41 class TestPrettyResultDisplay(TestCase):
42 42
43 43 def setUp(self):
44 44 self.ip = InteractiveShellStub(None)
45 45 # This allows our stub to be retrieved instead of the real
46 46 # InteractiveShell
47 47 masquerade_as(self.ip, InteractiveShell)
48 48 self.prd = pretty_ext.PrettyResultDisplay(self.ip,
49 49 name='pretty_result_display')
50 50
51 51 def test_for_type(self):
52 52 self.prd.for_type(A, a_pprinter)
53 53 a = A()
54 54 result = pretty.pretty(a)
55 55 self.assertEquals(result, "<A>")
56 56
57 57 ipy_src = """
58 58 class A(object):
59 59 def __repr__(self):
60 60 return 'A()'
61 61
62 62 class B(object):
63 63 def __repr__(self):
64 64 return 'B()'
65 65
66 66 a = A()
67 67 b = B()
68 68
69 69 def a_pretty_printer(obj, p, cycle):
70 70 p.text('<A>')
71 71
72 72 def b_pretty_printer(obj, p, cycle):
73 73 p.text('<B>')
74 74
75 75
76 76 a
77 77 b
78 78
79 79 ip = get_ipython()
80 80 prd = ip.load_extension('pretty')
81 81 prd.for_type(A, a_pretty_printer)
82 82 prd.for_type_by_name(B.__module__, B.__name__, b_pretty_printer)
83 83
84 84 a
85 85 b
86 86 """
87 87 ipy_out = """
88 88 A()
89 89 B()
90 90 <A>
91 91 <B>
92 92 """
93 93
94 94 class TestPrettyInteractively(tt.TempFileMixin):
95
96 # XXX Unfortunately, ipexec_validate fails under win32. If someone helps
97 # us write a win32-compatible version, we can reactivate this test.
98 @dec.skip_win32
95 99 def test_printers(self):
96 100 self.mktmp(ipy_src, '.ipy')
97 101 tt.ipexec_validate(self.fname, ipy_out)
General Comments 0
You need to be logged in to leave comments. Login now