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_log_util.py 1.9 kB

5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. LogUtil test.
  16. """
  17. import logging
  18. import pytest
  19. from mindarmour.utils.logger import LogUtil
  20. @pytest.mark.level0
  21. @pytest.mark.platform_arm_ascend_training
  22. @pytest.mark.platform_x86_ascend_training
  23. @pytest.mark.env_card
  24. @pytest.mark.component_mindarmour
  25. def test_logger():
  26. logger = LogUtil.get_instance()
  27. tag = 'Test'
  28. msg = 'i am %s, work in %s'
  29. args = ('tom', 'china')
  30. logger.debug(tag, msg, *args)
  31. logger.info(tag, msg, *args)
  32. logger.error(tag, msg, *args)
  33. logger.warn(tag, msg, *args)
  34. logger.set_level(logging.DEBUG)
  35. logger.debug(tag, msg, *args)
  36. logger.info(tag, msg, *args)
  37. logger.error(tag, msg, *args)
  38. logger.warn(tag, msg, *args)
  39. msg = 'i am tom, work in china'
  40. logger.info(tag, msg)
  41. logger.info(tag, 'accuracy is %f.', 0.995)
  42. logger.debug(tag, 'accuracy is %s.', 0.995)
  43. @pytest.mark.level0
  44. @pytest.mark.platform_arm_ascend_training
  45. @pytest.mark.platform_x86_ascend_training
  46. @pytest.mark.env_card
  47. @pytest.mark.component_mindarmour
  48. def test_value_error():
  49. with pytest.raises(SyntaxError) as e:
  50. assert LogUtil()
  51. assert str(e.value) == 'can not instance, please use get_instance.'
  52. logger = LogUtil.get_instance()
  53. handler = 'logging.Handler(level=1)'
  54. with pytest.raises(ValueError):
  55. logger.add_handler(handler)

MindArmour关注AI的安全和隐私问题。致力于增强模型的安全可信、保护用户的数据隐私。主要包含3个模块:对抗样本鲁棒性模块、Fuzz Testing模块、隐私保护与评估模块。