test_input.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. import inspect
  12. from taipy.gui import Gui
  13. def test_input_md(gui: Gui, helpers):
  14. x = "Hello World!" # noqa: F841
  15. gui._set_frame(inspect.currentframe())
  16. md_string = "<|{x}|input|>"
  17. expected_list = [
  18. "<Input",
  19. 'updateVarName="tpec_TpExPr_x_TPMDL_0"',
  20. 'defaultValue="Hello World!"',
  21. 'type="text"',
  22. "value={tpec_TpExPr_x_TPMDL_0}",
  23. ]
  24. helpers.test_control_md(gui, md_string, expected_list)
  25. def test_password_md(gui: Gui, helpers):
  26. x = "Hello World!" # noqa: F841
  27. gui._set_frame(inspect.currentframe())
  28. md_string = "<|{x}|input|password|>"
  29. expected_list = [
  30. "<Input",
  31. 'updateVarName="tpec_TpExPr_x_TPMDL_0"',
  32. 'defaultValue="Hello World!"',
  33. 'type="password"',
  34. "value={tpec_TpExPr_x_TPMDL_0}",
  35. ]
  36. helpers.test_control_md(gui, md_string, expected_list)
  37. def test_input_html_1(gui: Gui, helpers):
  38. x = "Hello World!" # noqa: F841
  39. gui._set_frame(inspect.currentframe())
  40. html_string = '<taipy:input value="{x}" />'
  41. expected_list = [
  42. "<Input",
  43. 'updateVarName="tpec_TpExPr_x_TPMDL_0"',
  44. 'defaultValue="Hello World!"',
  45. 'type="text"',
  46. "value={tpec_TpExPr_x_TPMDL_0}",
  47. ]
  48. helpers.test_control_html(gui, html_string, expected_list)
  49. def test_password_html(gui: Gui, helpers):
  50. x = "Hello World!" # noqa: F841
  51. gui._set_frame(inspect.currentframe())
  52. html_string = '<taipy:input value="{x}" password="True" />'
  53. expected_list = [
  54. "<Input",
  55. 'updateVarName="tpec_TpExPr_x_TPMDL_0"',
  56. 'defaultValue="Hello World!"',
  57. 'type="password"',
  58. "value={tpec_TpExPr_x_TPMDL_0}",
  59. ]
  60. helpers.test_control_html(gui, html_string, expected_list)
  61. def test_input_html_2(gui: Gui, helpers):
  62. x = "Hello World!" # noqa: F841
  63. gui._set_frame(inspect.currentframe())
  64. html_string = "<taipy:input>{x}</taipy:input>"
  65. expected_list = [
  66. "<Input",
  67. 'updateVarName="tpec_TpExPr_x_TPMDL_0"',
  68. 'defaultValue="Hello World!"',
  69. 'type="text"',
  70. "value={tpec_TpExPr_x_TPMDL_0}",
  71. ]
  72. helpers.test_control_html(gui, html_string, expected_list)