test_table.py 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 inspect
  12. from taipy.gui import Gui
  13. def test_table_md_1(gui: Gui, helpers, csvdata):
  14. md_string = "<|{csvdata}|table|page_size=10|page_size_options=10;30;100|columns=Day;Entity;Code;Daily hospital occupancy|date_format=eee dd MMM yyyy|>" # noqa: E501
  15. expected_list = [
  16. "<Table",
  17. 'defaultColumns="{&quot;Entity&quot;: &#x7B;&quot;type&quot;: &quot;object&quot;, &quot;index&quot;: 1, &quot;dfid&quot;: &quot;Entity&quot;&#x7D;, &quot;Code&quot;: &#x7B;&quot;type&quot;: &quot;object&quot;, &quot;index&quot;: 2, &quot;dfid&quot;: &quot;Code&quot;&#x7D;, &quot;Daily hospital occupancy&quot;: &#x7B;&quot;type&quot;: &quot;int&quot;, &quot;index&quot;: 3, &quot;dfid&quot;: &quot;Daily hospital occupancy&quot;&#x7D;, &quot;Day_str&quot;: &#x7B;&quot;type&quot;: &quot;datetime&quot;, &quot;index&quot;: 0, &quot;format&quot;: &quot;eee dd MMM yyyy&quot;, &quot;dfid&quot;: &quot;Day&quot;&#x7D;}"', # noqa: E501
  18. 'height="80vh"',
  19. 'width="100%"',
  20. 'pageSizeOptions="[10, 30, 100]"',
  21. "pageSize={10.0}",
  22. "selected={[]}",
  23. 'updateVarName="_TpD_tpec_TpExPr_csvdata_TPMDL_0"',
  24. "data={_TpD_tpec_TpExPr_csvdata_TPMDL_0}",
  25. ]
  26. gui._set_frame(inspect.currentframe())
  27. helpers.test_control_md(gui, md_string, expected_list)
  28. def test_table_reset_md(gui: Gui, helpers, csvdata):
  29. md_string = "<|{csvdata}|table|rebuild|page_size=10|page_size_options=10;30;100|columns=Day;Entity;Code;Daily hospital occupancy|date_format=eee dd MMM yyyy|>" # noqa: E501
  30. expected_list = [
  31. "<Table",
  32. 'defaultColumns="{&quot;Entity&quot;: &#x7B;&quot;type&quot;: &quot;object&quot;, &quot;index&quot;: 1, &quot;dfid&quot;: &quot;Entity&quot;&#x7D;, &quot;Code&quot;: &#x7B;&quot;type&quot;: &quot;object&quot;, &quot;index&quot;: 2, &quot;dfid&quot;: &quot;Code&quot;&#x7D;, &quot;Daily hospital occupancy&quot;: &#x7B;&quot;type&quot;: &quot;int&quot;, &quot;index&quot;: 3, &quot;dfid&quot;: &quot;Daily hospital occupancy&quot;&#x7D;, &quot;Day_str&quot;: &#x7B;&quot;type&quot;: &quot;datetime&quot;, &quot;index&quot;: 0, &quot;format&quot;: &quot;eee dd MMM yyyy&quot;, &quot;dfid&quot;: &quot;Day&quot;&#x7D;}"', # noqa: E501
  33. 'height="80vh"',
  34. 'width="100%"',
  35. 'pageSizeOptions="[10, 30, 100]"',
  36. "pageSize={10.0}",
  37. "selected={[]}",
  38. 'updateVarName="_TpD_tpec_TpExPr_csvdata_TPMDL_0"',
  39. "data={_TpD_tpec_TpExPr_csvdata_TPMDL_0}",
  40. "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}",
  41. ]
  42. gui._set_frame(inspect.currentframe())
  43. helpers.test_control_md(gui, md_string, expected_list)
  44. def test_table_md_2(gui: Gui, helpers, csvdata):
  45. table_properties = { # noqa: F841
  46. "page_size": 10,
  47. "page_size_options": [10, 50, 100, 500],
  48. "allow_all_rows": True,
  49. "columns": {
  50. "Day": {"index": 0, "format": "dd/MM/yyyy", "title": "Date of measure"},
  51. "Entity": {"index": 1},
  52. "Code": {"index": 2},
  53. "Daily hospital occupancy": {"index": 3},
  54. },
  55. "date_format": "eee dd MMM yyyy",
  56. "number_format": "%.3f",
  57. "width": "60vw",
  58. "height": "60vh",
  59. }
  60. md_string = "<|{csvdata}|table|properties=table_properties|auto_loading|editable|>"
  61. expected_list = [
  62. "<Table",
  63. "allowAllRows={true}",
  64. "autoLoading={true}",
  65. "editable={true}",
  66. 'onEdit="__gui.table_on_edit',
  67. 'onDelete="__gui.table_on_delete',
  68. 'onAdd="__gui.table_on_add',
  69. '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;format&quot;: &quot;%.3f&quot;, &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;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;}"', # noqa: E501
  70. 'height="60vh"',
  71. 'width="60vw"',
  72. 'pageSizeOptions="[10, 50, 100, 500]"',
  73. "pageSize={10}",
  74. "selected={[]}",
  75. 'updateVarName="_TpD_tpec_TpExPr_csvdata_TPMDL_0"',
  76. "data={_TpD_tpec_TpExPr_csvdata_TPMDL_0}",
  77. ]
  78. gui._set_frame(inspect.currentframe())
  79. helpers.test_control_md(gui, md_string, expected_list)
  80. def test_table_html_1(gui: Gui, helpers, csvdata):
  81. html_string = '<taipy:table data="{csvdata}" page_size="10" page_size_options="10;30;100" columns="Day;Entity;Code;Daily hospital occupancy" date_format="eee dd MMM yyyy" />' # noqa: E501
  82. expected_list = [
  83. "<Table",
  84. 'defaultColumns="{&quot;Entity&quot;: &#x7B;&quot;type&quot;: &quot;object&quot;, &quot;index&quot;: 1, &quot;dfid&quot;: &quot;Entity&quot;&#x7D;, &quot;Code&quot;: &#x7B;&quot;type&quot;: &quot;object&quot;, &quot;index&quot;: 2, &quot;dfid&quot;: &quot;Code&quot;&#x7D;, &quot;Daily hospital occupancy&quot;: &#x7B;&quot;type&quot;: &quot;int&quot;, &quot;index&quot;: 3, &quot;dfid&quot;: &quot;Daily hospital occupancy&quot;&#x7D;, &quot;Day_str&quot;: &#x7B;&quot;type&quot;: &quot;datetime&quot;, &quot;index&quot;: 0, &quot;format&quot;: &quot;eee dd MMM yyyy&quot;, &quot;dfid&quot;: &quot;Day&quot;&#x7D;}"', # noqa: E501
  85. 'height="80vh"',
  86. 'width="100%"',
  87. 'pageSizeOptions="[10, 30, 100]"',
  88. "pageSize={10.0}",
  89. "selected={[]}",
  90. 'updateVarName="_TpD_tpec_TpExPr_csvdata_TPMDL_0"',
  91. "data={_TpD_tpec_TpExPr_csvdata_TPMDL_0}",
  92. ]
  93. gui._set_frame(inspect.currentframe())
  94. helpers.test_control_html(gui, html_string, expected_list)
  95. def test_table_html_2(gui: Gui, helpers, csvdata):
  96. table_properties = { # noqa: F841
  97. "page_size": 10,
  98. "page_size_options": [10, 50, 100, 500],
  99. "allow_all_rows": True,
  100. "columns": {
  101. "Day": {"index": 0, "format": "dd/MM/yyyy", "title": "Date of measure"},
  102. "Entity": {"index": 1},
  103. "Code": {"index": 2},
  104. "Daily hospital occupancy": {"index": 3},
  105. },
  106. "date_format": "eee dd MMM yyyy",
  107. "number_format": "%.3f",
  108. "width": "60vw",
  109. "height": "60vh",
  110. }
  111. html_string = '<taipy:table data="{csvdata}" properties="table_properties" auto_loading="Yes" show_all="Sure" />'
  112. expected_list = [
  113. "<Table",
  114. "allowAllRows={true}",
  115. "autoLoading={true}",
  116. "showAll={true}",
  117. '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;format&quot;: &quot;%.3f&quot;, &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;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;}"', # noqa: E501
  118. 'height="60vh"',
  119. 'width="60vw"',
  120. 'pageSizeOptions="[10, 50, 100, 500]"',
  121. "pageSize={10}",
  122. "selected={[]}",
  123. 'updateVarName="_TpD_tpec_TpExPr_csvdata_TPMDL_0"',
  124. "data={_TpD_tpec_TpExPr_csvdata_TPMDL_0}",
  125. ]
  126. gui._set_frame(inspect.currentframe())
  127. helpers.test_control_html(gui, html_string, expected_list)