2015-12-20 14:11:39 +00:00
|
|
|
import collections
|
2021-02-28 16:08:27 +00:00
|
|
|
from typing import Dict, Union
|
2021-02-22 18:04:23 +00:00
|
|
|
import unittest
|
2015-12-20 10:26:30 +00:00
|
|
|
|
2021-02-22 18:02:13 +00:00
|
|
|
|
2015-12-20 12:12:54 +00:00
|
|
|
class NotImplementedByController(unittest.SkipTest, NotImplementedError):
|
2021-02-28 16:08:27 +00:00
|
|
|
def __str__(self) -> str:
|
2021-02-22 18:02:13 +00:00
|
|
|
return "Not implemented by controller: {}".format(self.args[0])
|
|
|
|
|
2015-12-20 10:43:55 +00:00
|
|
|
|
2015-12-22 00:56:01 +00:00
|
|
|
class ImplementationChoice(unittest.SkipTest):
|
2021-02-28 16:08:27 +00:00
|
|
|
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
|
|
|
|
2015-12-20 10:26:30 +00:00
|
|
|
class OptionalExtensionNotSupported(unittest.SkipTest):
|
2021-02-28 16:08:27 +00:00
|
|
|
def __str__(self) -> str:
|
2021-02-22 18:02:13 +00:00
|
|
|
return "Unsupported extension: {}".format(self.args[0])
|
|
|
|
|
2015-12-20 10:26:30 +00:00
|
|
|
|
|
|
|
class OptionalSaslMechanismNotSupported(unittest.SkipTest):
|
2021-02-28 16:08:27 +00:00
|
|
|
def __str__(self) -> str:
|
2021-02-22 18:02:13 +00:00
|
|
|
return "Unsupported SASL mechanism: {}".format(self.args[0])
|
|
|
|
|
2015-12-20 10:26:30 +00:00
|
|
|
|
2019-12-08 20:26:21 +00:00
|
|
|
class CapabilityNotSupported(unittest.SkipTest):
|
2021-02-28 16:08:27 +00:00
|
|
|
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
|
|
|
|
2021-02-27 09:36:30 +00:00
|
|
|
class IsupportTokenNotSupported(unittest.SkipTest):
|
2021-02-28 16:08:27 +00:00
|
|
|
def __str__(self) -> str:
|
2021-02-27 09:36:30 +00:00
|
|
|
return "Unsupported ISUPPORT token: {}".format(self.args[0])
|
|
|
|
|
|
|
|
|
2021-02-26 23:21:23 +00:00
|
|
|
class ChannelModeNotSupported(unittest.SkipTest):
|
2021-02-28 16:08:27 +00:00
|
|
|
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):
|
2021-02-28 16:08:27 +00:00
|
|
|
def __str__(self) -> str:
|
2021-02-26 23:21:23 +00:00
|
|
|
return "Unsupported extban: {} ({})".format(self.args[0], self.args[1])
|
|
|
|
|
|
|
|
|
2015-12-22 18:55:48 +00:00
|
|
|
class NotRequiredBySpecifications(unittest.SkipTest):
|
2021-02-28 16:08:27 +00:00
|
|
|
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-22 18:55:48 +00:00
|
|
|
|
2015-12-23 18:39:34 +00:00
|
|
|
class SkipStrictTest(unittest.SkipTest):
|
2021-02-28 16:08:27 +00:00
|
|
|
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
|
|
|
|
2015-12-22 17:54:06 +00:00
|
|
|
class TextTestResult(unittest.TextTestResult):
|
2021-02-28 16:08:27 +00:00
|
|
|
def getDescription(self, test: unittest.TestCase) -> str:
|
2021-02-22 18:02:13 +00:00
|
|
|
if hasattr(test, "description"):
|
2021-02-28 16:08:27 +00:00
|
|
|
doc_first_lines = test.description() # type: ignore
|
2015-12-22 17:54:06 +00:00
|
|
|
else:
|
|
|
|
doc_first_lines = test.shortDescription()
|
2021-02-22 18:02:13 +00:00
|
|
|
return "\n".join((str(test), doc_first_lines or ""))
|
|
|
|
|
2015-12-22 17:54:06 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2015-12-22 17:54:06 +00:00
|
|
|
resultclass = TextTestResult
|
|
|
|
|
2021-02-28 16:08:27 +00:00
|
|
|
def run(
|
|
|
|
self, test: Union[unittest.TestSuite, unittest.TestCase]
|
|
|
|
) -> unittest.TestResult:
|
2015-12-20 10:26:30 +00:00
|
|
|
result = super().run(test)
|
2015-12-22 17:54:06 +00:00
|
|
|
assert self.resultclass is TextTestResult
|
2015-12-20 10:26:30 +00:00
|
|
|
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:"
|
|
|
|
)
|
2021-02-28 16:08:27 +00:00
|
|
|
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))
|
2015-12-20 10:26:30 +00:00
|
|
|
return result
|