@@ -67,6 +67,48 @@ def test_context():
67
67
# Check that this value is reset after the exiting the context.
68
68
assert mpl .rcParams [PARAM ] == 'gray'
69
69
70
+ def test_context_dict ():
71
+ ORIGINAL = 'gray'
72
+ VALUE_OTHER = 'blue'
73
+ mpl .rcParams [PARAM ] = ORIGINAL
74
+ with style .context ({PARAM : VALUE_OTHER }):
75
+ assert mpl .rcParams [PARAM ] == VALUE_OTHER
76
+ assert mpl .rcParams [PARAM ] == ORIGINAL
77
+
78
+ def test_context_dictname1 ():
79
+ # Test dict after style name where dict modifies the same parameter.
80
+ ORIGINAL = 'gray'
81
+ VALUE_OTHER = 'blue'
82
+ mpl .rcParams [PARAM ] = ORIGINAL
83
+ with temp_style ('test' , DUMMY_SETTINGS ):
84
+ with style .context (['test' , {PARAM : VALUE_OTHER }]):
85
+ assert mpl .rcParams [PARAM ] == VALUE_OTHER
86
+ assert mpl .rcParams [PARAM ] == ORIGINAL
87
+
88
+ def test_context_dictname2 ():
89
+ # Test dict before style name where dict modifies the same parameter.
90
+ ORIGINAL = 'gray'
91
+ VALUE_OTHER = 'blue'
92
+ mpl .rcParams [PARAM ] = ORIGINAL
93
+ with temp_style ('test' , DUMMY_SETTINGS ):
94
+ with style .context ([{PARAM : VALUE_OTHER }, 'test' ]):
95
+ assert mpl .rcParams [PARAM ] == VALUE
96
+ assert mpl .rcParams [PARAM ] == ORIGINAL
97
+
98
+ def test_context_dictname3 ():
99
+ # Test dict after style name where dict modifies the a different parameter.
100
+ ORIGINAL = 'gray'
101
+ PARAM_OTHER = 'text.usetex'
102
+ VALUE_OTHER = True
103
+ d = {PARAM_OTHER : VALUE_OTHER }
104
+ mpl .rcParams [PARAM ] = ORIGINAL
105
+ mpl .rcParams [PARAM_OTHER ] = (not VALUE_OTHER )
106
+ with temp_style ('test' , DUMMY_SETTINGS ):
107
+ with style .context (['test' , d ]):
108
+ assert mpl .rcParams [PARAM ] == VALUE
109
+ assert mpl .rcParams [PARAM_OTHER ] == VALUE_OTHER
110
+ assert mpl .rcParams [PARAM ] == ORIGINAL
111
+ assert mpl .rcParams [PARAM_OTHER ] == (not VALUE_OTHER )
70
112
71
113
if __name__ == '__main__' :
72
114
from numpy import testing
0 commit comments