1
0

test_date.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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_html_1(gui: Gui, test_client, helpers):
  36. gui._bind_var_val("date", datetime.strptime("15 Dec 2020", "%d %b %Y"))
  37. html_string = '<taipy:date date="{date}" />'
  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. ]
  44. helpers.test_control_html(gui, html_string, expected_list)
  45. def test_date_html_2(gui: Gui, test_client, helpers):
  46. gui._bind_var_val("date", datetime.strptime("15 Dec 2020", "%d %b %Y"))
  47. html_string = "<taipy:date>{date}</taipy:date>"
  48. expected_list = [
  49. "<DateSelector",
  50. 'defaultDate="2020-12-',
  51. 'updateVarName="_TpDt_tpec_TpExPr_date_TPMDL_0"',
  52. "date={_TpDt_tpec_TpExPr_date_TPMDL_0}",
  53. ]
  54. helpers.test_control_html(gui, html_string, expected_list)