diff --git a/.travis_dependencies.sh b/.travis_dependencies.sh index d25d75861d..ded23b350b 100644 --- a/.travis_dependencies.sh +++ b/.travis_dependencies.sh @@ -11,7 +11,7 @@ conda_create () conda update -q conda conda config --add channels pypi conda info -a - deps='pip numpy scipy nose coverage scikit-learn!=0.19.0 matplotlib==2.0 numba' + deps='pip numpy scipy nose coverage scikit-learn!=0.19.0 matplotlib numba' conda create -q -n $ENV_NAME "python=$TRAVIS_PYTHON_VERSION" $deps conda update --all diff --git a/appveyor.yml b/appveyor.yml index 38e109cd2f..fc2ffd3c1e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -8,7 +8,7 @@ environment: MINICONDA: C:\Miniconda cache: - - "%MINICONDA%\\envs" + - "%MINICONDA%\\envs -> appveyor.yml" init: - "ECHO %PYTHON_VERSION% %MINICONDA%" @@ -18,8 +18,8 @@ install: - conda config --set always_yes yes --set changeps1 no - conda update -q conda - conda info -a - - "IF NOT EXIST %MINICONDA%\\envs\\test-environment conda create -q -n test-environment python=%PYTHON_VERSION% numpy scipy nose coverage scikit-learn!=0.19.0 matplotlib==2.0 numba" - - activate test-environment + - "IF NOT EXIST %MINICONDA%\\envs\\test-environment-%PYTHON_VERSION% conda create -q -n test-environment-%PYTHON_VERSION% python=%PYTHON_VERSION% numpy scipy nose coverage scikit-learn!=0.19.0 numba" + - "activate test-environment-%PYTHON_VERSION%" - conda install -c conda-forge ffmpeg - pip install -e .[tests] diff --git a/setup.py b/setup.py index 9b3beb8f22..65550fe814 100644 --- a/setup.py +++ b/setup.py @@ -45,7 +45,7 @@ 'matplotlib >= 2.0.0', 'sphinxcontrib-versioning >= 2.2.1', 'sphinx-gallery'], - 'tests': ['matplotlib == 2.0'], + 'tests': ['matplotlib >= 2.1'], 'display': ['matplotlib >= 1.5'], } ) diff --git a/tests/baseline_images/test_display/time_scales_auto.png b/tests/baseline_images/test_display/time_scales_auto.png index 8fb342b579..b56d181d3e 100644 Binary files a/tests/baseline_images/test_display/time_scales_auto.png and b/tests/baseline_images/test_display/time_scales_auto.png differ diff --git a/tests/mpl_ic.py b/tests/mpl_ic.py index 9a899563b7..1fe5a5abef 100644 --- a/tests/mpl_ic.py +++ b/tests/mpl_ic.py @@ -23,13 +23,13 @@ from matplotlib import ticker from matplotlib import pyplot as plt from matplotlib import ft2font -from matplotlib.testing.noseclasses import KnownFailureTest, \ - KnownFailureDidNotFailTest, ImageComparisonFailure +from matplotlib.testing.noseclasses import KnownFailure +from matplotlib.testing.exceptions import ImageComparisonFailure from matplotlib.testing.compare import comparable_formats, compare_images, \ make_test_filename -def knownfailureif(fail_condition, msg=None, known_exception_class=None ): +def knownfailureif(fail_condition, msg=None, known_exception_class=None): """ Assume a will fail if *fail_condition* is True. *fail_condition* @@ -44,10 +44,12 @@ def knownfailureif(fail_condition, msg=None, known_exception_class=None ): # based on numpy.testing.dec.knownfailureif if msg is None: msg = 'Test known to fail' + def known_fail_decorator(f): # Local import to avoid a hard nose dependency and only incur the # import time overhead at actual test-time. import nose + def failer(*args, **kwargs): try: # Always run the test (to generate images). @@ -55,11 +57,15 @@ def failer(*args, **kwargs): except Exception as err: if fail_condition: if known_exception_class is not None: - if not isinstance(err,known_exception_class): + if not isinstance(err, known_exception_class): # This is not the expected exception raise - # (Keep the next ultra-long comment so in shows in console.) - raise KnownFailureTest(msg) # An error here when running nose means that you don't have the matplotlib.testing.noseclasses:KnownFailure plugin in use. + # (Keep the next ultra-long comment so in shows in + # console.) + # An error here when running nose means that you don't have + # the matplotlib.testing.noseclasses:KnownFailure plugin in + # use. + raise KnownFailure(msg) else: raise if fail_condition and fail_condition != 'indeterminate': @@ -81,6 +87,10 @@ def _do_cleanup(original_units_registry): warnings.resetwarnings() # reset any warning filters set in tests +class KnownFailureDidNotFailTest(KnownFailure): + pass + + class CleanupTest(object): @classmethod def setup_class(cls): @@ -130,6 +140,7 @@ def check_freetype_version(ver): return found >= ver[0] and found <= ver[1] + class ImageComparisonTest(CleanupTest): @classmethod def setup_class(cls): @@ -157,18 +168,24 @@ def test(self): for fignum, baseline in zip(plt.get_fignums(), self._baseline_images): for extension in self._extensions: - will_fail = not extension in comparable_formats() + will_fail = extension not in comparable_formats() if will_fail: - fail_msg = 'Cannot compare %s files on this system' % extension + fail_msg = ('Cannot compare %s files on this system' % + extension) else: fail_msg = 'No failure expected' - orig_expected_fname = os.path.join(baseline_dir, baseline) + '.' + extension - if extension == 'eps' and not os.path.exists(orig_expected_fname): - orig_expected_fname = os.path.join(baseline_dir, baseline) + '.pdf' + orig_expected_fname = ( + os.path.join(baseline_dir, baseline) + '.' + extension) + if (extension == 'eps' and + not os.path.exists(orig_expected_fname)): + orig_expected_fname = ( + os.path.join(baseline_dir, baseline) + '.pdf') expected_fname = make_test_filename(os.path.join( - result_dir, os.path.basename(orig_expected_fname)), 'expected') - actual_fname = os.path.join(result_dir, baseline) + '.' + extension + result_dir, + os.path.basename(orig_expected_fname)), 'expected') + actual_fname = ( + os.path.join(result_dir, baseline) + '.' + extension) if os.path.exists(orig_expected_fname): shutil.copyfile(orig_expected_fname, expected_fname) else: @@ -198,17 +215,20 @@ def do_test(): if err: raise ImageComparisonFailure( - 'images not close: %(actual)s vs. %(expected)s ' - '(RMS %(rms).3f)'%err) + 'images not close: %(actual)s vs. %(expected)s' + ' (RMS %(rms).3f)' % err) except ImageComparisonFailure: if not check_freetype_version(self._freetype_version): - raise KnownFailureTest( - "Mismatched version of freetype. Test requires '%s', you have '%s'" % - (self._freetype_version, ft2font.__freetype_version__)) + raise KnownFailure( + "Mismatched version of freetype. Test " + "requires '%s', you have '%s'" % + (self._freetype_version, + ft2font.__freetype_version__)) raise yield (do_test,) + def image_comparison(baseline_images=None, extensions=None, tol=13, freetype_version=None, remove_text=False, savefig_kwarg=None): @@ -258,7 +278,7 @@ def image_comparison(baseline_images=None, extensions=None, tol=13, extensions = ['png', 'pdf', 'svg'] if savefig_kwarg is None: - #default no kwargs to savefig + # default no kwargs to savefig savefig_kwarg = dict() def compare_images_decorator(func): @@ -290,20 +310,22 @@ def compare_images_decorator(func): return new_class return compare_images_decorator + def _image_directories(func): """ Compute the baseline and result image directories for testing *func*. Create the result directory if it doesn't exist. """ module_name = func.__module__ -# mods = module_name.split('.') -# mods.pop(0) # <- will be the name of the package being tested (in - # most cases "matplotlib") -# assert mods.pop(0) == 'tests' -# subdir = os.path.join(*mods) + # mods = module_name.split('.') + # mods.pop(0) # <- will be the name of the package being tested (in + # most cases "matplotlib") + # assert mods.pop(0) == 'tests' + # subdir = os.path.join(*mods) subdir = module_name import imp + def find_dotted_module(module_name, path=None): """A version of imp which can handle dots in the module name""" res = None diff --git a/tests/test_display.py b/tests/test_display.py index 74a513cfc2..26641fe910 100644 --- a/tests/test_display.py +++ b/tests/test_display.py @@ -244,7 +244,7 @@ def test_time_scales_auto(): # sr = 22050, hop_length = 512, S.shape[1] = 198 # 197 * 512 / 22050 ~= 4.6s - plt.figure() + plt.figure(figsize=(10, 10)) plt.subplot(4, 1, 1) # sr * 10 -> ms librosa.display.specshow(S_abs, sr=10 * sr, x_axis='time')