Show More
@@ -13,6 +13,8 b'' | |||||
13 | # Imports |
|
13 | # Imports | |
14 | #----------------------------------------------------------------------------- |
|
14 | #----------------------------------------------------------------------------- | |
15 | from __future__ import print_function |
|
15 | from __future__ import print_function | |
|
16 | from tempfile import NamedTemporaryFile, mkdtemp | |||
|
17 | ||||
16 |
|
18 | |||
17 | # Third-party imports |
|
19 | # Third-party imports | |
18 | import nose.tools as nt |
|
20 | import nose.tools as nt | |
@@ -37,19 +39,52 b' def test_warning_on_non_existant_path_FileLink():' | |||||
37 | fl = display.FileLink('example.txt') |
|
39 | fl = display.FileLink('example.txt') | |
38 | 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>)')) | |
39 |
|
41 | |||
|
42 | def test_existing_path_FileLink(): | |||
|
43 | """ Calling _repr_html_ functions as expected on existing filepath """ | |||
|
44 | tf = NamedTemporaryFile() | |||
|
45 | fl = display.FileLink(tf.name) | |||
|
46 | actual = fl._repr_html_() | |||
|
47 | # Note: this is a bit awkward since tf.name has to be a full path | |||
|
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) | |||
|
54 | ||||
40 | #-------------------------- |
|
55 | #-------------------------- | |
41 | # FileLinks tests |
|
56 | # FileLinks tests | |
42 | #-------------------------- |
|
57 | #-------------------------- | |
43 |
|
58 | |||
44 | def test_instantiation_FileLinks(): |
|
59 | def test_instantiation_FileLinks(): | |
45 | """Test classes can be instantiated""" |
|
60 | """Test classes can be instantiated""" | |
46 |
fls = display.FileLinks( |
|
61 | fls = display.FileLinks('example') | |
47 |
|
62 | |||
48 | def test_warning_on_non_existant_path_FileLinks(): |
|
63 | def test_warning_on_non_existant_path_FileLinks(): | |
49 | """Calling _repr_html_ on non-existant files returns a warning""" |
|
64 | """Calling _repr_html_ on non-existant files returns a warning""" | |
50 | fls = display.FileLinks('example') |
|
65 | fls = display.FileLinks('example') | |
51 | nt.assert_true(fls._repr_html_().startswith('Path (<tt>example</tt>)')) |
|
66 | nt.assert_true(fls._repr_html_().startswith('Path (<tt>example</tt>)')) | |
52 |
|
67 | |||
|
68 | def test_existing_path_FileLinks(): | |||
|
69 | """ Calling _repr_html_ functions as expected on existing directory """ | |||
|
70 | td = mkdtemp() | |||
|
71 | tf1 = NamedTemporaryFile(dir=td) | |||
|
72 | tf2 = NamedTemporaryFile(dir=td) | |||
|
73 | fl = display.FileLinks(td) | |||
|
74 | actual = fl._repr_html_() | |||
|
75 | actual = actual.split('\n') | |||
|
76 | actual.sort() | |||
|
77 | # Note: this is a bit awkward since tf.name has to be a full path | |||
|
78 | # for it to exist, but that won't happen in our applications. While | |||
|
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() | |||
|
85 | # We compare the sorted list of links here as that's more reliable | |||
|
86 | nt.assert_equal(actual,expected) | |||
|
87 | ||||
53 | #-------------------------- |
|
88 | #-------------------------- | |
54 | # DirectoryLink tests |
|
89 | # DirectoryLink tests | |
55 | #-------------------------- |
|
90 | #-------------------------- | |
@@ -62,3 +97,16 b' def test_warning_on_non_existant_path_DirectoryLink():' | |||||
62 | """Calling _repr_html_ on non-existant files returns a warning""" |
|
97 | """Calling _repr_html_ on non-existant files returns a warning""" | |
63 | dl = display.DirectoryLink('example') |
|
98 | dl = display.DirectoryLink('example') | |
64 | nt.assert_true(dl._repr_html_().startswith('Path (<tt>example</tt>)')) |
|
99 | nt.assert_true(dl._repr_html_().startswith('Path (<tt>example</tt>)')) | |
|
100 | ||||
|
101 | def test_existing_path_FileLinks(): | |||
|
102 | """ Calling _repr_html_ functions as expected on existing directory """ | |||
|
103 | td = mkdtemp() | |||
|
104 | dl = display.DirectoryLink(td) | |||
|
105 | actual = dl._repr_html_() | |||
|
106 | # Note: this is a bit awkward since tf.name has to be a full path | |||
|
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) |
General Comments 0
You need to be logged in to leave comments.
Login now