Skip to content

Commit

Permalink
Merge pull request #680 from librosa/mpl-test-2.1
Browse files Browse the repository at this point in the history
updated display tests to support mpl2.1
  • Loading branch information
bmcfee committed Feb 21, 2018
2 parents 7fe6cd0 + 68cbea3 commit f8817ce
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .travis_dependencies.sh
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions appveyor.yml
Expand Up @@ -8,7 +8,7 @@ environment:
MINICONDA: C:\Miniconda

cache:
- "%MINICONDA%\\envs"
- "%MINICONDA%\\envs -> appveyor.yml"

init:
- "ECHO %PYTHON_VERSION% %MINICONDA%"
Expand All @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -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'],
}
)
Binary file modified tests/baseline_images/test_display/time_scales_auto.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 46 additions & 24 deletions tests/mpl_ic.py
Expand Up @@ -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*
Expand All @@ -44,22 +44,28 @@ 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).
result = f(*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':
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_display.py
Expand Up @@ -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')
Expand Down

0 comments on commit f8817ce

Please sign in to comment.