Rename irctest.optionality to irctest.runner, and clean code a bit.

This commit is contained in:
Valentin Lorentz
2015-12-22 18:54:06 +01:00
parent 95db1d4dfd
commit ef8adc7ede
5 changed files with 25 additions and 14 deletions

View File

@ -5,7 +5,7 @@ import unittest
import functools
import importlib
from .cases import _IrcTestCase
from .optionality import OptionalityReportingTextTestRunner
from .runner import TextTestRunner
from .basecontrollers import BaseClientController, BaseServerController
def main(args):
@ -29,7 +29,7 @@ def main(args):
_IrcTestCase.controllerClass = controller_class
_IrcTestCase.show_io = args.show_io
ts = module.discover()
testRunner = OptionalityReportingTextTestRunner(
testRunner = TextTestRunner(
verbosity=args.verbose,
descriptions=True,
)

View File

@ -6,7 +6,7 @@ import time
import subprocess
import psutil
from .optionality import NotImplementedByController
from .runner import NotImplementedByController
class _BaseController:
"""Base class for software controllers.

View File

@ -8,7 +8,7 @@ import supybot.utils
from . import client_mock
from . import authentication
from . import optionality
from . import runner
from .irc_utils import message_parser
from .irc_utils import capabilities
@ -16,7 +16,7 @@ class _IrcTestCase(unittest.TestCase):
"""Base class for test cases."""
controllerClass = None # Will be set by __main__.py
def shortDescription(self):
def description(self):
method_doc = self._testMethodDoc
if not method_doc:
return ''
@ -311,12 +311,12 @@ class OptionalityHelper:
def checkSaslSupport(self):
if self.controller.supported_sasl_mechanisms:
return
raise optionality.NotImplementedByController('SASL')
raise runner.NotImplementedByController('SASL')
def checkMechanismSupport(self, mechanism):
if mechanism in self.controller.supported_sasl_mechanisms:
return
raise optionality.OptionalSaslMechanismNotSupported(mechanism)
raise runner.OptionalSaslMechanismNotSupported(mechanism)
def skipUnlessHasMechanism(mech):
def decorator(f):

View File

@ -19,12 +19,23 @@ class OptionalSaslMechanismNotSupported(unittest.SkipTest):
def __str__(self):
return 'Unsupported SASL mechanism: {}'.format(self.args[0])
class OptionalityReportingTextTestRunner(unittest.TextTestRunner):
class TextTestResult(unittest.TextTestResult):
def getDescription(self, test):
if hasattr(test, 'description'):
doc_first_lines = test.description()
else:
doc_first_lines = test.shortDescription()
return '\n'.join((str(test), doc_first_lines))
class TextTestRunner(unittest.TextTestRunner):
"""Small wrapper around unittest.TextTestRunner that reports the
number of tests that were skipped because the software does not support
an optional feature."""
resultclass = TextTestResult
def run(self, test):
result = super().run(test)
assert self.resultclass is TextTestResult
if result.skipped:
print()
print('Some tests were skipped because the following optional '

View File

@ -5,7 +5,7 @@ Section 3.2 of RFC 2812
from irctest import cases
from irctest import client_mock
from irctest import optionality
from irctest import runner
from irctest.irc_utils import ambiguities
from irctest.irc_utils.message_parser import Message
@ -155,7 +155,7 @@ class JoinTestCase(cases.BaseServerTestCase):
try:
m = self.getMessage(1)
if m.command == '482':
raise optionality.ImplementationChoice(
raise runner.ImplementationChoice(
'Channel creators are not opped by default, and '
'channel modes to no allow regular users to change '
'topic.')
@ -187,7 +187,7 @@ class JoinTestCase(cases.BaseServerTestCase):
try:
m = self.getMessage(1)
if m.command == '482':
raise optionality.ImplementationChoice(
raise runner.ImplementationChoice(
'Channel creators are not opped by default.')
self.assertMessageEqual(m, command='TOPIC')
except client_mock.NoMessageException:
@ -288,7 +288,7 @@ class JoinTestCase(cases.BaseServerTestCase):
try:
m = self.getMessage(1)
if m.command == '482':
raise optionality.ImplementationChoice(
raise runner.ImplementationChoice(
'Channel creators are not opped by default.')
self.assertMessageEqual(m, command='KICK')
except client_mock.NoMessageException:
@ -328,10 +328,10 @@ class JoinTestCase(cases.BaseServerTestCase):
try:
m = self.getMessage(1)
if m.command == '482':
raise optionality.OptionalExtensionNotSupported(
raise runner.OptionalExtensionNotSupported(
'Channel creators are not opped by default.')
if m.command in {'401', '403'}:
raise optionality.NotImplementedByController(
raise runner.NotImplementedByController(
'Multi-target KICK')
except client_mock.NoMessageException:
# The RFCs do not say KICK must be echoed