You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

conftest.py 2.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # Copyright 2020 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ============================================================================
  15. """The st config for optimizer."""
  16. import os
  17. import shutil
  18. import tempfile
  19. from unittest.mock import Mock
  20. import pytest
  21. from flask import Response
  22. from mindinsight.lineagemgr.cache_item_updater import LineageCacheItemUpdater
  23. from mindinsight.datavisual.data_transform import data_manager
  24. from mindinsight.datavisual.data_transform.data_manager import DataManager
  25. from mindinsight.datavisual.utils import tools
  26. SUMMARY_BASE_DIR = tempfile.NamedTemporaryFile(prefix='test_optimizer_summary_dir_base_').name
  27. MOCK_DATA_MANAGER = DataManager(SUMMARY_BASE_DIR)
  28. MOCK_DATA_MANAGER.register_brief_cache_item_updater(LineageCacheItemUpdater())
  29. MOCK_DATA_MANAGER.start_load_data().join()
  30. @pytest.fixture(scope="session")
  31. def init_summary_logs():
  32. """Create summary directory."""
  33. try:
  34. if os.path.exists(SUMMARY_BASE_DIR):
  35. shutil.rmtree(SUMMARY_BASE_DIR)
  36. permissions = os.R_OK | os.W_OK | os.X_OK
  37. mode = permissions << 6
  38. if not os.path.exists(SUMMARY_BASE_DIR):
  39. os.mkdir(SUMMARY_BASE_DIR, mode=mode)
  40. yield
  41. finally:
  42. if os.path.exists(SUMMARY_BASE_DIR):
  43. shutil.rmtree(SUMMARY_BASE_DIR)
  44. @pytest.fixture
  45. def client():
  46. """This fixture is flask client."""
  47. data_manager.DATA_MANAGER = MOCK_DATA_MANAGER
  48. packages = ["mindinsight.backend.optimizer"]
  49. mock_obj = Mock(return_value=packages)
  50. tools.find_app_package = mock_obj
  51. from mindinsight.backend.application import APP
  52. APP.response_class = Response
  53. app_client = APP.test_client()
  54. yield app_client