test_date.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. 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_width(gui: Gui, test_client, helpers):
  36. gui._bind_var_val("date", datetime.strptime("15 Dec 2020", "%d %b %Y"))
  37. md_string = "<|{date}|date|width=70%|>"
  38. expected_list = [
  39. "<DateSelector",
  40. 'defaultDate="2020-12-',
  41. 'updateVarName="_TpDt_tpec_TpExPr_date_TPMDL_0"',
  42. 'width="70%"',
  43. "date={_TpDt_tpec_TpExPr_date_TPMDL_0}",
  44. ]
  45. helpers.test_control_md(gui, md_string, expected_list)
  46. def test_date_html_1(gui: Gui, test_client, helpers):
  47. gui._bind_var_val("date", datetime.strptime("15 Dec 2020", "%d %b %Y"))
  48. html_string = '<taipy:date date="{date}" />'
  49. expected_list = [
  50. "<DateSelector",
  51. 'defaultDate="2020-12-',
  52. 'updateVarName="_TpDt_tpec_TpExPr_date_TPMDL_0"',
  53. "date={_TpDt_tpec_TpExPr_date_TPMDL_0}",
  54. ]
  55. helpers.test_control_html(gui, html_string, expected_list)
  56. def test_date_html_2(gui: Gui, test_client, helpers):
  57. gui._bind_var_val("date", datetime.strptime("15 Dec 2020", "%d %b %Y"))
  58. html_string = "<taipy:date>{date}</taipy:date>"
  59. expected_list = [
  60. "<DateSelector",
  61. 'defaultDate="2020-12-',
  62. 'updateVarName="_TpDt_tpec_TpExPr_date_TPMDL_0"',
  63. "date={_TpDt_tpec_TpExPr_date_TPMDL_0}",
  64. ]
  65. helpers.test_control_html(gui, html_string, expected_list)