Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5293b22

Browse files
committed
Merge pull request matplotlib#3154 from WeatherGod/mplot3d/whitelist_tests
whitelist mpl_toolkits tests
2 parents 8337baf + 7ed3c2d commit 5293b22

File tree

5 files changed

+114
-2
lines changed

5 files changed

+114
-2
lines changed

lib/matplotlib/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,6 +1356,7 @@ def tk_window_focus():
13561356
'matplotlib.tests.test_tightlayout',
13571357
'matplotlib.tests.test_transforms',
13581358
'matplotlib.tests.test_triangulation',
1359+
'mpl_toolkits.tests.test_mplot3d',
13591360
]
13601361

13611362

lib/mpl_toolkits/tests/__init__.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
from __future__ import (absolute_import, division, print_function,
2+
unicode_literals)
3+
4+
import six
5+
6+
import difflib
7+
import os
8+
9+
from matplotlib import rcParams, rcdefaults, use
10+
11+
12+
_multiprocess_can_split_ = True
13+
14+
15+
# Check that the test directories exist
16+
if not os.path.exists(os.path.join(
17+
os.path.dirname(__file__), 'baseline_images')):
18+
raise IOError(
19+
'The baseline image directory does not exist. '
20+
'This is most likely because the test data is not installed. '
21+
'You may need to install matplotlib from source to get the '
22+
'test data.')
23+
24+
25+
def setup():
26+
# The baseline images are created in this locale, so we should use
27+
# it during all of the tests.
28+
import locale
29+
import warnings
30+
from matplotlib.backends import backend_agg, backend_pdf, backend_svg
31+
32+
try:
33+
locale.setlocale(locale.LC_ALL, str('en_US.UTF-8'))
34+
except locale.Error:
35+
try:
36+
locale.setlocale(locale.LC_ALL, str('English_United States.1252'))
37+
except locale.Error:
38+
warnings.warn(
39+
"Could not set locale to English/United States. "
40+
"Some date-related tests may fail")
41+
42+
use('Agg', warn=False) # use Agg backend for these tests
43+
44+
# These settings *must* be hardcoded for running the comparison
45+
# tests and are not necessarily the default values as specified in
46+
# rcsetup.py
47+
rcdefaults() # Start with all defaults
48+
rcParams['font.family'] = 'Bitstream Vera Sans'
49+
rcParams['text.hinting'] = False
50+
rcParams['text.hinting_factor'] = 8
51+
52+
# Clear the font caches. Otherwise, the hinting mode can travel
53+
# from one test to another.
54+
backend_agg.RendererAgg._fontd.clear()
55+
backend_pdf.RendererPdf.truetype_font_cache.clear()
56+
backend_svg.RendererSVG.fontd.clear()
57+
58+
59+
def assert_str_equal(reference_str, test_str,
60+
format_str=('String {str1} and {str2} do not '
61+
'match:\n{differences}')):
62+
"""
63+
Assert the two strings are equal. If not, fail and print their
64+
diffs using difflib.
65+
66+
"""
67+
if reference_str != test_str:
68+
diff = difflib.unified_diff(reference_str.splitlines(1),
69+
test_str.splitlines(1),
70+
'Reference', 'Test result',
71+
'', '', 0)
72+
raise ValueError(format_str.format(str1=reference_str,
73+
str2=test_str,
74+
differences=''.join(diff)))

setup.cfg.template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
#tests = True
2222
#sample_data = True
2323
#toolkits = True
24+
# Tests for the toolkits are only automatically installed
25+
# if the tests and toolkits packages are also getting installed.
26+
#toolkits_tests = auto
2427

2528
[gui_support]
2629
# Matplotlib supports multiple GUI toolkits, including Cocoa,

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
setupext.SampleData(),
8686
setupext.Toolkits(),
8787
setupext.Tests(),
88+
setupext.Toolkits_Tests(),
8889
'Optional backend extensions',
8990
# These backends are listed in order of preference, the first
9091
# being the most preferred. The first one that looks like it will

setupext.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,14 +450,15 @@ class OptionalPackage(SetupPackage):
450450
force = False
451451
config_category = "packages"
452452

453-
def get_config(self):
453+
@classmethod
454+
def get_config(cls):
454455
"""
455456
Look at `setup.cfg` and return one of ["auto", True, False] indicating
456457
if the package is at default state ("auto"), forced by the user (True)
457458
or opted-out (False).
458459
"""
459460
try:
460-
return config.getboolean(self.config_category, self.name)
461+
return config.getboolean(cls.config_category, cls.name)
461462
except:
462463
return "auto"
463464

@@ -681,6 +682,38 @@ def get_install_requires(self):
681682
requires += ['mock']
682683
return requires
683684

685+
class Toolkits_Tests(Tests):
686+
name = "toolkits_tests"
687+
688+
def check_requirements(self):
689+
conf = self.get_config()
690+
toolkits_conf = Toolkits.get_config()
691+
tests_conf = Tests.get_config()
692+
693+
if conf is True:
694+
Tests.force = True
695+
Toolkits.force = True
696+
elif conf == "auto" and not (toolkits_conf and tests_conf):
697+
# Only auto-install if both toolkits and tests are set
698+
# to be installed
699+
raise CheckFailed("toolkits_tests needs 'toolkits' and 'tests'")
700+
return ""
701+
702+
def get_packages(self):
703+
return [
704+
'mpl_toolkits.tests',
705+
]
706+
707+
def get_package_data(self):
708+
baseline_images = [
709+
'tests/baseline_images/%s/*' % x
710+
for x in os.listdir('lib/mpl_toolkits/tests/baseline_images')]
711+
712+
return {'mpl_toolkits': baseline_images}
713+
714+
def get_namespace_packages(self):
715+
return ['mpl_toolkits']
716+
684717

685718
class DelayedExtension(Extension, object):
686719
"""

0 commit comments

Comments
 (0)