Skip to content

Commit 31ec92b

Browse files
committed
change tests to thread local changes
1 parent 8700d1f commit 31ec92b

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

ultraplot/tests/test_config.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,27 @@ def test_wrong_keyword_reset():
88
"""
99
The context should reset after a failed attempt.
1010
"""
11-
# Init context
12-
uplt.rc.context()
13-
config = uplt.rc
14-
# Set a wrong key
15-
with pytest.raises(KeyError):
16-
config._get_item_dicts("non_existing_key", "non_existing_value")
17-
# Set a known good value
18-
config._get_item_dicts("coastcolor", "black")
19-
# Confirm we can still plot
20-
fig, ax = uplt.subplots(proj="cyl")
21-
ax.format(coastcolor="black")
22-
fig.canvas.draw()
11+
# Use context manager for temporary rc changes
12+
# Use context manager with direct value setting
13+
with uplt.rc.context(coastcolor="black"):
14+
# Set a wrong key
15+
with pytest.raises(KeyError):
16+
uplt.rc._get_item_dicts("non_existing_key", "non_existing_value")
17+
# Confirm we can still plot
18+
fig, ax = uplt.subplots(proj="cyl")
19+
ax.format(coastcolor="black")
20+
fig.canvas.draw()
2321

2422

2523
def test_cycle_in_rc_file(tmp_path):
2624
"""
2725
Test that loading an rc file correctly overwrites the cycle setting.
2826
"""
27+
rc = uplt.config.Configurator()
2928
rc_content = "cycle: colorblind"
3029
rc_file = tmp_path / "test.rc"
3130
rc_file.write_text(rc_content)
32-
33-
# Load the file directly. This should overwrite any existing settings.
34-
uplt.rc.load(str(rc_file))
35-
31+
rc.load(str(rc_file))
3632
assert uplt.rc["cycle"] == "colorblind"
3733

3834

@@ -208,6 +204,8 @@ def test_cycle_rc_setting(cycle, raises_error):
208204
"""
209205
if raises_error:
210206
with pytest.raises(ValueError):
211-
uplt.rc["cycle"] = cycle
207+
with uplt.rc.context(cycle=cycle):
208+
pass
212209
else:
213-
uplt.rc["cycle"] = cycle
210+
with uplt.rc.context(cycle=cycle):
211+
pass

0 commit comments

Comments
 (0)