test_icon.py 949 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import pytest
  2. from pynecone import utils
  3. from pynecone.components.media.icon import ICON_LIST, Icon
  4. def test_no_tag_errors():
  5. """Test that an icon without a tag raises an error."""
  6. with pytest.raises(AttributeError):
  7. Icon.create()
  8. def test_children_errors():
  9. """Test that an icon with children raises an error."""
  10. with pytest.raises(AttributeError):
  11. Icon.create("child", tag="search")
  12. @pytest.mark.parametrize(
  13. "tag",
  14. ICON_LIST,
  15. )
  16. def test_valid_icon(tag: str):
  17. """Test that a valid icon does not raise an error.
  18. Args:
  19. tag: The icon tag.
  20. """
  21. icon = Icon.create(tag=tag)
  22. assert icon.tag == utils.to_title_case(tag) + "Icon"
  23. @pytest.mark.parametrize("tag", ["", " ", "invalid", 123])
  24. def test_invalid_icon(tag):
  25. """Test that an invalid icon raises an error.
  26. Args:
  27. tag: The icon tag.
  28. """
  29. with pytest.raises(ValueError):
  30. Icon.create(tag=tag)