test_config.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. from datetime import timedelta
  12. from taipy.common.config import Config
  13. from taipy.common.config.common.scope import Scope
  14. class TestConfig:
  15. def test_configure_csv_data_node(self):
  16. a, b, c, d, e, f = "foo", "path", True, "numpy", Scope.SCENARIO, timedelta(1)
  17. Config.configure_csv_data_node(a, b, c, d, e, f)
  18. assert len(Config.data_nodes) == 2
  19. def test_configure_excel_data_node(self):
  20. a, b, c, d, e, f, g = "foo", "path", True, "Sheet1", "numpy", Scope.SCENARIO, timedelta(1)
  21. Config.configure_excel_data_node(a, b, c, d, e, f, g)
  22. assert len(Config.data_nodes) == 2
  23. def test_configure_generic_data_node(self):
  24. a, b, c, d, e, f, g, h = "foo", print, print, (), (), Scope.SCENARIO, timedelta(1), "qux"
  25. Config.configure_generic_data_node(a, b, c, d, e, f, g, property=h)
  26. assert len(Config.data_nodes) == 2
  27. def test_configure_in_memory_data_node(self):
  28. a, b, c, d, e = "foo", 0, Scope.SCENARIO, timedelta(1), "qux"
  29. Config.configure_in_memory_data_node(a, b, c, d, property=e)
  30. assert len(Config.data_nodes) == 2
  31. def test_configure_pickle_data_node(self):
  32. a, b, c, d, e = "foo", 0, Scope.SCENARIO, timedelta(1), "path"
  33. Config.configure_pickle_data_node(a, b, c, d, path=e)
  34. assert len(Config.data_nodes) == 2
  35. def test_configure_json_data_node(self):
  36. a, dp, ec, dc, sc, f, p = "foo", "path", "ec", "dc", Scope.SCENARIO, timedelta(1), "qux"
  37. Config.configure_json_data_node(a, dp, ec, dc, sc, f, path=p)
  38. assert len(Config.data_nodes) == 2
  39. def test_configure_sql_table_data_node(self):
  40. a, b, c, d, e, f, g, h, i, extra_args, exposed_type, scope, vp, k = (
  41. "foo",
  42. "user",
  43. "pwd",
  44. "db",
  45. "engine",
  46. "table_name",
  47. "port",
  48. "host",
  49. "driver",
  50. {"foo": "bar"},
  51. "exposed_type",
  52. Scope.SCENARIO,
  53. timedelta(1),
  54. "qux",
  55. )
  56. Config.configure_sql_table_data_node(a, b, c, d, e, f, g, h, i, extra_args, exposed_type, scope, vp, property=k)
  57. assert len(Config.data_nodes) == 2
  58. def test_configure_sql_data_node(self):
  59. a, b, c, d, e, f, g, h, i, j, k, extra_args, exposed_type, scope, vp, k = (
  60. "foo",
  61. "user",
  62. "pwd",
  63. "db",
  64. "engine",
  65. "read_query",
  66. "write_query_builder",
  67. "append_query_builder",
  68. "port",
  69. "host",
  70. "driver",
  71. {"foo": "bar"},
  72. "exposed_type",
  73. Scope.SCENARIO,
  74. timedelta(1),
  75. "qux",
  76. )
  77. Config.configure_sql_data_node(a, b, c, d, e, f, g, h, i, j, k, extra_args, exposed_type, scope, vp, property=k)
  78. assert len(Config.data_nodes) == 2
  79. def test_configure_mongo_data_node(self):
  80. a, b, c, d, e, f, g, h, extra_args, scope, vp, k = (
  81. "foo",
  82. "db_name",
  83. "collection_name",
  84. None,
  85. "user",
  86. "pwd",
  87. "host",
  88. "port",
  89. {"foo": "bar"},
  90. Scope.SCENARIO,
  91. timedelta(1),
  92. "qux",
  93. )
  94. Config.configure_mongo_collection_data_node(a, b, c, d, e, f, g, h, extra_args, scope, vp, property=k)
  95. assert len(Config.data_nodes) == 2
  96. def test_configure_s3_object_data_node(self):
  97. a, b, c, d, e, f, extra_args, scope, vp, k = (
  98. "foo",
  99. "access_key",
  100. "secret_acces_key",
  101. "s3_bucket_name",
  102. "s3_object_key",
  103. None,
  104. {"foo": "bar"},
  105. Scope.SCENARIO,
  106. timedelta(1),
  107. "qux",
  108. )
  109. Config.configure_s3_object_data_node(a, b, c, d, e, f, extra_args, scope, vp, property=k)
  110. assert len(Config.data_nodes) == 2