test_cond.py 1003 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import pytest
  2. import pynecone as pc
  3. from pynecone.components.layout.cond import Cond
  4. from pynecone.components.typography.text import Text
  5. @pytest.fixture
  6. def cond_state(request):
  7. class CondState(pc.State):
  8. value: request.param["value_type"] = request.param["value"]
  9. return CondState
  10. @pytest.mark.parametrize(
  11. "cond_state",
  12. [
  13. pytest.param({"value_type": bool, "value": True}),
  14. pytest.param({"value_type": int, "value": 0}),
  15. pytest.param({"value_type": str, "value": "true"}),
  16. ],
  17. indirect=True,
  18. )
  19. def test_validate_cond(cond_state: pc.Var):
  20. """Test if cond can be a pc.Val with any values
  21. Args:
  22. cond_state: A fixture.
  23. """
  24. cond_component = Cond.create(
  25. cond_state.value,
  26. Text.create("cond is True"),
  27. Text.create("cond is False"),
  28. )
  29. assert str(cond_component) == (
  30. "{cond_state.value ? "
  31. "<Text>{`cond is True`}</Text> : "
  32. "<Text>{`cond is False`}</Text>}"
  33. )