diff --git a/IPython/lib/tests/test_display.py b/IPython/lib/tests/test_display.py
index dfcfa93..b16f412 100644
--- a/IPython/lib/tests/test_display.py
+++ b/IPython/lib/tests/test_display.py
@@ -13,6 +13,8 @@
# Imports
#-----------------------------------------------------------------------------
from __future__ import print_function
+from tempfile import NamedTemporaryFile, mkdtemp
+
# Third-party imports
import nose.tools as nt
@@ -37,19 +39,52 @@ def test_warning_on_non_existant_path_FileLink():
fl = display.FileLink('example.txt')
nt.assert_true(fl._repr_html_().startswith('Path (example.txt)'))
+def test_existing_path_FileLink():
+ """ Calling _repr_html_ functions as expected on existing filepath """
+ tf = NamedTemporaryFile()
+ fl = display.FileLink(tf.name)
+ actual = fl._repr_html_()
+ # Note: this is a bit awkward since tf.name has to be a full path
+ # for it to exist, but that won't happen in our applications. While
+ # in practice "files/" would be prepended to the href path, os.join
+ # doesn't do that if the second value is an absolute path. So, the
+ # expected here is slightly different than what we get in practice.
+ expected = "%s
" % (tf.name,tf.name)
+ nt.assert_equal(actual,expected)
+
#--------------------------
# FileLinks tests
#--------------------------
def test_instantiation_FileLinks():
"""Test classes can be instantiated"""
- fls = display.FileLinks(['example1.txt','example2.txt'])
+ fls = display.FileLinks('example')
def test_warning_on_non_existant_path_FileLinks():
"""Calling _repr_html_ on non-existant files returns a warning"""
fls = display.FileLinks('example')
nt.assert_true(fls._repr_html_().startswith('Path (example)'))
+def test_existing_path_FileLinks():
+ """ Calling _repr_html_ functions as expected on existing directory """
+ td = mkdtemp()
+ tf1 = NamedTemporaryFile(dir=td)
+ tf2 = NamedTemporaryFile(dir=td)
+ fl = display.FileLinks(td)
+ actual = fl._repr_html_()
+ actual = actual.split('\n')
+ actual.sort()
+ # Note: this is a bit awkward since tf.name has to be a full path
+ # for it to exist, but that won't happen in our applications. While
+ # in practice "files/" would be prepended to the href path, os.join
+ # doesn't do that if the second value is an absolute path. So, the
+ # expected here is slightly different than what we get in practice.
+ expected = ["%s
" % (tf2.name,tf2.name.split('/')[-1]),
+ "%s
" % (tf1.name,tf1.name.split('/')[-1])]
+ expected.sort()
+ # We compare the sorted list of links here as that's more reliable
+ nt.assert_equal(actual,expected)
+
#--------------------------
# DirectoryLink tests
#--------------------------
@@ -62,3 +97,16 @@ def test_warning_on_non_existant_path_DirectoryLink():
"""Calling _repr_html_ on non-existant files returns a warning"""
dl = display.DirectoryLink('example')
nt.assert_true(dl._repr_html_().startswith('Path (example)'))
+
+def test_existing_path_FileLinks():
+ """ Calling _repr_html_ functions as expected on existing directory """
+ td = mkdtemp()
+ dl = display.DirectoryLink(td)
+ actual = dl._repr_html_()
+ # Note: this is a bit awkward since tf.name has to be a full path
+ # for it to exist, but that won't happen in our applications. While
+ # in practice "files/" would be prepended to the href path, os.join
+ # doesn't do that if the second value is an absolute path. So, the
+ # expected here is slightly different than what we get in practice.
+ expected = "%s
" % (td,td)
+ nt.assert_equal(actual,expected)