test_date.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. import taipy.gui.builder as tgb
  13. from taipy.gui import Gui
  14. def test_date_builder_1(gui: Gui, test_client, helpers):
  15. gui._bind_var_val("date", datetime.strptime("15 Dec 2020", "%d %b %Y"))
  16. with tgb.Page(frame=None) as page:
  17. tgb.date(id="date", date="{date}")
  18. expected_list = [
  19. "<DateSelector",
  20. 'defaultDate="2020-12-',
  21. 'updateVarName="_TpDt_tpec_TpExPr_date_TPMDL_0"',
  22. "date={_TpDt_tpec_TpExPr_date_TPMDL_0}",
  23. ]
  24. helpers.test_control_builder(gui, page, expected_list)
  25. def test_date_builder_2(gui: Gui, test_client, helpers):
  26. gui._bind_var_val("date", datetime.strptime("15 Dec 2020", "%d %b %Y"))
  27. with tgb.Page(frame=None) as page:
  28. tgb.date(id="date", date="{date}", with_time=True)
  29. expected_list = [
  30. "<DateSelector",
  31. 'defaultDate="2020-12-',
  32. 'updateVarName="_TpDt_tpec_TpExPr_date_TPMDL_0"',
  33. "date={_TpDt_tpec_TpExPr_date_TPMDL_0}",
  34. "withTime={true}",
  35. ]
  36. helpers.test_control_builder(gui, page, expected_list)