##// END OF EJS Templates
added tests to confirm that error is raise when FileLink is passed a directory. Also specifically disallowed passing a file to FileLinks for consistency.
Greg Caporaso -
Show More
@@ -87,7 +87,7 b' class FileLink(object):'
87 """
87 """
88 if isdir(path):
88 if isdir(path):
89 raise ValueError,\
89 raise ValueError,\
90 ("Cannot display a directory as a FileLink object. "
90 ("Cannot display a directory using FileLink. "
91 "Use FileLinks to display '%s'." % path)
91 "Use FileLinks to display '%s'." % path)
92 self.path = path
92 self.path = path
93 self.url_prefix = url_prefix
93 self.url_prefix = url_prefix
@@ -171,6 +171,10 b' class FileLinks(FileLink):'
171 place, can be passed here to support alternative formatting.
171 place, can be passed here to support alternative formatting.
172
172
173 """
173 """
174 if isfile(path):
175 raise ValueError,\
176 ("Cannot display a file using FileLinks. "
177 "Use FileLink to display '%s'." % path)
174 self.included_suffixes = included_suffixes
178 self.included_suffixes = included_suffixes
175 # remove trailing slashs for more consistent output formatting
179 # remove trailing slashs for more consistent output formatting
176 path = path.rstrip('/')
180 path = path.rstrip('/')
@@ -58,6 +58,12 b' def test_existing_path_FileLink_repr():'
58 expected = tf.name
58 expected = tf.name
59 nt.assert_equal(actual,expected)
59 nt.assert_equal(actual,expected)
60
60
61 def test_error_on_directory_to_FileLink():
62 """FileLink: Raises error when passed directory
63 """
64 td = mkdtemp()
65 nt.assert_raises(ValueError,display.FileLink,td)
66
61 #--------------------------
67 #--------------------------
62 # FileLinks tests
68 # FileLinks tests
63 #--------------------------
69 #--------------------------
@@ -138,3 +144,10 b' def test_existing_path_FileLinks_repr_alt_formatter():'
138 # We compare the sorted list of links here as that's more reliable
144 # We compare the sorted list of links here as that's more reliable
139 nt.assert_equal(actual,expected)
145 nt.assert_equal(actual,expected)
140
146
147 def test_error_on_file_to_FileLinks():
148 """FileLinks: Raises error when passed file
149 """
150 td = mkdtemp()
151 tf1 = NamedTemporaryFile(dir=td)
152 nt.assert_raises(ValueError,display.FileLinks,tf1.name)
153
General Comments 0
You need to be logged in to leave comments. Login now