MCPcopy Create free account
hub / github.com/ipython/traitlets / _from_string_test

Function _from_string_test

tests/test_traitlets.py:2902–2918  ·  view source on GitHub ↗

Run a test of trait.from_string

(traittype, s, expected)

Source from the content-addressed store, hash-verified

2900
2901
2902def _from_string_test(traittype, s, expected):
2903 """Run a test of trait.from_string"""
2904 if isinstance(traittype, TraitType):
2905 trait = traittype
2906 else:
2907 trait = traittype(allow_none=True)
2908 if isinstance(s, list):
2909 cast = trait.from_string_list # type:ignore
2910 else:
2911 cast = trait.from_string
2912 if type(expected) is type and issubclass(expected, Exception):
2913 with pytest.raises(expected): # noqa: PT012
2914 value = cast(s)
2915 trait.validate(CrossValidationStub(), value) # type:ignore
2916 else:
2917 value = cast(s)
2918 assert value == expected
2919
2920
2921@pytest.mark.parametrize(

Callers 15

test_unicode_from_stringFunction · 0.85
test_bytes_from_stringFunction · 0.85
test_cbytes_from_stringFunction · 0.85
test_int_from_stringFunction · 0.85
test_float_from_stringFunction · 0.85
test_complex_from_stringFunction · 0.85
test_bool_from_stringFunction · 0.85
test_dict_from_stringFunction · 0.85
test_list_from_stringFunction · 0.85
test_set_from_stringFunction · 0.85

Calls 2

CrossValidationStubClass · 0.85
validateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…