From a1e161c183edb29d70a6b4f16ccf64161b7efc7e 2014-12-09 01:44:32 From: Doug Blank Date: 2014-12-09 01:44:32 Subject: [PATCH] recursive==False uses next(iter) for PY3 compatability; added tests to make sure it doesn't recurse --- diff --git a/IPython/lib/display.py b/IPython/lib/display.py index 812b2fd..f65ee41 100644 --- a/IPython/lib/display.py +++ b/IPython/lib/display.py @@ -524,7 +524,7 @@ class FileLinks(FileLink): if self.recursive: walked_dir = list(walk(self.path)) else: - walked_dir = [walk(self.path).next()] + walked_dir = [next(walk(self.path))] walked_dir.sort() for dirname, subdirs, fnames in walked_dir: result_lines += self.notebook_display_formatter(dirname, fnames, self.included_suffixes) @@ -537,7 +537,7 @@ class FileLinks(FileLink): if self.recursive: walked_dir = list(walk(self.path)) else: - walked_dir = [walk(self.path).next()] + walked_dir = [next(walk(self.path))] walked_dir.sort() for dirname, subdirs, fnames in walked_dir: result_lines += self.terminal_display_formatter(dirname, fnames, self.included_suffixes) diff --git a/IPython/lib/tests/test_display.py b/IPython/lib/tests/test_display.py index 3223482..43fb66e 100644 --- a/IPython/lib/tests/test_display.py +++ b/IPython/lib/tests/test_display.py @@ -156,7 +156,23 @@ def test_error_on_file_to_FileLinks(): tf1 = NamedTemporaryFile(dir=td) nt.assert_raises(ValueError,display.FileLinks,tf1.name) +def test_recursive_FileLinks(): + """FileLinks: Does not recurse when recursive=False + """ + td = mkdtemp() + tf = NamedTemporaryFile(dir=td) + subtd = mkdtemp(dir=td) + subtf = NamedTemporaryFile(dir=subtd) + fl = display.FileLinks(td) + actual = str(fl) + actual = actual.split('\n') + nt.assert_equal(len(actual), 4, actual) + fl = display.FileLinks(td, recursive=False) + actual = str(fl) + actual = actual.split('\n') + nt.assert_equal(len(actual), 2, actual) + @skipif_not_numpy def test_audio_from_file(): path = pjoin(dirname(__file__), 'test.wav') - display.Audio(filename=path) \ No newline at end of file + display.Audio(filename=path)