test_plugins.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. #
  4. # Maintainer: Jonathan Lange
  5. """
  6. Tests for L{twisted.plugins.twisted_trial}.
  7. """
  8. from twisted.plugin import getPlugins
  9. from twisted.trial import unittest
  10. from twisted.trial.itrial import IReporter
  11. class PluginsTests(unittest.SynchronousTestCase):
  12. """
  13. Tests for Trial's reporter plugins.
  14. """
  15. def getPluginsByLongOption(self, longOption):
  16. """
  17. Return the Trial reporter plugin with the given long option.
  18. If more than one is found, raise ValueError. If none are found, raise
  19. IndexError.
  20. """
  21. plugins = [
  22. plugin for plugin in getPlugins(IReporter)
  23. if plugin.longOpt == longOption]
  24. if len(plugins) > 1:
  25. raise ValueError(
  26. "More than one plugin found with long option %r: %r"
  27. % (longOption, plugins))
  28. return plugins[0]
  29. def test_subunitPlugin(self):
  30. """
  31. One of the reporter plugins is the subunit reporter plugin.
  32. """
  33. subunitPlugin = self.getPluginsByLongOption('subunit')
  34. self.assertEqual('Subunit Reporter', subunitPlugin.name)
  35. self.assertEqual('twisted.trial.reporter', subunitPlugin.module)
  36. self.assertEqual('subunit', subunitPlugin.longOpt)
  37. self.assertIdentical(None, subunitPlugin.shortOpt)
  38. self.assertEqual('SubunitReporter', subunitPlugin.klass)