1
0

test_input.py 2.8 KB

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