irctest/irctest/runner.py

92 lines
3.0 KiB
Python
Raw Normal View History

2015-12-20 14:11:39 +00:00
import collections
from typing import Dict, Union
2021-02-22 18:04:23 +00:00
import unittest
2021-02-22 18:02:13 +00:00
2015-12-20 12:12:54 +00:00
class NotImplementedByController(unittest.SkipTest, NotImplementedError):
def __str__(self) -> str:
2021-02-22 18:02:13 +00:00
return "Not implemented by controller: {}".format(self.args[0])
2015-12-22 00:56:01 +00:00
class ImplementationChoice(unittest.SkipTest):
def __str__(self) -> str:
2021-02-22 18:02:13 +00:00
return (
"Choice in the implementation makes it impossible to "
"perform a test: {}".format(self.args[0])
)
2015-12-22 00:56:01 +00:00
class OptionalExtensionNotSupported(unittest.SkipTest):
def __str__(self) -> str:
2021-02-22 18:02:13 +00:00
return "Unsupported extension: {}".format(self.args[0])
class OptionalSaslMechanismNotSupported(unittest.SkipTest):
def __str__(self) -> str:
2021-02-22 18:02:13 +00:00
return "Unsupported SASL mechanism: {}".format(self.args[0])
2019-12-08 20:26:21 +00:00
class CapabilityNotSupported(unittest.SkipTest):
def __str__(self) -> str:
2021-02-22 18:02:13 +00:00
return "Unsupported capability: {}".format(self.args[0])
2019-12-08 20:26:21 +00:00
class IsupportTokenNotSupported(unittest.SkipTest):
def __str__(self) -> str:
return "Unsupported ISUPPORT token: {}".format(self.args[0])
2021-02-26 23:21:23 +00:00
class ChannelModeNotSupported(unittest.SkipTest):
def __str__(self) -> str:
2021-02-26 23:21:23 +00:00
return "Unsupported channel mode: {} ({})".format(self.args[0], self.args[1])
class ExtbanNotSupported(unittest.SkipTest):
def __str__(self) -> str:
2021-02-26 23:21:23 +00:00
return "Unsupported extban: {} ({})".format(self.args[0], self.args[1])
class NotRequiredBySpecifications(unittest.SkipTest):
def __str__(self) -> str:
2021-02-22 18:02:13 +00:00
return "Tests not required by the set of tested specification(s)."
2015-12-23 18:39:34 +00:00
class SkipStrictTest(unittest.SkipTest):
def __str__(self) -> str:
2021-02-22 18:02:13 +00:00
return "Tests not required because strict tests are disabled."
2015-12-23 18:39:34 +00:00
class TextTestResult(unittest.TextTestResult):
def getDescription(self, test: unittest.TestCase) -> str:
2021-02-22 18:02:13 +00:00
if hasattr(test, "description"):
doc_first_lines = test.description() # type: ignore
else:
doc_first_lines = test.shortDescription()
2021-02-22 18:02:13 +00:00
return "\n".join((str(test), doc_first_lines or ""))
class TextTestRunner(unittest.TextTestRunner):
2015-12-20 12:47:30 +00:00
"""Small wrapper around unittest.TextTestRunner that reports the
number of tests that were skipped because the software does not support
an optional feature."""
2021-02-22 18:02:13 +00:00
resultclass = TextTestResult
def run(
self, test: Union[unittest.TestSuite, unittest.TestCase]
) -> unittest.TestResult:
result = super().run(test)
assert self.resultclass is TextTestResult
if result.skipped:
print()
2021-02-22 18:02:13 +00:00
print(
"Some tests were skipped because the following optional "
"specifications/mechanisms are not supported:"
)
msg_to_count: Dict[str, int] = collections.defaultdict(lambda: 0)
2015-12-20 14:11:39 +00:00
for (test, msg) in result.skipped:
msg_to_count[msg] += 1
for (msg, count) in sorted(msg_to_count.items()):
2021-02-22 18:02:13 +00:00
print("\t{} ({} test(s))".format(msg, count))
return result