Add option --loose.

This commit is contained in:
Valentin Lorentz 2015-12-23 19:39:34 +01:00
parent 4ef79cbe45
commit 5d4473b767
4 changed files with 16 additions and 3 deletions

View File

@ -29,6 +29,7 @@ def main(args):
exit(1) exit(1)
_IrcTestCase.controllerClass = controller_class _IrcTestCase.controllerClass = controller_class
_IrcTestCase.show_io = args.show_io _IrcTestCase.show_io = args.show_io
_IrcTestCase.strictTests = not args.loose
if args.specification: if args.specification:
try: try:
_IrcTestCase.testedSpecifications = frozenset( _IrcTestCase.testedSpecifications = frozenset(
@ -43,7 +44,8 @@ def main(args):
Specifications) Specifications)
print('Testing {} on specification(s): {}'.format( print('Testing {} on specification(s): {}'.format(
controller_class.software_name, controller_class.software_name,
', '.join(map(lambda x:x.value, _IrcTestCase.testedSpecifications)))) ', '.join(sorted(map(lambda x:x.value,
_IrcTestCase.testedSpecifications)))))
ts = module.discover() ts = module.discover()
testRunner = TextTestRunner( testRunner = TextTestRunner(
verbosity=args.verbose, 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 ' 'Use this option multiple times to test with multiple '
'specifications. If it is not given, defaults to all.') 'specifications. If it is not given, defaults to all.')
.format(list(map(str, Specifications)))) .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() args = parser.parse_args()

View File

@ -356,7 +356,7 @@ class OptionalityHelper:
class SpecificationSelector: class SpecificationSelector:
def requiredBySpecification(*specifications): def requiredBySpecification(*specifications, strict=False):
specifications = frozenset( specifications = frozenset(
Specifications.of_name(s) if isinstance(s, str) else s Specifications.of_name(s) if isinstance(s, str) else s
for s in specifications) for s in specifications)
@ -368,6 +368,8 @@ class SpecificationSelector:
def newf(self): def newf(self):
if specifications.isdisjoint(self.testedSpecifications): if specifications.isdisjoint(self.testedSpecifications):
raise runner.NotRequiredBySpecifications() raise runner.NotRequiredBySpecifications()
if strict and not self.strictTests:
raise runner.SkipStrictTest()
return f(self) return f(self)
return newf return newf
return decorator return decorator

View File

@ -23,6 +23,10 @@ class NotRequiredBySpecifications(unittest.SkipTest):
def __str__(self): def __str__(self):
return 'Tests not required by the set of tested specification(s).' 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): class TextTestResult(unittest.TextTestResult):
def getDescription(self, test): def getDescription(self, test):
if hasattr(test, 'description'): if hasattr(test, 'description'):

View File

@ -10,7 +10,8 @@ from irctest.irc_utils import ambiguities
from irctest.irc_utils.message_parser import Message from irctest.irc_utils.message_parser import Message
class JoinTestCase(cases.BaseServerTestCase): class JoinTestCase(cases.BaseServerTestCase):
@cases.SpecificationSelector.requiredBySpecification('RFC1459', 'RFC2812') @cases.SpecificationSelector.requiredBySpecification('RFC1459', 'RFC2812',
strict=True)
def testJoinAllMessages(self): def testJoinAllMessages(self):
"""“If a JOIN is successful, the user receives a JOIN message as """“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 confirmation and is then sent the channel's topic (using RPL_TOPIC) and