test_icon.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import pytest
  2. from pynecone.components.media.icon import ICON_LIST, Icon
  3. from pynecone.utils import format
  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 == format.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)
  31. @pytest.mark.parametrize(
  32. "tag",
  33. ["Check", "Close", "eDit"],
  34. )
  35. def test_tag_with_capital(tag: str):
  36. """Test that an icon that tag with capital does not raise an error.
  37. Args:
  38. tag: The icon tag.
  39. """
  40. icon = Icon.create(tag=tag)
  41. assert icon.tag == format.to_title_case(tag) + "Icon"