Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4846dea

Browse filesBrowse files
tacaswellQuLogic
authored andcommitted
Merge pull request #7620 from alanbernstein/add-warning-context
ENH: Add warning context to style files
1 parent 3ce3835 commit 4846dea
Copy full SHA for 4846dea

File tree

Expand file treeCollapse file tree

2 files changed

+23
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+23
-2
lines changed

‎lib/matplotlib/style/core.py

Copy file name to clipboardExpand all lines: lib/matplotlib/style/core.py
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,14 @@ def read_style_directory(style_dir):
188188
"""Return dictionary of styles defined in `style_dir`."""
189189
styles = dict()
190190
for path, name in iter_style_files(style_dir):
191-
styles[name] = rc_params_from_file(path, use_default_template=False)
191+
with warnings.catch_warnings(record=True) as warns:
192+
styles[name] = rc_params_from_file(path,
193+
use_default_template=False)
194+
195+
for w in warns:
196+
message = 'In %s: %s' % (path, w.message)
197+
warnings.warn(message)
198+
192199
return styles
193200

194201

‎lib/matplotlib/tests/test_style.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_style.py
+15-1Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import shutil
66
import tempfile
7+
import warnings
78
from collections import OrderedDict
89
from contextlib import contextmanager
910

@@ -24,7 +25,8 @@
2425
@contextmanager
2526
def temp_style(style_name, settings=None):
2627
"""Context manager to create a style sheet in a temporary directory."""
27-
settings = DUMMY_SETTINGS
28+
if not settings:
29+
settings = DUMMY_SETTINGS
2830
temp_file = '%s.%s' % (style_name, STYLE_EXTENSION)
2931

3032
# Write style settings to file in the temp directory.
@@ -44,6 +46,18 @@ def temp_style(style_name, settings=None):
4446
style.reload_library()
4547

4648

49+
def test_deprecated_rc_warning_includes_filename():
50+
SETTINGS = {'axes.color_cycle': 'ffffff'}
51+
basename = 'color_cycle'
52+
with warnings.catch_warnings(record=True) as warns:
53+
with temp_style(basename, SETTINGS):
54+
# style.reload_library() in temp_style() triggers the warning
55+
pass
56+
57+
for w in warns:
58+
assert basename in str(w.message)
59+
60+
4761
def test_available():
4862
with temp_style('_test_', DUMMY_SETTINGS):
4963
assert '_test_' in style.available

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.