test_table.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # Copyright 2023 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 inspect
  12. import taipy.gui.builder as tgb
  13. from taipy.gui import Gui
  14. def test_table_builder_1(gui: Gui, helpers, csvdata):
  15. with tgb.Page(frame=None) as page:
  16. tgb.table(
  17. data="{csvdata}",
  18. page_size=10,
  19. page_size_options=[10, 30, 100],
  20. columns=["Day", "Entity", "Code", "Daily hospital occupancy"],
  21. date_format="eee dd MMM yyyy",
  22. )
  23. expected_list = [
  24. "<Table",
  25. 'defaultColumns="{&quot;Entity&quot;: &#x7B;&quot;index&quot;: 1, &quot;type&quot;: &quot;object&quot;, &quot;dfid&quot;: &quot;Entity&quot;&#x7D;, &quot;Code&quot;: &#x7B;&quot;index&quot;: 2, &quot;type&quot;: &quot;object&quot;, &quot;dfid&quot;: &quot;Code&quot;&#x7D;, &quot;Daily hospital occupancy&quot;: &#x7B;&quot;index&quot;: 3, &quot;type&quot;: &quot;int&quot;, &quot;dfid&quot;: &quot;Daily hospital occupancy&quot;&#x7D;, &quot;Day_str&quot;: &#x7B;&quot;index&quot;: 0, &quot;type&quot;: &quot;datetime&quot;, &quot;dfid&quot;: &quot;Day&quot;, &quot;format&quot;: &quot;eee dd MMM yyyy&quot;&#x7D;}"',
  26. 'height="80vh"',
  27. 'width="100%"',
  28. 'pageSizeOptions="[10, 30, 100]"',
  29. "pageSize={10.0}",
  30. "selected={[]}",
  31. 'updateVarName="_TpD_tpec_TpExPr_csvdata_TPMDL_0"',
  32. "data={_TpD_tpec_TpExPr_csvdata_TPMDL_0}",
  33. ]
  34. gui._set_frame(inspect.currentframe())
  35. helpers.test_control_builder(gui, page, expected_list)
  36. def test_table_reset_builder(gui: Gui, helpers, csvdata):
  37. with tgb.Page(frame=None) as page:
  38. tgb.table(
  39. data="{csvdata}",
  40. rebuild=True,
  41. page_size=10,
  42. page_size_options="10;30;100",
  43. columns="Day;Entity;Code;Daily hospital occupancy",
  44. date_format="eee dd MMM yyyy",
  45. )
  46. expected_list = [
  47. "<Table",
  48. 'defaultColumns="{&quot;Entity&quot;: &#x7B;&quot;index&quot;: 1, &quot;type&quot;: &quot;object&quot;, &quot;dfid&quot;: &quot;Entity&quot;&#x7D;, &quot;Code&quot;: &#x7B;&quot;index&quot;: 2, &quot;type&quot;: &quot;object&quot;, &quot;dfid&quot;: &quot;Code&quot;&#x7D;, &quot;Daily hospital occupancy&quot;: &#x7B;&quot;index&quot;: 3, &quot;type&quot;: &quot;int&quot;, &quot;dfid&quot;: &quot;Daily hospital occupancy&quot;&#x7D;, &quot;Day_str&quot;: &#x7B;&quot;index&quot;: 0, &quot;type&quot;: &quot;datetime&quot;, &quot;dfid&quot;: &quot;Day&quot;, &quot;format&quot;: &quot;eee dd MMM yyyy&quot;&#x7D;}"',
  49. 'height="80vh"',
  50. 'width="100%"',
  51. 'pageSizeOptions="[10, 30, 100]"',
  52. "pageSize={10.0}",
  53. "selected={[]}",
  54. 'updateVarName="_TpD_tpec_TpExPr_csvdata_TPMDL_0"',
  55. "data={_TpD_tpec_TpExPr_csvdata_TPMDL_0}",
  56. "columns={tp_TpExPr_gui_tbl_cols_True_None_7B_22columns_22_3A_20_22Day_3BEntity_3BCode_3BDaily_20hospital_20occupancy_22_2C_20_22date_format_22_3A_20_22eee_20dd_20MMM_20yyyy_22_7D_7B_22data_22_3A_20_22tpec_TpExPr_csvdata_TPMDL_0_22_7D_tpec_TpExPr_csvdata_TPMDL_0_csvdata_TPMDL_0_0}",
  57. ]
  58. gui._set_frame(inspect.currentframe())
  59. helpers.test_control_builder(gui, page, expected_list)
  60. def test_table_builder_2(gui: Gui, helpers, csvdata):
  61. table_properties = { # noqa: F841
  62. "page_size": 10,
  63. "page_size_options": [10, 50, 100, 500],
  64. "allow_all_rows": True,
  65. "columns": {
  66. "Day": {"index": 0, "format": "dd/MM/yyyy", "title": "Date of measure"},
  67. "Entity": {"index": 1},
  68. "Code": {"index": 2},
  69. "Daily hospital occupancy": {"index": 3},
  70. },
  71. "date_format": "eee dd MMM yyyy",
  72. "number_format": "%.3f",
  73. "width": "60vw",
  74. "height": "60vh",
  75. }
  76. with tgb.Page(frame=None) as page:
  77. tgb.table(data="{csvdata}", properties="table_properties", auto_loading=True, editable=False)
  78. expected_list = [
  79. "<Table",
  80. "allowAllRows={true}",
  81. "autoLoading={true}",
  82. "editable={false}",
  83. 'defaultColumns="{&quot;Entity&quot;: &#x7B;&quot;index&quot;: 1, &quot;type&quot;: &quot;object&quot;, &quot;dfid&quot;: &quot;Entity&quot;&#x7D;, &quot;Code&quot;: &#x7B;&quot;index&quot;: 2, &quot;type&quot;: &quot;object&quot;, &quot;dfid&quot;: &quot;Code&quot;&#x7D;, &quot;Daily hospital occupancy&quot;: &#x7B;&quot;index&quot;: 3, &quot;type&quot;: &quot;int&quot;, &quot;dfid&quot;: &quot;Daily hospital occupancy&quot;, &quot;format&quot;: &quot;%.3f&quot;&#x7D;, &quot;Day_str&quot;: &#x7B;&quot;index&quot;: 0, &quot;format&quot;: &quot;dd/MM/yyyy&quot;, &quot;title&quot;: &quot;Date of measure&quot;, &quot;type&quot;: &quot;datetime&quot;, &quot;dfid&quot;: &quot;Day&quot;&#x7D;}"',
  84. 'height="60vh"',
  85. 'width="60vw"',
  86. 'pageSizeOptions="[10, 50, 100, 500]"',
  87. "pageSize={10}",
  88. "selected={[]}",
  89. 'updateVarName="_TpD_tpec_TpExPr_csvdata_TPMDL_0"',
  90. "data={_TpD_tpec_TpExPr_csvdata_TPMDL_0}",
  91. ]
  92. gui._set_frame(inspect.currentframe())
  93. helpers.test_control_builder(gui, page, expected_list)