test_table.py 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. # Copyright 2021-2024 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;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;}"', # 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;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;}"', # 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|not editable|>"
  61. expected_list = [
  62. "<Table",
  63. "allowAllRows={true}",
  64. "autoLoading={true}",
  65. "editable={false}",
  66. '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;}"', # noqa: E501
  67. 'height="60vh"',
  68. 'width="60vw"',
  69. 'pageSizeOptions="[10, 50, 100, 500]"',
  70. "pageSize={10}",
  71. "selected={[]}",
  72. 'updateVarName="_TpD_tpec_TpExPr_csvdata_TPMDL_0"',
  73. "data={_TpD_tpec_TpExPr_csvdata_TPMDL_0}",
  74. ]
  75. gui._set_frame(inspect.currentframe())
  76. helpers.test_control_md(gui, md_string, expected_list)
  77. def test_table_html_1(gui: Gui, helpers, csvdata):
  78. 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
  79. expected_list = [
  80. "<Table",
  81. '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;}"', # noqa: E501
  82. 'height="80vh"',
  83. 'width="100%"',
  84. 'pageSizeOptions="[10, 30, 100]"',
  85. "pageSize={10.0}",
  86. "selected={[]}",
  87. 'updateVarName="_TpD_tpec_TpExPr_csvdata_TPMDL_0"',
  88. "data={_TpD_tpec_TpExPr_csvdata_TPMDL_0}",
  89. ]
  90. gui._set_frame(inspect.currentframe())
  91. helpers.test_control_html(gui, html_string, expected_list)
  92. def test_table_html_2(gui: Gui, helpers, csvdata):
  93. table_properties = { # noqa: F841
  94. "page_size": 10,
  95. "page_size_options": [10, 50, 100, 500],
  96. "allow_all_rows": True,
  97. "columns": {
  98. "Day": {"index": 0, "format": "dd/MM/yyyy", "title": "Date of measure"},
  99. "Entity": {"index": 1},
  100. "Code": {"index": 2},
  101. "Daily hospital occupancy": {"index": 3},
  102. },
  103. "date_format": "eee dd MMM yyyy",
  104. "number_format": "%.3f",
  105. "width": "60vw",
  106. "height": "60vh",
  107. }
  108. html_string = '<taipy:table data="{csvdata}" properties="table_properties" auto_loading="Yes" show_all="Sure" />'
  109. expected_list = [
  110. "<Table",
  111. "allowAllRows={true}",
  112. "autoLoading={true}",
  113. "showAll={true}",
  114. '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;}"', # noqa: E501
  115. 'height="60vh"',
  116. 'width="60vw"',
  117. 'pageSizeOptions="[10, 50, 100, 500]"',
  118. "pageSize={10}",
  119. "selected={[]}",
  120. 'updateVarName="_TpD_tpec_TpExPr_csvdata_TPMDL_0"',
  121. "data={_TpD_tpec_TpExPr_csvdata_TPMDL_0}",
  122. ]
  123. gui._set_frame(inspect.currentframe())
  124. helpers.test_control_html(gui, html_string, expected_list)