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.

test_explain_loader.py 2.3 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. """UT for explainer.manager.explain_manager"""
  16. import os
  17. import threading
  18. import time
  19. from unittest.mock import patch
  20. from mindinsight.datavisual.data_access.file_handler import FileHandler
  21. from mindinsight.explainer.manager.explain_loader import ExplainLoader
  22. from mindinsight.explainer.manager.explain_loader import _LoaderStatus
  23. from mindinsight.explainer.manager.explain_parser import ExplainParser
  24. def abc():
  25. FileHandler.is_file('aaa')
  26. print('after')
  27. class TestExplainLoader:
  28. """Test explain loader class."""
  29. @patch.object(ExplainParser, 'list_events')
  30. @patch.object(FileHandler, 'list_dir')
  31. @patch.object(FileHandler, 'is_file')
  32. @patch.object(os, 'stat')
  33. def test_stop(self, mock_stat, mock_is_file, mock_list_dir, mock_list_events):
  34. """Test stop function."""
  35. mock_is_file.return_value = True
  36. mock_list_dir.return_value = ['events.summary.123.host_explain']
  37. mock_list_events.return_value = (True, False, None)
  38. class _MockStat:
  39. def __init__(self, _):
  40. self.st_ctime = 1
  41. self.st_mtime = 1
  42. self.st_size = 1
  43. mock_stat.side_effect = _MockStat
  44. loader = ExplainLoader(
  45. loader_id='./summary_dir',
  46. summary_dir='./summary_dir')
  47. def _stop_loader(explain_loader):
  48. time.sleep(0.01)
  49. assert explain_loader.status == _LoaderStatus.LOADING.value
  50. explain_loader.stop()
  51. thread = threading.Thread(target=_stop_loader, args=[loader], daemon=True)
  52. thread.start()
  53. loader.load()
  54. assert loader.status == _LoaderStatus.STOP.value