Run a test of trait.from_string
(traittype, s, expected)
| 2900 | |
| 2901 | |
| 2902 | def _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( |
no test coverage detected
searching dependent graphs…