From 5d4473b7672ef804ab8818554699a71498bf331b Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Wed, 23 Dec 2015 19:39:34 +0100 Subject: [PATCH] Add option --loose. --- irctest/__main__.py | 8 +++++++- irctest/cases.py | 4 +++- irctest/runner.py | 4 ++++ irctest/server_tests/test_channel_operations.py | 3 ++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/irctest/__main__.py b/irctest/__main__.py index 91ec889..b14e1f4 100644 --- a/irctest/__main__.py +++ b/irctest/__main__.py @@ -29,6 +29,7 @@ def main(args): exit(1) _IrcTestCase.controllerClass = controller_class _IrcTestCase.show_io = args.show_io + _IrcTestCase.strictTests = not args.loose if args.specification: try: _IrcTestCase.testedSpecifications = frozenset( @@ -43,7 +44,8 @@ def main(args): Specifications) print('Testing {} on specification(s): {}'.format( controller_class.software_name, - ', '.join(map(lambda x:x.value, _IrcTestCase.testedSpecifications)))) + ', '.join(sorted(map(lambda x:x.value, + _IrcTestCase.testedSpecifications))))) ts = module.discover() testRunner = TextTestRunner( verbosity=args.verbose, @@ -67,6 +69,10 @@ parser.add_argument('-s', '--specification', type=str, action='append', 'Use this option multiple times to test with multiple ' 'specifications. If it is not given, defaults to all.') .format(list(map(str, Specifications)))) +parser.add_argument('-l', '--loose', action='store_true', + help='Disables strict checks of conformity to the specification. ' + 'Strict means the specification is unclear, and the most restrictive ' + 'interpretation is choosen.') args = parser.parse_args() diff --git a/irctest/cases.py b/irctest/cases.py index 273978a..a8a03c4 100644 --- a/irctest/cases.py +++ b/irctest/cases.py @@ -356,7 +356,7 @@ class OptionalityHelper: class SpecificationSelector: - def requiredBySpecification(*specifications): + def requiredBySpecification(*specifications, strict=False): specifications = frozenset( Specifications.of_name(s) if isinstance(s, str) else s for s in specifications) @@ -368,6 +368,8 @@ class SpecificationSelector: def newf(self): if specifications.isdisjoint(self.testedSpecifications): raise runner.NotRequiredBySpecifications() + if strict and not self.strictTests: + raise runner.SkipStrictTest() return f(self) return newf return decorator diff --git a/irctest/runner.py b/irctest/runner.py index 2859c4c..7eec323 100644 --- a/irctest/runner.py +++ b/irctest/runner.py @@ -23,6 +23,10 @@ class NotRequiredBySpecifications(unittest.SkipTest): def __str__(self): return 'Tests not required by the set of tested specification(s).' +class SkipStrictTest(unittest.SkipTest): + def __str__(self): + return 'Tests not required because strict tests are disabled.' + class TextTestResult(unittest.TextTestResult): def getDescription(self, test): if hasattr(test, 'description'): diff --git a/irctest/server_tests/test_channel_operations.py b/irctest/server_tests/test_channel_operations.py index 63cfde8..3e187fa 100644 --- a/irctest/server_tests/test_channel_operations.py +++ b/irctest/server_tests/test_channel_operations.py @@ -10,7 +10,8 @@ from irctest.irc_utils import ambiguities from irctest.irc_utils.message_parser import Message class JoinTestCase(cases.BaseServerTestCase): - @cases.SpecificationSelector.requiredBySpecification('RFC1459', 'RFC2812') + @cases.SpecificationSelector.requiredBySpecification('RFC1459', 'RFC2812', + strict=True) def testJoinAllMessages(self): """“If a JOIN is successful, the user receives a JOIN message as confirmation and is then sent the channel's topic (using RPL_TOPIC) and