10000 Add rcfile function (which loads rc params from a given file). by memmett · Pull Request #861 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Add rcfile function (which loads rc params from a given file). #861

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

Merged
merged 13 commits into from
Aug 19, 2012
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test_rcparams.py to test rc_file and rc_context.
  • Loading branch information
memmett committed Aug 12, 2012
commit a54325e50ab6e4343af2d4123f4da7ef00193c87
1 change: 1 addition & 0 deletions lib/matplotlib/tests/mpl.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lines.linewidth: 33
35 changes: 35 additions & 0 deletions lib/matplotlib/tests/test_rcparams.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import os

import matplotlib as mpl
mpl.rc('text', usetex=False)
mpl.rc('lines', linewidth=22)

fname = os.path.abspath(os.path.dirname(__file__)) + os.sep + 'mpl.rc'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is fine, but I don't believe the abspath is necessary. Normally:

os.path.join(os.path.dirname(__file__), 'mpl.rc')

Would suffice.


def test_rcparams():

usetex = mpl.rcParams['text.usetex']
linewidth = mpl.rcParams['lines.linewidth']

# test context given dictionary
with mpl.rc_context(rc={'text.usetex': not usetex}):
assert mpl.rcParams['text.usetex'] == (not usetex)
assert mpl.rcParams['text.usetex'] == usetex

# test context given filename (mpl.rc sets linewdith to 33)
with mpl.rc_context(fname=fname):
assert mpl.rcParams['lines.linewidth'] == 33
assert mpl.rcParams['lines.linewidth'] == linewidth

# test context given filename and dictionary
with mpl.rc_context(fname=fname, rc={'lines.linewidth': 44}):
assert mpl.rcParams['lines.linewidth'] == 44
assert mpl.rcParams['lines.linewidth'] == linewidth

# test rc_file
mpl.rc_file(fname)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will have a global effect on the tests and will need to be undone at the end of execution. Perhaps:

try:
    mpl.rc_file(fname)
    assert mpl.rcParams['lines.linewidth'] == 33
finally:
    linewidth = mpl.rcParams['lines.linewidth']

assert mpl.rcParams['lines.linewidth'] == 33


if __name__ == '__main__':
test_rcparams()
0