Skip to content

Commit d8d95b7

Browse files
committed
add tests for codecov
1 parent 31ec92b commit d8d95b7

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

ultraplot/tests/test_config.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,73 @@ def test_cycle_rc_setting(cycle, raises_error):
209209
else:
210210
with uplt.rc.context(cycle=cycle):
211211
pass
212+
213+
214+
def test_check_key():
215+
"""
216+
Test the _check_key method in _RcParams
217+
"""
218+
from ultraplot.internals.rcsetup import _RcParams
219+
220+
# Create a test instance
221+
rc_params = _RcParams({"test_key": "test_value"}, {"test_key": lambda x: x})
222+
223+
# Test valid key
224+
key, value = rc_params._check_key("test_key", "new_value")
225+
assert key == "test_key"
226+
assert value == "new_value"
227+
228+
# Test new key (should be registered with default validator)
229+
key, value = rc_params._check_key("new_key", "new_value")
230+
assert key == "new_key"
231+
assert value == "new_value"
232+
assert "new_key" in rc_params._validate
233+
234+
235+
def test_repr():
236+
"""
237+
Test the __repr__ method in _RcParams
238+
"""
239+
from ultraplot.internals.rcsetup import _RcParams
240+
241+
# Create a test instance
242+
rc_params = _RcParams({"test_key": "test_value"}, {"test_key": lambda x: x})
243+
244+
# Test __repr__
245+
repr_str = repr(rc_params)
246+
assert "RcParams" in repr_str
247+
assert "test_key" in repr_str
248+
249+
250+
def test_validators():
251+
"""
252+
Test validators in _RcParams
253+
"""
254+
from ultraplot.internals.rcsetup import _RcParams
255+
256+
# Create a test instance with various validators
257+
validators = {
258+
"int_val": lambda x: int(x),
259+
"float_val": lambda x: float(x),
260+
"str_val": lambda x: str(x),
261+
}
262+
rc_params = _RcParams(
263+
{"int_val": 1, "float_val": 1.0, "str_val": "test"}, validators
264+
)
265+
266+
# Test valid values
267+
rc_params["int_val"] = 2
268+
assert rc_params["int_val"] == 2
269+
270+
rc_params["float_val"] = 2.5
271+
assert rc_params["float_val"] == 2.5
272+
273+
rc_params["str_val"] = "new_value"
274+
assert rc_params["str_val"] == "new_value"
275+
276+
# Test invalid values
277+
with pytest.raises(ValueError):
278+
rc_params["int_val"] = "not_an_int"
279+
280+
with pytest.raises(ValueError):
281+
rc_params["float_val"] = "not_a_float"

0 commit comments

Comments
 (0)