conftest.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #
  2. # Copyright 2018-2022 Elyra Authors
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. from pathlib import Path
  17. import pytest
  18. from elyra.metadata.metadata import Metadata
  19. from elyra.metadata.schemaspaces import ComponentCatalogs
  20. from elyra.metadata.manager import MetadataManager
  21. from elyra.pipeline.component_catalog import ComponentCache
  22. pytest_plugins = ["jupyter_server.pytest_plugin"]
  23. TEST_CATALOG_NAME = "new_test_catalog"
  24. KFP_COMPONENT_CACHE_INSTANCE = {
  25. "display_name": "KFP Example Components",
  26. "metadata": {"runtime_type": "KUBEFLOW_PIPELINES", "categories": ["examples"]},
  27. "schema_name": "elyra-kfp-examples-catalog",
  28. }
  29. AIRFLOW_TEST_OPERATOR_CATALOG = {
  30. "display_name": "Airflow Test Operator",
  31. "metadata": {
  32. "runtime_type": "APACHE_AIRFLOW",
  33. "base_path": str(Path(__file__).parent / "elyra" / "tests" / "pipeline" / "resources" / "components"),
  34. "paths": ["airflow_test_operator.py"],
  35. },
  36. "schema_name": "local-file-catalog",
  37. }
  38. @pytest.fixture
  39. def component_cache(jp_environ):
  40. """
  41. Initialize a component cache
  42. """
  43. # Create new instance and load the cache
  44. component_cache = ComponentCache.instance(emulate_server_app=True)
  45. component_cache.load()
  46. yield component_cache
  47. component_cache.cache_manager.stop()
  48. ComponentCache.clear_instance()
  49. @pytest.fixture
  50. def catalog_instance(component_cache, request):
  51. """Creates an instance of a component catalog and removes after test."""
  52. instance_metadata = request.param
  53. instance_name = "component_cache"
  54. md_mgr = MetadataManager(schemaspace=ComponentCatalogs.COMPONENT_CATALOGS_SCHEMASPACE_ID)
  55. catalog = md_mgr.create(instance_name, Metadata(**instance_metadata))
  56. component_cache.wait_for_all_cache_tasks()
  57. yield catalog
  58. md_mgr.remove(instance_name)
  59. @pytest.fixture
  60. def metadata_manager_with_teardown(jp_environ):
  61. """
  62. This fixture provides a MetadataManager instance for certain tests that modify the component
  63. catalog. This ensures the catalog instance is removed even when the test fails
  64. """
  65. metadata_manager = MetadataManager(schemaspace=ComponentCatalogs.COMPONENT_CATALOGS_SCHEMASPACE_ID)
  66. # Run test with provided metadata manager
  67. yield metadata_manager
  68. # Remove test catalog
  69. try:
  70. if metadata_manager.get(TEST_CATALOG_NAME):
  71. metadata_manager.remove(TEST_CATALOG_NAME)
  72. except Exception:
  73. pass
  74. # Set Elyra server extension as enabled (overriding server_config fixture from jupyter_server)
  75. @pytest.fixture
  76. def jp_server_config():
  77. return {"ServerApp": {"jpserver_extensions": {"elyra": True}}}