123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- # Copyright 2021-2025 Avaiga Private Limited
- #
- # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
- # the License. You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
- # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
- # specific language governing permissions and limitations under the License.
- import inspect
- from taipy.gui import Gui
- def test_table_md_1(gui: Gui, helpers, csvdata):
- 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
- expected_list = [
- "<Table",
- 'defaultColumns="{"Entity": {"type": "object", "index": 1, "dfid": "Entity"}, "Code": {"type": "object", "index": 2, "dfid": "Code"}, "Daily hospital occupancy": {"type": "int", "index": 3, "dfid": "Daily hospital occupancy"}, "Day_str": {"type": "datetime", "index": 0, "format": "eee dd MMM yyyy", "dfid": "Day"}}"', # noqa: E501
- 'height="80vh"',
- 'width="100%"',
- 'pageSizeOptions="[10, 30, 100]"',
- "pageSize={10.0}",
- "selected={[]}",
- 'updateVarName="_TpD_tpec_TpExPr_csvdata_TPMDL_0"',
- "data={_TpD_tpec_TpExPr_csvdata_TPMDL_0}",
- ]
- gui._set_frame(inspect.currentframe())
- helpers.test_control_md(gui, md_string, expected_list)
- def test_table_reset_md(gui: Gui, helpers, csvdata):
- 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
- expected_list = [
- "<Table",
- 'defaultColumns="{"Entity": {"type": "object", "index": 1, "dfid": "Entity"}, "Code": {"type": "object", "index": 2, "dfid": "Code"}, "Daily hospital occupancy": {"type": "int", "index": 3, "dfid": "Daily hospital occupancy"}, "Day_str": {"type": "datetime", "index": 0, "format": "eee dd MMM yyyy", "dfid": "Day"}}"', # noqa: E501
- 'height="80vh"',
- 'width="100%"',
- 'pageSizeOptions="[10, 30, 100]"',
- "pageSize={10.0}",
- "selected={[]}",
- 'updateVarName="_TpD_tpec_TpExPr_csvdata_TPMDL_0"',
- "data={_TpD_tpec_TpExPr_csvdata_TPMDL_0}",
- "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}",
- ]
- gui._set_frame(inspect.currentframe())
- helpers.test_control_md(gui, md_string, expected_list)
- def test_table_md_2(gui: Gui, helpers, csvdata):
- table_properties = { # noqa: F841
- "page_size": 10,
- "page_size_options": [10, 50, 100, 500],
- "allow_all_rows": True,
- "columns": {
- "Day": {"index": 0, "format": "dd/MM/yyyy", "title": "Date of measure"},
- "Entity": {"index": 1},
- "Code": {"index": 2},
- "Daily hospital occupancy": {"index": 3},
- },
- "date_format": "eee dd MMM yyyy",
- "number_format": "%.3f",
- "width": "60vw",
- "height": "60vh",
- }
- md_string = "<|{csvdata}|table|properties=table_properties|auto_loading|editable|>"
- expected_list = [
- "<Table",
- "allowAllRows={true}",
- "autoLoading={true}",
- "editable={true}",
- 'onEdit="__gui.table_on_edit',
- 'onDelete="__gui.table_on_delete',
- 'onAdd="__gui.table_on_add',
- 'defaultColumns="{"Entity": {"index": 1, "type": "object", "dfid": "Entity"}, "Code": {"index": 2, "type": "object", "dfid": "Code"}, "Daily hospital occupancy": {"index": 3, "format": "%.3f", "type": "int", "dfid": "Daily hospital occupancy"}, "Day_str": {"index": 0, "format": "dd/MM/yyyy", "title": "Date of measure", "type": "datetime", "dfid": "Day"}}"', # noqa: E501
- 'height="60vh"',
- 'width="60vw"',
- 'pageSizeOptions="[10, 50, 100, 500]"',
- "pageSize={10}",
- "selected={[]}",
- 'updateVarName="_TpD_tpec_TpExPr_csvdata_TPMDL_0"',
- "data={_TpD_tpec_TpExPr_csvdata_TPMDL_0}",
- ]
- gui._set_frame(inspect.currentframe())
- helpers.test_control_md(gui, md_string, expected_list)
- def test_table_html_1(gui: Gui, helpers, csvdata):
- 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
- expected_list = [
- "<Table",
- 'defaultColumns="{"Entity": {"type": "object", "index": 1, "dfid": "Entity"}, "Code": {"type": "object", "index": 2, "dfid": "Code"}, "Daily hospital occupancy": {"type": "int", "index": 3, "dfid": "Daily hospital occupancy"}, "Day_str": {"type": "datetime", "index": 0, "format": "eee dd MMM yyyy", "dfid": "Day"}}"', # noqa: E501
- 'height="80vh"',
- 'width="100%"',
- 'pageSizeOptions="[10, 30, 100]"',
- "pageSize={10.0}",
- "selected={[]}",
- 'updateVarName="_TpD_tpec_TpExPr_csvdata_TPMDL_0"',
- "data={_TpD_tpec_TpExPr_csvdata_TPMDL_0}",
- ]
- gui._set_frame(inspect.currentframe())
- helpers.test_control_html(gui, html_string, expected_list)
- def test_table_html_2(gui: Gui, helpers, csvdata):
- table_properties = { # noqa: F841
- "page_size": 10,
- "page_size_options": [10, 50, 100, 500],
- "allow_all_rows": True,
- "columns": {
- "Day": {"index": 0, "format": "dd/MM/yyyy", "title": "Date of measure"},
- "Entity": {"index": 1},
- "Code": {"index": 2},
- "Daily hospital occupancy": {"index": 3},
- },
- "date_format": "eee dd MMM yyyy",
- "number_format": "%.3f",
- "width": "60vw",
- "height": "60vh",
- }
- html_string = '<taipy:table data="{csvdata}" properties="table_properties" auto_loading="Yes" show_all="Sure" />'
- expected_list = [
- "<Table",
- "allowAllRows={true}",
- "autoLoading={true}",
- "showAll={true}",
- 'defaultColumns="{"Entity": {"index": 1, "type": "object", "dfid": "Entity"}, "Code": {"index": 2, "type": "object", "dfid": "Code"}, "Daily hospital occupancy": {"index": 3, "format": "%.3f", "type": "int", "dfid": "Daily hospital occupancy"}, "Day_str": {"index": 0, "format": "dd/MM/yyyy", "title": "Date of measure", "type": "datetime", "dfid": "Day"}}"', # noqa: E501
- 'height="60vh"',
- 'width="60vw"',
- 'pageSizeOptions="[10, 50, 100, 500]"',
- "pageSize={10}",
- "selected={[]}",
- 'updateVarName="_TpD_tpec_TpExPr_csvdata_TPMDL_0"',
- "data={_TpD_tpec_TpExPr_csvdata_TPMDL_0}",
- ]
- gui._set_frame(inspect.currentframe())
- helpers.test_control_html(gui, html_string, expected_list)
|