test_input.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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_input_md_width(gui: Gui, helpers):
  26. x = "Hello World!" # noqa: F841
  27. gui._set_frame(inspect.currentframe())
  28. md_string = "<|{x}|input|width=70%|>"
  29. expected_list = [
  30. "<Input",
  31. 'updateVarName="tpec_TpExPr_x_TPMDL_0"',
  32. 'defaultValue="Hello World!"',
  33. 'type="text"',
  34. 'width="70%"',
  35. "value={tpec_TpExPr_x_TPMDL_0}",
  36. ]
  37. helpers.test_control_md(gui, md_string, expected_list)
  38. def test_password_md(gui: Gui, helpers):
  39. x = "Hello World!" # noqa: F841
  40. gui._set_frame(inspect.currentframe())
  41. md_string = "<|{x}|input|password|>"
  42. expected_list = [
  43. "<Input",
  44. 'updateVarName="tpec_TpExPr_x_TPMDL_0"',
  45. 'defaultValue="Hello World!"',
  46. 'type="password"',
  47. "value={tpec_TpExPr_x_TPMDL_0}",
  48. ]
  49. helpers.test_control_md(gui, md_string, expected_list)
  50. def test_input_html_1(gui: Gui, helpers):
  51. x = "Hello World!" # noqa: F841
  52. gui._set_frame(inspect.currentframe())
  53. html_string = '<taipy:input value="{x}" />'
  54. expected_list = [
  55. "<Input",
  56. 'updateVarName="tpec_TpExPr_x_TPMDL_0"',
  57. 'defaultValue="Hello World!"',
  58. 'type="text"',
  59. "value={tpec_TpExPr_x_TPMDL_0}",
  60. ]
  61. helpers.test_control_html(gui, html_string, expected_list)
  62. def test_password_html(gui: Gui, helpers):
  63. x = "Hello World!" # noqa: F841
  64. gui._set_frame(inspect.currentframe())
  65. html_string = '<taipy:input value="{x}" password="True" width="{100}" />'
  66. expected_list = [
  67. "<Input",
  68. 'updateVarName="tpec_TpExPr_x_TPMDL_0"',
  69. 'defaultValue="Hello World!"',
  70. 'type="password"',
  71. 'width={100}',
  72. "value={tpec_TpExPr_x_TPMDL_0}",
  73. ]
  74. helpers.test_control_html(gui, html_string, expected_list)
  75. def test_input_html_2(gui: Gui, helpers):
  76. x = "Hello World!" # noqa: F841
  77. gui._set_frame(inspect.currentframe())
  78. html_string = "<taipy:input>{x}</taipy:input>"
  79. expected_list = [
  80. "<Input",
  81. 'updateVarName="tpec_TpExPr_x_TPMDL_0"',
  82. 'defaultValue="Hello World!"',
  83. 'type="text"',
  84. "value={tpec_TpExPr_x_TPMDL_0}",
  85. ]
  86. helpers.test_control_html(gui, html_string, expected_list)