-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Update matplotlibrc.template #10531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update matplotlibrc.template #10531
Changes from all commits
675e6b5
5d8284e
facd97a
dc17fe2
b7b3f32
e93c66a
a67b9d0
9964e8e
5cd5b29
7d08d3d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -422,3 +422,64 @@ def test_rcparams_reset_after_fail(): | |
pass | ||
|
||
assert mpl.rcParams['text.usetex'] is False | ||
|
||
|
||
def test_if_rctemplate_is_up_to_date(): | ||
# This tests if the matplotlibrc.template file | ||
# contains all valid rcParams. | ||
dep1 = mpl._all_deprecated | ||
dep2 = mpl._deprecated_set | ||
deprecated = list(dep1.union(dep2)) | ||
#print(deprecated) | ||
path_to_rc = mpl.matplotlib_fname() | ||
with open(path_to_rc, "r") as f: | ||
rclines = f.readlines() | ||
missing = {} | ||
for k,v in mpl.defaultParams.items(): | ||
if k[0] == "_": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe join:
|
||
continue | ||
if k in deprecated: | ||
continue | ||
if "verbose" in k: | ||
continue | ||
found = False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This (and following lines) can be written more compact:
Note, that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct. I think any better solution here would eventually lead to writing one single test and match the parsed file agains the defaultParams. Depends on if people think this should be done or not. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a big fan of "incrementally better", so I don't want to enforce a full parsing test. Your partial test is already a big improvement. Maybe you could add a short comment to clarify that this test is not expected to be 100%. And of course, use the compact form 😃. |
||
for line in rclines: | ||
if k in line: | ||
found = True | ||
if not found: | ||
missing.update({k:v}) | ||
if missing: | ||
raise ValueError("The following params are missing " + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Both should provide a reasonably informative error message. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe I'm There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pytest is pretty good about reporting. Consider the following:
So then running it:
It's pretty clear what's in the dictionary that should be empty |
||
"in the matplotlibrc.template file: {}" | ||
.format(missing.items())) | ||
|
||
|
||
def test_if_rctemplate_would_be_valid(tmpdir): | ||
# This tests if the matplotlibrc.template file would result in a valid | ||
# rc file if all lines are uncommented. | ||
path_to_rc = mpl.matplotlib_fname() | ||
with open(path_to_rc, "r") as f: | ||
rclines = f.readlines() | ||
newlines = [] | ||
for line in rclines: | ||
if line[0] == "#": | ||
newline = line[1:] | ||
else: | ||
newline = line | ||
if "$TEMPLATE_BACKEND" in newline: | ||
newline = "backend : Agg" | ||
if "datapath" in newline: | ||
newline = "" | ||
newlines.append(newline) | ||
d = tmpdir.mkdir('test1') | ||
fname = str(d.join('testrcvalid.temp')) | ||
with open(fname, "w") as f: | ||
f.writelines(newlines) | ||
with pytest.warns(None) as record: | ||
dic = mpl.rc_params_from_file(fname, | ||
fail_on_error=True, | ||
use_default_template=False) | ||
assert len(record) == 0 | ||
#d1 = set(dic.keys()) | ||
#d2 = set(matplotlib.defaultParams.keys()) | ||
#print(d2-d1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For better readability, I'd slightly prefer
for key, val
orfor name, val
because the for loop is quite long.