##// 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 85 result_html_suffix : text to append at the end of link
86 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 92 self.path = path
89 93 self.url_prefix = url_prefix
90 94 self.result_html_prefix = result_html_prefix
@@ -111,12 +115,6 b' class FileLink(object):'
111 115 """return absolute path to file
112 116 """
113 117 return abspath(self.path)
114
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 118
121 119 class FileLinks(FileLink):
122 120 """Class for embedding local file links in an IPython session, based on path
@@ -176,11 +174,11 b' class FileLinks(FileLink):'
176 174 self.included_suffixes = included_suffixes
177 175 # remove trailing slashs for more consistent output formatting
178 176 path = path.rstrip('/')
179 FileLink.__init__(self,
180 path,
181 url_prefix,
182 result_html_prefix,
183 result_html_suffix)
177
178 self.path = path
179 self.url_prefix = url_prefix
180 self.result_html_prefix = result_html_prefix
181 self.result_html_suffix = result_html_suffix
184 182
185 183 self.notebook_display_formatter = \
186 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 33 def test_instantiation_FileLink():
34 """Test classes can be instantiated"""
34 """FileLink: Test class can be instantiated"""
35 35 fl = display.FileLink('example.txt')
36 36
37 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 40 fl = display.FileLink('example.txt')
40 41 nt.assert_true(fl._repr_html_().startswith('Path (<tt>example.txt</tt>)'))
41 42
42 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 46 tf = NamedTemporaryFile()
45 47 fl = display.FileLink(tf.name)
46 48 actual = fl._repr_html_()
@@ -48,7 +50,8 b' def test_existing_path_FileLink():'
48 50 nt.assert_equal(actual,expected)
49 51
50 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 55 tf = NamedTemporaryFile()
53 56 fl = display.FileLink(tf.name)
54 57 actual = repr(fl)
@@ -60,16 +63,19 b' def test_existing_path_FileLink_repr():'
60 63 #--------------------------
61 64
62 65 def test_instantiation_FileLinks():
63 """Test classes can be instantiated"""
66 """FileLinks: Test class can be instantiated
67 """
64 68 fls = display.FileLinks('example')
65 69
66 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 73 fls = display.FileLinks('example')
69 74 nt.assert_true(fls._repr_html_().startswith('Path (<tt>example</tt>)'))
70 75
71 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 79 td = mkdtemp()
74 80 tf1 = NamedTemporaryFile(dir=td)
75 81 tf2 = NamedTemporaryFile(dir=td)
@@ -85,7 +91,7 b' def test_existing_path_FileLinks():'
85 91 nt.assert_equal(actual,expected)
86 92
87 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 96 td = mkdtemp()
91 97 tf1 = NamedTemporaryFile(dir=td)
@@ -102,7 +108,7 b' def test_existing_path_FileLinks_alt_formatter():'
102 108 nt.assert_equal(actual,expected)
103 109
104 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 112 td = mkdtemp()
107 113 tf1 = NamedTemporaryFile(dir=td)
108 114 tf2 = NamedTemporaryFile(dir=td)
@@ -116,7 +122,7 b' def test_existing_path_FileLinks_repr():'
116 122 nt.assert_equal(actual,expected)
117 123
118 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 127 td = mkdtemp()
122 128 tf1 = NamedTemporaryFile(dir=td)
@@ -132,23 +138,3 b' def test_existing_path_FileLinks_repr_alt_formatter():'
132 138 # We compare the sorted list of links here as that's more reliable
133 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