Skip to content

Commit

Permalink
Merge pull request #3154 from WeatherGod/mplot3d/whitelist_tests
Browse files Browse the repository at this point in the history
whitelist mpl_toolkits tests
  • Loading branch information
tacaswell committed Jul 12, 2014
2 parents 8337baf + 7ed3c2d commit 5293b22
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/matplotlib/__init__.py
Expand Up @@ -1356,6 +1356,7 @@ def tk_window_focus():
'matplotlib.tests.test_tightlayout',
'matplotlib.tests.test_transforms',
'matplotlib.tests.test_triangulation',
'mpl_toolkits.tests.test_mplot3d',
]


Expand Down
74 changes: 74 additions & 0 deletions lib/mpl_toolkits/tests/__init__.py
@@ -0,0 +1,74 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)

import six

import difflib
import os

from matplotlib import rcParams, rcdefaults, use


_multiprocess_can_split_ = True


# Check that the test directories exist
if not os.path.exists(os.path.join(
os.path.dirname(__file__), 'baseline_images')):
raise IOError(
'The baseline image directory does not exist. '
'This is most likely because the test data is not installed. '
'You may need to install matplotlib from source to get the '
'test data.')


def setup():
# The baseline images are created in this locale, so we should use
# it during all of the tests.
import locale
import warnings
from matplotlib.backends import backend_agg, backend_pdf, backend_svg

try:
locale.setlocale(locale.LC_ALL, str('en_US.UTF-8'))
except locale.Error:
try:
locale.setlocale(locale.LC_ALL, str('English_United States.1252'))
except locale.Error:
warnings.warn(
"Could not set locale to English/United States. "
"Some date-related tests may fail")

use('Agg', warn=False) # use Agg backend for these tests

# These settings *must* be hardcoded for running the comparison
# tests and are not necessarily the default values as specified in
# rcsetup.py
rcdefaults() # Start with all defaults
rcParams['font.family'] = 'Bitstream Vera Sans'
rcParams['text.hinting'] = False
rcParams['text.hinting_factor'] = 8

# Clear the font caches. Otherwise, the hinting mode can travel
# from one test to another.
backend_agg.RendererAgg._fontd.clear()
backend_pdf.RendererPdf.truetype_font_cache.clear()
backend_svg.RendererSVG.fontd.clear()


def assert_str_equal(reference_str, test_str,
format_str=('String {str1} and {str2} do not '
'match:\n{differences}')):
"""
Assert the two strings are equal. If not, fail and print their
diffs using difflib.
"""
if reference_str != test_str:
diff = difflib.unified_diff(reference_str.splitlines(1),
test_str.splitlines(1),
'Reference', 'Test result',
'', '', 0)
raise ValueError(format_str.format(str1=reference_str,
str2=test_str,
differences=''.join(diff)))
3 changes: 3 additions & 0 deletions setup.cfg.template
Expand Up @@ -21,6 +21,9 @@
#tests = True
#sample_data = True
#toolkits = True
# Tests for the toolkits are only automatically installed
# if the tests and toolkits packages are also getting installed.
#toolkits_tests = auto

[gui_support]
# Matplotlib supports multiple GUI toolkits, including Cocoa,
Expand Down
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -85,6 +85,7 @@
setupext.SampleData(),
setupext.Toolkits(),
setupext.Tests(),
setupext.Toolkits_Tests(),
'Optional backend extensions',
# These backends are listed in order of preference, the first
# being the most preferred. The first one that looks like it will
Expand Down
37 changes: 35 additions & 2 deletions setupext.py
Expand Up @@ -450,14 +450,15 @@ class OptionalPackage(SetupPackage):
force = False
config_category = "packages"

def get_config(self):
@classmethod
def get_config(cls):
"""
Look at `setup.cfg` and return one of ["auto", True, False] indicating
if the package is at default state ("auto"), forced by the user (True)
or opted-out (False).
"""
try:
return config.getboolean(self.config_category, self.name)
return config.getboolean(cls.config_category, cls.name)
except:
return "auto"

Expand Down Expand Up @@ -681,6 +682,38 @@ def get_install_requires(self):
requires += ['mock']
return requires

class Toolkits_Tests(Tests):
name = "toolkits_tests"

def check_requirements(self):
conf = self.get_config()
toolkits_conf = Toolkits.get_config()
tests_conf = Tests.get_config()

if conf is True:
Tests.force = True
Toolkits.force = True
elif conf == "auto" and not (toolkits_conf and tests_conf):
# Only auto-install if both toolkits and tests are set
# to be installed
raise CheckFailed("toolkits_tests needs 'toolkits' and 'tests'")
return ""

def get_packages(self):
return [
'mpl_toolkits.tests',
]

def get_package_data(self):
baseline_images = [
'tests/baseline_images/%s/*' % x
for x in os.listdir('lib/mpl_toolkits/tests/baseline_images')]

return {'mpl_toolkits': baseline_images}

def get_namespace_packages(self):
return ['mpl_toolkits']


class DelayedExtension(Extension, object):
"""
Expand Down

0 comments on commit 5293b22

Please sign in to comment.