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.4 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # Copyright 2020-2021 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. """
  16. Description: This file is used for some common util.
  17. """
  18. import os
  19. from unittest.mock import Mock
  20. import pytest
  21. from flask import Response
  22. from mindinsight.conf import settings
  23. from mindinsight.datavisual.utils import tools
  24. from mindinsight.debugger.proto import ms_graph_pb2
  25. from mindinsight.debugger.stream_handler.graph_handler import GraphHandler
  26. from mindinsight.debugger.session_manager import SessionManager
  27. GRAPH_PROTO_FILE = os.path.join(
  28. os.path.dirname(__file__), '../../../utils/resource/graph_pb/lenet.pb'
  29. )
  30. DEBUGGER_BASE_URL = '/v1/mindinsight/debugger/sessions/0/'
  31. DEBUGGER_TEST_BASE_DIR = os.path.dirname(__file__)
  32. DEBUGGER_EXPECTED_RESULTS = os.path.join(DEBUGGER_TEST_BASE_DIR, 'expect_results')
  33. def init_graph_handler():
  34. """Init graph proto."""
  35. with open(GRAPH_PROTO_FILE, 'rb') as file_handler:
  36. content = file_handler.read()
  37. graph = ms_graph_pb2.GraphProto()
  38. graph.ParseFromString(content)
  39. graph_handler = GraphHandler()
  40. graph_handler.put(graph)
  41. return graph_handler
  42. @pytest.fixture(scope='session')
  43. def app_client():
  44. """This fixture is flask server."""
  45. packages = ["mindinsight.backend.debugger"]
  46. settings.ENABLE_DEBUGGER = True
  47. mock_obj = Mock(return_value=packages)
  48. tools.find_app_package = mock_obj
  49. from mindinsight.backend.application import APP
  50. APP.response_class = Response
  51. client = APP.test_client()
  52. original_val = settings.ENABLE_RECOMMENDED_WATCHPOINTS
  53. settings.ENABLE_RECOMMENDED_WATCHPOINTS = False
  54. try:
  55. yield client
  56. finally:
  57. settings.ENABLE_RECOMMENDED_WATCHPOINTS = original_val
  58. SessionManager.get_instance().online_session.stop()