test_date.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. from datetime import datetime
  12. from taipy.gui import Gui
  13. def test_date_md_1(gui: Gui, test_client, helpers):
  14. gui._bind_var_val("date", datetime.strptime("15 Dec 2020", "%d %b %Y"))
  15. md_string = "<|{date}|date|>"
  16. expected_list = [
  17. "<DateSelector",
  18. 'defaultDate="2020-12-',
  19. 'updateVarName="_TpDt_tpec_TpExPr_date_TPMDL_0"',
  20. "date={_TpDt_tpec_TpExPr_date_TPMDL_0}",
  21. ]
  22. helpers.test_control_md(gui, md_string, expected_list)
  23. def test_date_md_2(gui: Gui, test_client, helpers):
  24. gui._bind_var_val("date", datetime.strptime("15 Dec 2020", "%d %b %Y"))
  25. md_string = "<|{date}|date|with_time|label=a label|>"
  26. expected_list = [
  27. "<DateSelector",
  28. 'defaultDate="2020-12-',
  29. 'updateVarName="_TpDt_tpec_TpExPr_date_TPMDL_0"',
  30. "date={_TpDt_tpec_TpExPr_date_TPMDL_0}",
  31. "withTime={true}",
  32. 'label="a label"',
  33. ]
  34. helpers.test_control_md(gui, md_string, expected_list)
  35. def test_date_md_3(gui: Gui, test_client, helpers):
  36. gui._bind_var_val("date", datetime.strptime("15 Dec 2020", "%d %b %Y"))
  37. md_string = "<|{date}|date|with_time|analogic|label=a label|>"
  38. expected_list = [
  39. "<DateSelector",
  40. 'defaultDate="2020-12-',
  41. 'updateVarName="_TpDt_tpec_TpExPr_date_TPMDL_0"',
  42. "date={_TpDt_tpec_TpExPr_date_TPMDL_0}",
  43. "withTime={true}",
  44. "analogic={true}",
  45. 'label="a label"',
  46. ]
  47. helpers.test_control_md(gui, md_string, expected_list)
  48. def test_date_md_width(gui: Gui, test_client, helpers):
  49. gui._bind_var_val("date", datetime.strptime("15 Dec 2020", "%d %b %Y"))
  50. md_string = "<|{date}|date|width=70%|>"
  51. expected_list = [
  52. "<DateSelector",
  53. 'defaultDate="2020-12-',
  54. 'updateVarName="_TpDt_tpec_TpExPr_date_TPMDL_0"',
  55. 'width="70%"',
  56. "date={_TpDt_tpec_TpExPr_date_TPMDL_0}",
  57. ]
  58. helpers.test_control_md(gui, md_string, expected_list)
  59. def test_date_html_1(gui: Gui, test_client, helpers):
  60. gui._bind_var_val("date", datetime.strptime("15 Dec 2020", "%d %b %Y"))
  61. html_string = '<taipy:date date="{date}" />'
  62. expected_list = [
  63. "<DateSelector",
  64. 'defaultDate="2020-12-',
  65. 'updateVarName="_TpDt_tpec_TpExPr_date_TPMDL_0"',
  66. "date={_TpDt_tpec_TpExPr_date_TPMDL_0}",
  67. ]
  68. helpers.test_control_html(gui, html_string, expected_list)
  69. def test_date_html_2(gui: Gui, test_client, helpers):
  70. gui._bind_var_val("date", datetime.strptime("15 Dec 2020", "%d %b %Y"))
  71. html_string = "<taipy:date>{date}</taipy:date>"
  72. expected_list = [
  73. "<DateSelector",
  74. 'defaultDate="2020-12-',
  75. 'updateVarName="_TpDt_tpec_TpExPr_date_TPMDL_0"',
  76. "date={_TpDt_tpec_TpExPr_date_TPMDL_0}",
  77. ]
  78. helpers.test_control_html(gui, html_string, expected_list)