test_timezone.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # Copyright 2021-2025 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. import inspect
  12. from importlib import util
  13. import pytest
  14. if util.find_spec("playwright"):
  15. from playwright._impl._page import Page
  16. from taipy.gui import Gui
  17. from taipy.gui.utils.date import _string_to_date
  18. @pytest.mark.teste2e
  19. def test_timzone_specified_1(page: "Page", gui: Gui, helpers):
  20. _timezone_test_template(page, gui, helpers, "Etc/GMT", ["2022-03-03 00:00:00 UTC"])
  21. @pytest.mark.teste2e
  22. def test_timzone_specified_2(page: "Page", gui: Gui, helpers):
  23. _timezone_test_template(
  24. page, gui, helpers, "Europe/Paris", ["2022-03-03 01:00:00 GMT+1", "2022-03-03 01:00:00 UTC+1"]
  25. )
  26. @pytest.mark.teste2e
  27. def test_timzone_specified_3(page: "Page", gui: Gui, helpers):
  28. _timezone_test_template(
  29. page, gui, helpers, "Asia/Ho_Chi_Minh", ["2022-03-03 07:00:00 GMT+7", "2022-03-03 07:00:00 UTC+7"]
  30. )
  31. @pytest.mark.teste2e
  32. def test_timzone_specified_4(page: "Page", gui: Gui, helpers):
  33. _timezone_test_template(
  34. page, gui, helpers, "America/Sao_Paulo", ["2022-03-02 21:00:00 GMT-3", "2022-03-02 21:00:00 UTC−3"]
  35. )
  36. @pytest.mark.teste2e
  37. def test_timezone_client_side(page: "Page", gui: Gui, helpers):
  38. _timezone_test_template(page, gui, helpers, "client", ["2022-03-03 01:00:00 GMT+1", "2022-03-03 01:00:00 UTC+1"])
  39. def _timezone_test_template(page: "Page", gui: Gui, helpers, time_zone, texts):
  40. page_md = """
  41. <|{t}|id=text1|>
  42. """
  43. t = _string_to_date("2022-03-03T00:00:00.000Z") # noqa: F841
  44. gui._set_frame(inspect.currentframe())
  45. gui.add_page(name="test", page=page_md)
  46. helpers.run_e2e(gui, time_zone=time_zone)
  47. page.goto("./test")
  48. page.expect_websocket()
  49. page.wait_for_selector("#text1")
  50. text1 = page.query_selector("#text1")
  51. assert text1.inner_text() in texts
  52. @pytest.mark.teste2e
  53. def test_date_only(page: "Page", gui: Gui, helpers):
  54. page_md = """
  55. <|{t}|id=text1|>
  56. """
  57. t = _string_to_date("Wed Jul 28 1993") # noqa: F841
  58. gui._set_frame(inspect.currentframe())
  59. gui.add_page(name="test", page=page_md)
  60. helpers.run_e2e(gui)
  61. page.goto("./test")
  62. page.expect_websocket()
  63. page.wait_for_selector("#text1")
  64. text1 = page.query_selector("#text1")
  65. assert text1.inner_text() in ["1993-07-28"]