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.

mock.py 1.7 kB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Copyright 2019 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. Mock for ut test case.
  17. """
  18. class MockLogger:
  19. """Mock logger in DataLoader and collect log message for verification."""
  20. log_msg = {'error': None, 'warning': None, 'info': None}
  21. @classmethod
  22. def error(cls, msg, *args):
  23. """Mock logger.error() and collect error message."""
  24. cls.log_msg['error'] = msg.replace("%s", "{}").replace("%r", "'{}'").format(*args)
  25. @classmethod
  26. def warning(cls, msg, *args):
  27. """Mock logger.warning() and collect warning message."""
  28. cls.log_msg['warning'] = msg.replace("%s", "{}").replace("%r", "'{}'").format(*args)
  29. @classmethod
  30. def info(cls, msg, *args):
  31. """Mock logger.info() and collect info message."""
  32. cls.log_msg['info'] = msg.replace("%s", "{}").replace("%r", "'{}'").format(*args)
  33. @classmethod
  34. def debug(cls, msg, *args):
  35. """Mock logger.debug() and collect debug message."""
  36. cls.log_msg['debug'] = msg.replace("%s", "{}").replace("%r", "'{}'").format(*args)