test_tgb.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # Copyright 2021-2025 Avaiga Private Limited
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  4. # the License. You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  9. # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
  10. # specific language governing permissions and limitations under the License.
  11. import typing as t
  12. from taipy.gui import Gui
  13. from taipy.gui.extension import Element, ElementLibrary, ElementProperty, PropertyType
  14. class TgbLibrary(ElementLibrary):
  15. elements = {
  16. "e1": Element(
  17. "s1",
  18. {
  19. "b1": ElementProperty(PropertyType.boolean, doc_string="e1.b1 doc"),
  20. "b2": ElementProperty(PropertyType.dynamic_boolean),
  21. "s1": ElementProperty(PropertyType.string),
  22. "s2": ElementProperty(PropertyType.dynamic_string),
  23. "d1": ElementProperty(PropertyType.dict),
  24. "d2": ElementProperty(PropertyType.dynamic_dict),
  25. },
  26. "E1", doc_string="e1 doc",
  27. ),
  28. "e2": Element(
  29. "x",
  30. {
  31. "p1": ElementProperty(PropertyType.any),
  32. "p2": ElementProperty(PropertyType.any),
  33. },
  34. "E2",
  35. ),
  36. }
  37. def get_name(self) -> str:
  38. return "test_ext_tgb"
  39. def get_elements(self) -> t.Dict[str, Element]:
  40. return TgbLibrary.elements
  41. def test_tgb_generation(gui: Gui, test_client, helpers):
  42. from taipy.gui.extension.__main__ import generate_doc
  43. library = TgbLibrary()
  44. api = generate_doc(library)
  45. assert "def e1(" in api, "Missing element e1"
  46. assert "s1" in api, "Missing property s1"
  47. assert "s1: str" in api, "Incorrect property type for s1"
  48. assert "(s1: str, *" in api, "Property s1 should be the default property"
  49. assert "b1: bool" in api, "Missing or incorrect property type for b1"
  50. assert "b2: bool" in api, "Missing or incorrect property type for b2"
  51. assert "s2: str" in api, "Missing or incorrect property type for s2"
  52. assert "d1: dict" in api, "Missing or incorrect property type for d2"
  53. assert "d2: dict" in api, "Missing or incorrect property type for d2"
  54. assert "e1 doc" in api, "Missing doc for e1"
  55. assert "def e2(" in api, "Missing element e2"
  56. assert "e2(p1, p2)" in api, "Wrong default property in e2"