test_base.py 790 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import pytest
  2. from pynecone.base import Base
  3. @pytest.fixture
  4. def child() -> Base:
  5. """A child class.
  6. Returns:
  7. A child class.
  8. """
  9. class Child(Base):
  10. num: float
  11. key: str
  12. return Child(num=3.14, key="pi")
  13. def test_get_fields(child):
  14. """Test that the fields are set correctly.
  15. Args:
  16. child: A child class.
  17. """
  18. assert child.get_fields().keys() == {"num", "key"}
  19. def test_set(child):
  20. """Test setting fields.
  21. Args:
  22. child: A child class.
  23. """
  24. child.set(num=1, key="a")
  25. assert child.num == 1
  26. assert child.key == "a"
  27. def test_json(child):
  28. """Test converting to json.
  29. Args:
  30. child: A child class.
  31. """
  32. assert child.json().replace(" ", "") == '{"num":3.14,"key":"pi"}'