test_date_range.py 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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_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_md_width(gui: Gui, test_client, helpers):
  41. # do not remove test_client: it brings an app context needed for this test
  42. gui._bind_var_val(
  43. "dates", [datetime.strptime("15 Dec 2020", "%d %b %Y"), datetime.strptime("31 Dec 2020", "%d %b %Y")]
  44. )
  45. md_string = "<|{dates}|date_range|width=70%|>"
  46. expected_list = [
  47. "<DateRange",
  48. 'defaultDates="[&quot;2020-12-',
  49. 'updateVarName="_TpDr_tpec_TpExPr_dates_TPMDL_0"',
  50. 'width="70%"',
  51. "dates={_TpDr_tpec_TpExPr_dates_TPMDL_0}",
  52. ]
  53. helpers.test_control_md(gui, md_string, expected_list)
  54. def test_date_range_html_1(gui: Gui, test_client, helpers):
  55. gui._bind_var_val(
  56. "dates", [datetime.strptime("15 Dec 2020", "%d %b %Y"), datetime.strptime("31 Dec 2020", "%d %b %Y")]
  57. )
  58. html_string = '<taipy:date_range dates="{dates}" />'
  59. expected_list = [
  60. "<DateRange",
  61. 'defaultDates="[&quot;2020-12-',
  62. 'updateVarName="_TpDr_tpec_TpExPr_dates_TPMDL_0"',
  63. "dates={_TpDr_tpec_TpExPr_dates_TPMDL_0}",
  64. ]
  65. helpers.test_control_html(gui, html_string, expected_list)
  66. def test_date_range_html_2(gui: Gui, test_client, helpers):
  67. gui._bind_var_val(
  68. "dates", [datetime.strptime("15 Dec 2020", "%d %b %Y"), datetime.strptime("31 Dec 2020", "%d %b %Y")]
  69. )
  70. html_string = "<taipy:date_range>{dates}</taipy:date_range>"
  71. expected_list = [
  72. "<DateRange",
  73. 'defaultDates="[&quot;2020-12-',
  74. 'updateVarName="_TpDr_tpec_TpExPr_dates_TPMDL_0"',
  75. "dates={_TpDr_tpec_TpExPr_dates_TPMDL_0}",
  76. ]
  77. helpers.test_control_html(gui, html_string, expected_list)