test_DirectNotify.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import pytest
  2. from panda3d import core
  3. from direct.directnotify import DirectNotify, Logger, Notifier
  4. CATEGORY_NAME = 'test'
  5. @pytest.fixture
  6. def notify():
  7. notify = DirectNotify.DirectNotify()
  8. notify.newCategory(CATEGORY_NAME)
  9. return notify
  10. def test_categories():
  11. notify = DirectNotify.DirectNotify()
  12. assert len(notify.getCategories()) == 0
  13. assert notify.getCategory(CATEGORY_NAME) is None
  14. notifier = notify.newCategory(CATEGORY_NAME, logger=Logger.Logger())
  15. assert isinstance(notifier, Notifier.Notifier)
  16. assert notify.getCategories() == [CATEGORY_NAME]
  17. def test_setDconfigLevels(notify):
  18. config = core.ConfigVariableString('notify-level-' + CATEGORY_NAME, '')
  19. notifier = notify.getCategory(CATEGORY_NAME)
  20. config.value = 'error'
  21. notify.setDconfigLevels()
  22. assert notifier.getSeverity() == core.NS_error
  23. config.value = 'warning'
  24. notify.setDconfigLevels()
  25. assert notifier.getSeverity() == core.NS_warning
  26. config.value = 'info'
  27. notify.setDconfigLevels()
  28. assert notifier.getSeverity() == core.NS_info
  29. config.value = 'debug'
  30. notify.setDconfigLevels()
  31. assert notifier.getSeverity() == core.NS_debug
  32. def test_setVerbose(notify):
  33. notifier = notify.getCategory(CATEGORY_NAME)
  34. notifier.setWarning(False)
  35. notifier.setInfo(False)
  36. notifier.setDebug(False)
  37. notify.setVerbose()
  38. assert notifier.getWarning()
  39. assert notifier.getInfo()
  40. assert notifier.getDebug()
  41. def test_giveNotify(notify):
  42. class HasNotify:
  43. notify = None
  44. notify.giveNotify(HasNotify)
  45. assert isinstance(HasNotify.notify, Notifier.Notifier)