|
5 | 5 | from contextlib import contextmanager |
6 | 6 |
|
7 | 7 | from matplotlib.cbook import is_string_like, iterable |
| 8 | +from matplotlib import rcParams, rcdefaults, use |
8 | 9 |
|
9 | 10 |
|
10 | 11 | def _is_list_like(obj): |
@@ -70,3 +71,37 @@ def assert_produces_warning(expected_warning=Warning, filter_level="always", |
70 | 71 | % expected_warning.__name__) |
71 | 72 | assert not extra_warnings, ("Caused unexpected warning(s): %r." |
72 | 73 | % extra_warnings) |
| 74 | + |
| 75 | + |
| 76 | +def setup(): |
| 77 | + # The baseline images are created in this locale, so we should use |
| 78 | + # it during all of the tests. |
| 79 | + import locale |
| 80 | + import warnings |
| 81 | + from matplotlib.backends import backend_agg, backend_pdf, backend_svg |
| 82 | + |
| 83 | + try: |
| 84 | + locale.setlocale(locale.LC_ALL, str('en_US.UTF-8')) |
| 85 | + except locale.Error: |
| 86 | + try: |
| 87 | + locale.setlocale(locale.LC_ALL, str('English_United States.1252')) |
| 88 | + except locale.Error: |
| 89 | + warnings.warn( |
| 90 | + "Could not set locale to English/United States. " |
| 91 | + "Some date-related tests may fail") |
| 92 | + |
| 93 | + use('Agg', warn=False) # use Agg backend for these tests |
| 94 | + |
| 95 | + # These settings *must* be hardcoded for running the comparison |
| 96 | + # tests and are not necessarily the default values as specified in |
| 97 | + # rcsetup.py |
| 98 | + rcdefaults() # Start with all defaults |
| 99 | + rcParams['font.family'] = 'Bitstream Vera Sans' |
| 100 | + rcParams['text.hinting'] = False |
| 101 | + rcParams['text.hinting_factor'] = 8 |
| 102 | + |
| 103 | + # Clear the font caches. Otherwise, the hinting mode can travel |
| 104 | + # from one test to another. |
| 105 | + backend_agg.RendererAgg._fontd.clear() |
| 106 | + backend_pdf.RendererPdf.truetype_font_cache.clear() |
| 107 | + backend_svg.RendererSVG.fontd.clear() |
0 commit comments