##// END OF EJS Templates
modified to join urls with '/'.join instead of os.path.join. @takluyver pointed out that while os.path.join does work for this on OS X and Linux, it's not meant for constructing URLs, so fails on Windows where paths are constructed using \ rather than /.
Greg Caporaso -
Show More
@@ -4,7 +4,7 b' Authors : MinRK, gregcaporaso'
4 """
4 """
5
5
6 from os import walk
6 from os import walk
7 from os.path import join, exists, isfile, splitext
7 from os.path import exists, isfile, splitext
8
8
9
9
10 class YouTubeVideo(object):
10 class YouTubeVideo(object):
@@ -74,7 +74,7 b' class FileLink(object):'
74 self.result_html_suffix = result_html_suffix
74 self.result_html_suffix = result_html_suffix
75
75
76 def _format_path(self):
76 def _format_path(self):
77 fp = join(self.url_prefix,self.path)
77 fp = '/'.join([self.url_prefix,self.path])
78 return ''.join([self.result_html_prefix,
78 return ''.join([self.result_html_prefix,
79 self.link_str % (fp, self.path),
79 self.link_str % (fp, self.path),
80 self.result_html_suffix])
80 self.result_html_suffix])
@@ -44,12 +44,7 b' def test_existing_path_FileLink():'
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 # Note: this is a bit awkward since tf.name has to be a full path
47 expected = "<a href='files/%s' target='_blank'>%s</a><br>" % (tf.name,tf.name)
48 # for it to exist, but that won't happen in our applications. While
49 # in practice "files/" would be prepended to the href path, os.join
50 # doesn't do that if the second value is an absolute path. So, the
51 # expected here is slightly different than what we get in practice.
52 expected = "<a href='%s' target='_blank'>%s</a><br>" % (tf.name,tf.name)
53 nt.assert_equal(actual,expected)
48 nt.assert_equal(actual,expected)
54
49
55 #--------------------------
50 #--------------------------
@@ -74,13 +69,8 b' def test_existing_path_FileLinks():'
74 actual = fl._repr_html_()
69 actual = fl._repr_html_()
75 actual = actual.split('\n')
70 actual = actual.split('\n')
76 actual.sort()
71 actual.sort()
77 # Note: this is a bit awkward since tf.name has to be a full path
72 expected = ["<a href='files/%s' target='_blank'>%s</a><br>" % (tf2.name,tf2.name),
78 # for it to exist, but that won't happen in our applications. While
73 "<a href='files/%s' target='_blank'>%s</a><br>" % (tf1.name,tf1.name)]
79 # in practice "files/" would be prepended to the href path, os.join
80 # doesn't do that if the second value is an absolute path. So, the
81 # expected here is slightly different than what we get in practice.
82 expected = ["<a href='%s' target='_blank'>%s</a><br>" % (tf2.name,tf2.name.split('/')[-1]),
83 "<a href='%s' target='_blank'>%s</a><br>" % (tf1.name,tf1.name.split('/')[-1])]
84 expected.sort()
74 expected.sort()
85 # We compare the sorted list of links here as that's more reliable
75 # We compare the sorted list of links here as that's more reliable
86 nt.assert_equal(actual,expected)
76 nt.assert_equal(actual,expected)
@@ -103,10 +93,5 b' def test_existing_path_FileLinks():'
103 td = mkdtemp()
93 td = mkdtemp()
104 dl = display.DirectoryLink(td)
94 dl = display.DirectoryLink(td)
105 actual = dl._repr_html_()
95 actual = dl._repr_html_()
106 # Note: this is a bit awkward since tf.name has to be a full path
96 expected = "<a href='files/%s' target='_blank'>%s</a><br>" % (td,td)
107 # for it to exist, but that won't happen in our applications. While
108 # in practice "files/" would be prepended to the href path, os.join
109 # doesn't do that if the second value is an absolute path. So, the
110 # expected here is slightly different than what we get in practice.
111 expected = "<a href='%s' target='_blank'>%s</a><br>" % (td,td)
112 nt.assert_equal(actual,expected)
97 nt.assert_equal(actual,expected)
General Comments 0
You need to be logged in to leave comments. Login now