From ef8adc7edef07d929ccbdea813227bc39618684a Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Tue, 22 Dec 2015 18:54:06 +0100 Subject: [PATCH] Rename irctest.optionality to irctest.runner, and clean code a bit. --- irctest/__main__.py | 4 ++-- irctest/basecontrollers.py | 2 +- irctest/cases.py | 8 ++++---- irctest/{optionality.py => runner.py} | 13 ++++++++++++- irctest/server_tests/test_channel_operations.py | 12 ++++++------ 5 files changed, 25 insertions(+), 14 deletions(-) rename irctest/{optionality.py => runner.py} (77%) diff --git a/irctest/__main__.py b/irctest/__main__.py index 4af430e..0bdc15b 100644 --- a/irctest/__main__.py +++ b/irctest/__main__.py @@ -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, ) diff --git a/irctest/basecontrollers.py b/irctest/basecontrollers.py index cf9e5b8..813a762 100644 --- a/irctest/basecontrollers.py +++ b/irctest/basecontrollers.py @@ -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. diff --git a/irctest/cases.py b/irctest/cases.py index e915533..74aa147 100644 --- a/irctest/cases.py +++ b/irctest/cases.py @@ -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): diff --git a/irctest/optionality.py b/irctest/runner.py similarity index 77% rename from irctest/optionality.py rename to irctest/runner.py index a9875ef..d71275a 100644 --- a/irctest/optionality.py +++ b/irctest/runner.py @@ -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 ' diff --git a/irctest/server_tests/test_channel_operations.py b/irctest/server_tests/test_channel_operations.py index 5eae683..2e636c3 100644 --- a/irctest/server_tests/test_channel_operations.py +++ b/irctest/server_tests/test_channel_operations.py @@ -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