test_date_range.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # Copyright 2023 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_range_md_1(gui: Gui, test_client, helpers):
  14. gui._bind_var_val(
  15. "dates", [datetime.strptime("15 Dec 2020", "%d %b %Y"), datetime.strptime("31 Dec 2020", "%d %b %Y")]
  16. )
  17. md_string = "<|{dates}|date_range|>"
  18. expected_list = [
  19. "<DateRange",
  20. 'defaultDates="[&quot;2020-12-',
  21. 'updateVarName="_TpDr_tpec_TpExPr_dates_TPMDL_0"',
  22. "dates={_TpDr_tpec_TpExPr_dates_TPMDL_0}",
  23. ]
  24. helpers.test_control_md(gui, md_string, expected_list)
  25. def test_date_range_md_2(gui: Gui, test_client, helpers):
  26. gui._bind_var_val(
  27. "dates", [datetime.strptime("15 Dec 2020", "%d %b %Y"), datetime.strptime("31 Dec 2020", "%d %b %Y")]
  28. )
  29. md_string = "<|{dates}|date_range|with_time|label_start=start|label_end=end|>"
  30. expected_list = [
  31. "<DateRange",
  32. 'defaultDates="[&quot;2020-12-',
  33. 'updateVarName="_TpDr_tpec_TpExPr_dates_TPMDL_0"',
  34. "dates={_TpDr_tpec_TpExPr_dates_TPMDL_0}",
  35. "withTime={true}",
  36. 'labelStart="start"',
  37. 'labelEnd="end"',
  38. ]
  39. helpers.test_control_md(gui, md_string, expected_list)
  40. def test_date_range_html_1(gui: Gui, test_client, helpers):
  41. gui._bind_var_val(
  42. "dates", [datetime.strptime("15 Dec 2020", "%d %b %Y"), datetime.strptime("31 Dec 2020", "%d %b %Y")]
  43. )
  44. html_string = '<taipy:date_range dates="{dates}" />'
  45. expected_list = [
  46. "<DateRange",
  47. 'defaultDates="[&quot;2020-12-',
  48. 'updateVarName="_TpDr_tpec_TpExPr_dates_TPMDL_0"',
  49. "dates={_TpDr_tpec_TpExPr_dates_TPMDL_0}",
  50. ]
  51. helpers.test_control_html(gui, html_string, expected_list)
  52. def test_date_range_html_2(gui: Gui, test_client, helpers):
  53. gui._bind_var_val(
  54. "dates", [datetime.strptime("15 Dec 2020", "%d %b %Y"), datetime.strptime("31 Dec 2020", "%d %b %Y")]
  55. )
  56. html_string = "<taipy:date_range>{dates}</taipy:date_range>"
  57. expected_list = [
  58. "<DateRange",
  59. 'defaultDates="[&quot;2020-12-',
  60. 'updateVarName="_TpDr_tpec_TpExPr_dates_TPMDL_0"',
  61. "dates={_TpDr_tpec_TpExPr_dates_TPMDL_0}",
  62. ]
  63. helpers.test_control_html(gui, html_string, expected_list)