##// END OF EJS Templates
fixed function name overlap that was causing a test to not be run
Greg Caporaso -
Show More
@@ -1,119 +1,119 b''
1 """Tests for IPython.lib.display.
1 """Tests for IPython.lib.display.
2
2
3 """
3 """
4 #-----------------------------------------------------------------------------
4 #-----------------------------------------------------------------------------
5 # Copyright (c) 2012, the IPython Development Team.
5 # Copyright (c) 2012, the IPython Development Team.
6 #
6 #
7 # Distributed under the terms of the Modified BSD License.
7 # Distributed under the terms of the Modified BSD License.
8 #
8 #
9 # The full license is in the file COPYING.txt, distributed with this software.
9 # The full license is in the file COPYING.txt, distributed with this software.
10 #-----------------------------------------------------------------------------
10 #-----------------------------------------------------------------------------
11
11
12 #-----------------------------------------------------------------------------
12 #-----------------------------------------------------------------------------
13 # Imports
13 # Imports
14 #-----------------------------------------------------------------------------
14 #-----------------------------------------------------------------------------
15 from __future__ import print_function
15 from __future__ import print_function
16 from tempfile import NamedTemporaryFile, mkdtemp
16 from tempfile import NamedTemporaryFile, mkdtemp
17
17 from os.path import split
18
18
19 # Third-party imports
19 # Third-party imports
20 import nose.tools as nt
20 import nose.tools as nt
21
21
22 # Our own imports
22 # Our own imports
23 from IPython.lib import display
23 from IPython.lib import display
24
24
25 #-----------------------------------------------------------------------------
25 #-----------------------------------------------------------------------------
26 # Classes and functions
26 # Classes and functions
27 #-----------------------------------------------------------------------------
27 #-----------------------------------------------------------------------------
28
28
29 #--------------------------
29 #--------------------------
30 # FileLink tests
30 # FileLink tests
31 #--------------------------
31 #--------------------------
32
32
33 def test_instantiation_FileLink():
33 def test_instantiation_FileLink():
34 """Test classes can be instantiated"""
34 """Test classes can be instantiated"""
35 fl = display.FileLink('example.txt')
35 fl = display.FileLink('example.txt')
36
36
37 def test_warning_on_non_existant_path_FileLink():
37 def test_warning_on_non_existant_path_FileLink():
38 """Calling _repr_html_ on non-existant files returns a warning"""
38 """Calling _repr_html_ on non-existant files returns a warning"""
39 fl = display.FileLink('example.txt')
39 fl = display.FileLink('example.txt')
40 nt.assert_true(fl._repr_html_().startswith('Path (<tt>example.txt</tt>)'))
40 nt.assert_true(fl._repr_html_().startswith('Path (<tt>example.txt</tt>)'))
41
41
42 def test_existing_path_FileLink():
42 def test_existing_path_FileLink():
43 """ Calling _repr_html_ functions as expected on existing filepath """
43 """ Calling _repr_html_ functions as expected on existing filepath """
44 tf = NamedTemporaryFile()
44 tf = NamedTemporaryFile()
45 fl = display.FileLink(tf.name)
45 fl = display.FileLink(tf.name)
46 actual = fl._repr_html_()
46 actual = fl._repr_html_()
47 expected = "<a href='files/%s' target='_blank'>%s</a><br>" % (tf.name,tf.name)
47 expected = "<a href='files/%s' target='_blank'>%s</a><br>" % (tf.name,tf.name)
48 nt.assert_equal(actual,expected)
48 nt.assert_equal(actual,expected)
49
49
50 def test_existing_path_FileLink_repr():
50 def test_existing_path_FileLink_repr():
51 """ Calling repr() functions as expected on existing filepath """
51 """ Calling repr() functions as expected on existing filepath """
52 tf = NamedTemporaryFile()
52 tf = NamedTemporaryFile()
53 fl = display.FileLink(tf.name)
53 fl = display.FileLink(tf.name)
54 actual = repr(fl)
54 actual = repr(fl)
55 expected = tf.name
55 expected = tf.name
56 nt.assert_equal(actual,expected)
56 nt.assert_equal(actual,expected)
57
57
58 #--------------------------
58 #--------------------------
59 # FileLinks tests
59 # FileLinks tests
60 #--------------------------
60 #--------------------------
61
61
62 def test_instantiation_FileLinks():
62 def test_instantiation_FileLinks():
63 """Test classes can be instantiated"""
63 """Test classes can be instantiated"""
64 fls = display.FileLinks('example')
64 fls = display.FileLinks('example')
65
65
66 def test_warning_on_non_existant_path_FileLinks():
66 def test_warning_on_non_existant_path_FileLinks():
67 """Calling _repr_html_ on non-existant files returns a warning"""
67 """Calling _repr_html_ on non-existant files returns a warning"""
68 fls = display.FileLinks('example')
68 fls = display.FileLinks('example')
69 nt.assert_true(fls._repr_html_().startswith('Path (<tt>example</tt>)'))
69 nt.assert_true(fls._repr_html_().startswith('Path (<tt>example</tt>)'))
70
70
71 def test_existing_path_FileLinks():
71 def test_existing_path_FileLinks():
72 """ Calling _repr_html_ functions as expected on existing directory """
72 """ Calling _repr_html_ functions as expected on existing directory """
73 td = mkdtemp()
73 td = mkdtemp()
74 tf1 = NamedTemporaryFile(dir=td)
74 tf1 = NamedTemporaryFile(dir=td)
75 tf2 = NamedTemporaryFile(dir=td)
75 tf2 = NamedTemporaryFile(dir=td)
76 fl = display.FileLinks(td)
76 fl = display.FileLinks(td)
77 actual = fl._repr_html_()
77 actual = fl._repr_html_()
78 actual = actual.split('\n')
78 actual = actual.split('\n')
79 actual.sort()
79 actual.sort()
80 expected = ["<a href='files/%s' target='_blank'>%s</a><br>" % (tf2.name,tf2.name),
80 expected = ["<a href='files/%s' target='_blank'>%s</a><br>" % (tf2.name,split(tf2.name)[1]),
81 "<a href='files/%s' target='_blank'>%s</a><br>" % (tf1.name,tf1.name)]
81 "<a href='files/%s' target='_blank'>%s</a><br>" % (tf1.name,split(tf1.name)[1])]
82 expected.sort()
82 expected.sort()
83 # We compare the sorted list of links here as that's more reliable
83 # We compare the sorted list of links here as that's more reliable
84 nt.assert_equal(actual,expected)
84 nt.assert_equal(actual,expected)
85
85
86 def test_existing_path_FileLinks_repr():
86 def test_existing_path_FileLinks_repr():
87 """ Calling repr() functions as expected on existing directory """
87 """ Calling repr() functions as expected on existing directory """
88 td = mkdtemp()
88 td = mkdtemp()
89 tf1 = NamedTemporaryFile(dir=td)
89 tf1 = NamedTemporaryFile(dir=td)
90 tf2 = NamedTemporaryFile(dir=td)
90 tf2 = NamedTemporaryFile(dir=td)
91 fl = display.FileLinks(td)
91 fl = display.FileLinks(td)
92 actual = repr(fl)
92 actual = repr(fl)
93 actual = actual.split('\n')
93 actual = actual.split('\n')
94 actual.sort()
94 actual.sort()
95 expected = [tf1.name,tf2.name]
95 expected = [tf1.name,tf2.name]
96 expected.sort()
96 expected.sort()
97 # We compare the sorted list of links here as that's more reliable
97 # We compare the sorted list of links here as that's more reliable
98 nt.assert_equal(actual,expected)
98 nt.assert_equal(actual,expected)
99
99
100 #--------------------------
100 #--------------------------
101 # DirectoryLink tests
101 # DirectoryLink tests
102 #--------------------------
102 #--------------------------
103
103
104 def test_instantiation_DirectoryLink():
104 def test_instantiation_DirectoryLink():
105 """Test classes can be instantiated"""
105 """Test classes can be instantiated"""
106 dl = display.DirectoryLink('example')
106 dl = display.DirectoryLink('example')
107
107
108 def test_warning_on_non_existant_path_DirectoryLink():
108 def test_warning_on_non_existant_path_DirectoryLink():
109 """Calling _repr_html_ on non-existant files returns a warning"""
109 """Calling _repr_html_ on non-existant files returns a warning"""
110 dl = display.DirectoryLink('example')
110 dl = display.DirectoryLink('example')
111 nt.assert_true(dl._repr_html_().startswith('Path (<tt>example</tt>)'))
111 nt.assert_true(dl._repr_html_().startswith('Path (<tt>example</tt>)'))
112
112
113 def test_existing_path_FileLinks():
113 def test_existing_path_DirectoryLink():
114 """ Calling _repr_html_ functions as expected on existing directory """
114 """ Calling _repr_html_ functions as expected on existing directory """
115 td = mkdtemp()
115 td = mkdtemp()
116 dl = display.DirectoryLink(td)
116 dl = display.DirectoryLink(td)
117 actual = dl._repr_html_()
117 actual = dl._repr_html_()
118 expected = "<a href='files/%s' target='_blank'>%s</a><br>" % (td,td)
118 expected = "<a href='files/%s' target='_blank'>%s</a><br>" % (td,td)
119 nt.assert_equal(actual,expected)
119 nt.assert_equal(actual,expected)
General Comments 0
You need to be logged in to leave comments. Login now