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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. """
  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. GRAPH_PROTO_FILE = os.path.join(
  27. os.path.dirname(__file__), '../../../utils/resource/graph_pb/lenet.pb'
  28. )
  29. DEBUGGER_BASE_URL = '/v1/mindinsight/debugger'
  30. DEBUGGER_EXPECTED_RESULTS = os.path.join(os.path.dirname(__file__), 'expect_results')
  31. def init_graph_handler():
  32. """Init graph proto."""
  33. with open(GRAPH_PROTO_FILE, 'rb') as file_handler:
  34. content = file_handler.read()
  35. graph = ms_graph_pb2.GraphProto()
  36. graph.ParseFromString(content)
  37. graph_handler = GraphHandler()
  38. graph_handler.put(graph)
  39. return graph_handler
  40. @pytest.fixture(scope='session')
  41. def app_client():
  42. """This fixture is flask server."""
  43. packages = ["mindinsight.backend.debugger", "mindinsight.backend.conditionmgr"]
  44. settings.ENABLE_DEBUGGER = True
  45. mock_obj = Mock(return_value=packages)
  46. tools.find_app_package = mock_obj
  47. from mindinsight.backend.application import APP
  48. from mindinsight.backend.debugger.debugger_api import BACKEND_SERVER
  49. APP.response_class = Response
  50. client = APP.test_client()
  51. original_val = settings.ENABLE_RECOMMENDED_WATCHPOINTS
  52. settings.ENABLE_RECOMMENDED_WATCHPOINTS = False
  53. try:
  54. yield client
  55. finally:
  56. settings.ENABLE_RECOMMENDED_WATCHPOINTS = original_val
  57. BACKEND_SERVER.stop()