test_base.py 516 B

123456789101112131415161718192021
  1. from typing import Dict, List, Union
  2. import pytest
  3. from reflex.vars.base import figure_out_type
  4. @pytest.mark.parametrize(
  5. ("value", "expected"),
  6. [
  7. (1, int),
  8. (1.0, float),
  9. ("a", str),
  10. ([1, 2, 3], List[int]),
  11. ([1, 2.0, "a"], List[Union[int, float, str]]),
  12. ({"a": 1, "b": 2}, Dict[str, int]),
  13. ({"a": 1, 2: "b"}, Dict[Union[int, str], Union[str, int]]),
  14. ],
  15. )
  16. def test_figure_out_type(value, expected):
  17. assert figure_out_type(value) == expected