Show More
@@ -1,97 +1,119 b'' | |||
|
1 | 1 | """Tests for IPython.lib.display. |
|
2 | 2 | |
|
3 | 3 | """ |
|
4 | 4 | #----------------------------------------------------------------------------- |
|
5 | 5 | # Copyright (c) 2012, the IPython Development Team. |
|
6 | 6 | # |
|
7 | 7 | # Distributed under the terms of the Modified BSD License. |
|
8 | 8 | # |
|
9 | 9 | # The full license is in the file COPYING.txt, distributed with this software. |
|
10 | 10 | #----------------------------------------------------------------------------- |
|
11 | 11 | |
|
12 | 12 | #----------------------------------------------------------------------------- |
|
13 | 13 | # Imports |
|
14 | 14 | #----------------------------------------------------------------------------- |
|
15 | 15 | from __future__ import print_function |
|
16 | 16 | from tempfile import NamedTemporaryFile, mkdtemp |
|
17 | 17 | |
|
18 | 18 | |
|
19 | 19 | # Third-party imports |
|
20 | 20 | import nose.tools as nt |
|
21 | 21 | |
|
22 | 22 | # Our own imports |
|
23 | 23 | from IPython.lib import display |
|
24 | 24 | |
|
25 | 25 | #----------------------------------------------------------------------------- |
|
26 | 26 | # Classes and functions |
|
27 | 27 | #----------------------------------------------------------------------------- |
|
28 | 28 | |
|
29 | 29 | #-------------------------- |
|
30 | 30 | # FileLink tests |
|
31 | 31 | #-------------------------- |
|
32 | 32 | |
|
33 | 33 | def test_instantiation_FileLink(): |
|
34 | 34 | """Test classes can be instantiated""" |
|
35 | 35 | fl = display.FileLink('example.txt') |
|
36 | 36 | |
|
37 | 37 | def test_warning_on_non_existant_path_FileLink(): |
|
38 | 38 | """Calling _repr_html_ on non-existant files returns a warning""" |
|
39 | 39 | fl = display.FileLink('example.txt') |
|
40 | 40 | nt.assert_true(fl._repr_html_().startswith('Path (<tt>example.txt</tt>)')) |
|
41 | 41 | |
|
42 | 42 | def test_existing_path_FileLink(): |
|
43 | 43 | """ Calling _repr_html_ functions as expected on existing filepath """ |
|
44 | 44 | tf = NamedTemporaryFile() |
|
45 | 45 | fl = display.FileLink(tf.name) |
|
46 | 46 | actual = fl._repr_html_() |
|
47 | 47 | expected = "<a href='files/%s' target='_blank'>%s</a><br>" % (tf.name,tf.name) |
|
48 | 48 | nt.assert_equal(actual,expected) |
|
49 | 49 | |
|
50 | def test_existing_path_FileLink_repr(): | |
|
51 | """ Calling repr() functions as expected on existing filepath """ | |
|
52 | tf = NamedTemporaryFile() | |
|
53 | fl = display.FileLink(tf.name) | |
|
54 | actual = repr(fl) | |
|
55 | expected = tf.name | |
|
56 | nt.assert_equal(actual,expected) | |
|
57 | ||
|
50 | 58 | #-------------------------- |
|
51 | 59 | # FileLinks tests |
|
52 | 60 | #-------------------------- |
|
53 | 61 | |
|
54 | 62 | def test_instantiation_FileLinks(): |
|
55 | 63 | """Test classes can be instantiated""" |
|
56 | 64 | fls = display.FileLinks('example') |
|
57 | 65 | |
|
58 | 66 | def test_warning_on_non_existant_path_FileLinks(): |
|
59 | 67 | """Calling _repr_html_ on non-existant files returns a warning""" |
|
60 | 68 | fls = display.FileLinks('example') |
|
61 | 69 | nt.assert_true(fls._repr_html_().startswith('Path (<tt>example</tt>)')) |
|
62 | 70 | |
|
63 | 71 | def test_existing_path_FileLinks(): |
|
64 | 72 | """ Calling _repr_html_ functions as expected on existing directory """ |
|
65 | 73 | td = mkdtemp() |
|
66 | 74 | tf1 = NamedTemporaryFile(dir=td) |
|
67 | 75 | tf2 = NamedTemporaryFile(dir=td) |
|
68 | 76 | fl = display.FileLinks(td) |
|
69 | 77 | actual = fl._repr_html_() |
|
70 | 78 | actual = actual.split('\n') |
|
71 | 79 | actual.sort() |
|
72 | 80 | expected = ["<a href='files/%s' target='_blank'>%s</a><br>" % (tf2.name,tf2.name), |
|
73 | 81 | "<a href='files/%s' target='_blank'>%s</a><br>" % (tf1.name,tf1.name)] |
|
74 | 82 | expected.sort() |
|
75 | 83 | # We compare the sorted list of links here as that's more reliable |
|
76 | 84 | nt.assert_equal(actual,expected) |
|
77 | 85 | |
|
86 | def test_existing_path_FileLinks_repr(): | |
|
87 | """ Calling repr() functions as expected on existing directory """ | |
|
88 | td = mkdtemp() | |
|
89 | tf1 = NamedTemporaryFile(dir=td) | |
|
90 | tf2 = NamedTemporaryFile(dir=td) | |
|
91 | fl = display.FileLinks(td) | |
|
92 | actual = repr(fl) | |
|
93 | actual = actual.split('\n') | |
|
94 | actual.sort() | |
|
95 | expected = [tf1.name,tf2.name] | |
|
96 | expected.sort() | |
|
97 | # We compare the sorted list of links here as that's more reliable | |
|
98 | nt.assert_equal(actual,expected) | |
|
99 | ||
|
78 | 100 | #-------------------------- |
|
79 | 101 | # DirectoryLink tests |
|
80 | 102 | #-------------------------- |
|
81 | 103 | |
|
82 | 104 | def test_instantiation_DirectoryLink(): |
|
83 | 105 | """Test classes can be instantiated""" |
|
84 | 106 | dl = display.DirectoryLink('example') |
|
85 | 107 | |
|
86 | 108 | def test_warning_on_non_existant_path_DirectoryLink(): |
|
87 | 109 | """Calling _repr_html_ on non-existant files returns a warning""" |
|
88 | 110 | dl = display.DirectoryLink('example') |
|
89 | 111 | nt.assert_true(dl._repr_html_().startswith('Path (<tt>example</tt>)')) |
|
90 | 112 | |
|
91 | 113 | def test_existing_path_FileLinks(): |
|
92 | 114 | """ Calling _repr_html_ functions as expected on existing directory """ |
|
93 | 115 | td = mkdtemp() |
|
94 | 116 | dl = display.DirectoryLink(td) |
|
95 | 117 | actual = dl._repr_html_() |
|
96 | 118 | expected = "<a href='files/%s' target='_blank'>%s</a><br>" % (td,td) |
|
97 | 119 | nt.assert_equal(actual,expected) |
General Comments 0
You need to be logged in to leave comments.
Login now