From d06f35623aea61828da682ed0740e282482885e6 Mon Sep 17 00:00:00 2001 From: Eddie Hebert Date: Mon, 6 Jan 2014 12:51:20 -0500 Subject: [PATCH] MAINT: Make walk usage in example tests compatible with Python 3 The rename of walk is not provided by six, so check the import error via an exception. Also, callback behavior slightly changes between the two versions, so instead iterate over the walked files and call what was formerly a callback, directly as a function. --- tests/test_examples.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/test_examples.py b/tests/test_examples.py index 1bbbd4ab..0ae919a6 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -21,15 +21,22 @@ import matplotlib matplotlib.use('Agg') -from os import path import os +from os import path + +try: + from path import walk +except ImportError: + # Assume Python 3 + from os import walk + import fnmatch import imp def test_examples(): os.chdir(example_dir()) - for fname in all_matching_files('.', '*.py'): + for fname in all_matching_files(example_dir(), '*.py'): yield check_example, fname @@ -40,7 +47,8 @@ def all_matching_files(d, pattern): fls.extend(nfiles) files = [] - path.walk(d, addfiles, files) + for dirpath, dirnames, filenames in walk(d): + addfiles(files, dirpath, filenames) return files