##// END OF EJS Templates
removing DirectoryLink class (which was an alias for FileLink) and modifying FileLink to raise an error if a directory is provided. @ellisonbg pointed out that these give a 404. I think removing this for now is the way to go as we don't have an immediate use case for DirectoryLink - FileLinks is what we would want users to call for linking to a directory.
Greg Caporaso -
Show More
@@ -85,6 +85,10 b' class FileLink(object):'
85 result_html_suffix : text to append at the end of link
85 result_html_suffix : text to append at the end of link
86 [default: '<br>']
86 [default: '<br>']
87 """
87 """
88 if isdir(path):
89 raise ValueError,\
90 ("Cannot display a directory as a FileLink object. "
91 "Use FileLinks to display '%s'." % path)
88 self.path = path
92 self.path = path
89 self.url_prefix = url_prefix
93 self.url_prefix = url_prefix
90 self.result_html_prefix = result_html_prefix
94 self.result_html_prefix = result_html_prefix
@@ -112,12 +116,6 b' class FileLink(object):'
112 """
116 """
113 return abspath(self.path)
117 return abspath(self.path)
114
118
115 # Create an alias for formatting a single directory name as a link.
116 # Right now this is the same as a formatting for a single file, but
117 # we'll encourage users to reference these with a different class in
118 # case we want to change this in the future.
119 DirectoryLink = FileLink
120
121 class FileLinks(FileLink):
119 class FileLinks(FileLink):
122 """Class for embedding local file links in an IPython session, based on path
120 """Class for embedding local file links in an IPython session, based on path
123
121
@@ -176,11 +174,11 b' class FileLinks(FileLink):'
176 self.included_suffixes = included_suffixes
174 self.included_suffixes = included_suffixes
177 # remove trailing slashs for more consistent output formatting
175 # remove trailing slashs for more consistent output formatting
178 path = path.rstrip('/')
176 path = path.rstrip('/')
179 FileLink.__init__(self,
177
180 path,
178 self.path = path
181 url_prefix,
179 self.url_prefix = url_prefix
182 result_html_prefix,
180 self.result_html_prefix = result_html_prefix
183 result_html_suffix)
181 self.result_html_suffix = result_html_suffix
184
182
185 self.notebook_display_formatter = \
183 self.notebook_display_formatter = \
186 notebook_display_formatter or self._get_notebook_display_formatter()
184 notebook_display_formatter or self._get_notebook_display_formatter()
@@ -31,16 +31,18 b' from IPython.lib import display'
31 #--------------------------
31 #--------------------------
32
32
33 def test_instantiation_FileLink():
33 def test_instantiation_FileLink():
34 """Test classes can be instantiated"""
34 """FileLink: Test class 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 """FileLink: Calling _repr_html_ on non-existant files returns a warning
39 """
39 fl = display.FileLink('example.txt')
40 fl = display.FileLink('example.txt')
40 nt.assert_true(fl._repr_html_().startswith('Path (<tt>example.txt</tt>)'))
41 nt.assert_true(fl._repr_html_().startswith('Path (<tt>example.txt</tt>)'))
41
42
42 def test_existing_path_FileLink():
43 def test_existing_path_FileLink():
43 """ Calling _repr_html_ functions as expected on existing filepath """
44 """FileLink: Calling _repr_html_ functions as expected on existing filepath
45 """
44 tf = NamedTemporaryFile()
46 tf = NamedTemporaryFile()
45 fl = display.FileLink(tf.name)
47 fl = display.FileLink(tf.name)
46 actual = fl._repr_html_()
48 actual = fl._repr_html_()
@@ -48,7 +50,8 b' def test_existing_path_FileLink():'
48 nt.assert_equal(actual,expected)
50 nt.assert_equal(actual,expected)
49
51
50 def test_existing_path_FileLink_repr():
52 def test_existing_path_FileLink_repr():
51 """ Calling repr() functions as expected on existing filepath """
53 """FileLink: Calling repr() functions as expected on existing filepath
54 """
52 tf = NamedTemporaryFile()
55 tf = NamedTemporaryFile()
53 fl = display.FileLink(tf.name)
56 fl = display.FileLink(tf.name)
54 actual = repr(fl)
57 actual = repr(fl)
@@ -60,16 +63,19 b' def test_existing_path_FileLink_repr():'
60 #--------------------------
63 #--------------------------
61
64
62 def test_instantiation_FileLinks():
65 def test_instantiation_FileLinks():
63 """Test classes can be instantiated"""
66 """FileLinks: Test class can be instantiated
67 """
64 fls = display.FileLinks('example')
68 fls = display.FileLinks('example')
65
69
66 def test_warning_on_non_existant_path_FileLinks():
70 def test_warning_on_non_existant_path_FileLinks():
67 """Calling _repr_html_ on non-existant files returns a warning"""
71 """FileLinks: Calling _repr_html_ on non-existant files returns a warning
72 """
68 fls = display.FileLinks('example')
73 fls = display.FileLinks('example')
69 nt.assert_true(fls._repr_html_().startswith('Path (<tt>example</tt>)'))
74 nt.assert_true(fls._repr_html_().startswith('Path (<tt>example</tt>)'))
70
75
71 def test_existing_path_FileLinks():
76 def test_existing_path_FileLinks():
72 """ Calling _repr_html_ functions as expected on existing directory """
77 """FileLinks: Calling _repr_html_ functions as expected on existing dir
78 """
73 td = mkdtemp()
79 td = mkdtemp()
74 tf1 = NamedTemporaryFile(dir=td)
80 tf1 = NamedTemporaryFile(dir=td)
75 tf2 = NamedTemporaryFile(dir=td)
81 tf2 = NamedTemporaryFile(dir=td)
@@ -85,7 +91,7 b' def test_existing_path_FileLinks():'
85 nt.assert_equal(actual,expected)
91 nt.assert_equal(actual,expected)
86
92
87 def test_existing_path_FileLinks_alt_formatter():
93 def test_existing_path_FileLinks_alt_formatter():
88 """ Calling _repr_html_ functions as expected with an alternative formatter
94 """FileLinks: Calling _repr_html_ functions as expected w/ an alt formatter
89 """
95 """
90 td = mkdtemp()
96 td = mkdtemp()
91 tf1 = NamedTemporaryFile(dir=td)
97 tf1 = NamedTemporaryFile(dir=td)
@@ -102,7 +108,7 b' def test_existing_path_FileLinks_alt_formatter():'
102 nt.assert_equal(actual,expected)
108 nt.assert_equal(actual,expected)
103
109
104 def test_existing_path_FileLinks_repr():
110 def test_existing_path_FileLinks_repr():
105 """ Calling repr() functions as expected on existing directory """
111 """FileLinks: Calling repr() functions as expected on existing directory """
106 td = mkdtemp()
112 td = mkdtemp()
107 tf1 = NamedTemporaryFile(dir=td)
113 tf1 = NamedTemporaryFile(dir=td)
108 tf2 = NamedTemporaryFile(dir=td)
114 tf2 = NamedTemporaryFile(dir=td)
@@ -116,7 +122,7 b' def test_existing_path_FileLinks_repr():'
116 nt.assert_equal(actual,expected)
122 nt.assert_equal(actual,expected)
117
123
118 def test_existing_path_FileLinks_repr_alt_formatter():
124 def test_existing_path_FileLinks_repr_alt_formatter():
119 """ Calling repr() functions as expected with an alternative formatter
125 """FileLinks: Calling repr() functions as expected w/ alt formatter
120 """
126 """
121 td = mkdtemp()
127 td = mkdtemp()
122 tf1 = NamedTemporaryFile(dir=td)
128 tf1 = NamedTemporaryFile(dir=td)
@@ -132,23 +138,3 b' def test_existing_path_FileLinks_repr_alt_formatter():'
132 # We compare the sorted list of links here as that's more reliable
138 # We compare the sorted list of links here as that's more reliable
133 nt.assert_equal(actual,expected)
139 nt.assert_equal(actual,expected)
134
140
135 #--------------------------
136 # DirectoryLink tests
137 #--------------------------
138
139 def test_instantiation_DirectoryLink():
140 """Test classes can be instantiated"""
141 dl = display.DirectoryLink('example')
142
143 def test_warning_on_non_existant_path_DirectoryLink():
144 """Calling _repr_html_ on non-existant files returns a warning"""
145 dl = display.DirectoryLink('example')
146 nt.assert_true(dl._repr_html_().startswith('Path (<tt>example</tt>)'))
147
148 def test_existing_path_DirectoryLink():
149 """ Calling _repr_html_ functions as expected on existing directory """
150 td = mkdtemp()
151 dl = display.DirectoryLink(td)
152 actual = dl._repr_html_()
153 expected = "<a href='files/%s' target='_blank'>%s</a><br>" % (td,td)
154 nt.assert_equal(actual,expected)
General Comments 0
You need to be logged in to leave comments. Login now