diff --git a/pycommons/tests/__init__.py b/pycommons/tests/__init__.py index e5500d9..8d75952 100644 --- a/pycommons/tests/__init__.py +++ b/pycommons/tests/__init__.py @@ -6,6 +6,29 @@ __author__ = "Shashank Sharma" __email__ = "shashankrnr32@gmail.com" +from .case import IsolatedAsyncIOTestCase, TestCase +from .condition import skip, skip_if, skip_unless, flaky, fails +from .exception import raises +from .parametrized import cases, TestData +from .utils import TestUtils + +__all__ = [ + "IsolatedAsyncIOTestCase", + "TestCase", + "TestData", + "TestUtils", + "__author__", + "__email__", + "__version__", + "cases", + "fails", + "flaky", + "raises", + "skip", + "skip_if", + "skip_unless", +] + # Used to automatically set version number from GitHub actions # as well as not break when being tested locally try: diff --git a/pycommons/tests/case.py b/pycommons/tests/case.py index c931c96..11ce6b7 100644 --- a/pycommons/tests/case.py +++ b/pycommons/tests/case.py @@ -5,14 +5,59 @@ class TestCase(unittest.TestCase): - def assertSame(self, expected: Any, actual: Any, msg: Optional[str] = None): + """ + Extensions to python's `unittest.TestCase` class. Provides additional + assertion methods and helper methods. + """ + + def assertSame(self, expected: Any, actual: Any, msg: Optional[str] = None) -> None: + """ + Assert if the expected object is same as the actual object, i.e. their ids match. + + Args: + expected: Expected object + actual: Actual object + msg: message + + Returns: + None + """ if id(expected) != id(actual): self.fail(msg) def assertNotSame(self, expected: Any, actual: Any, msg: Optional[str] = None): + """ + Assert if the expected object is not the same as the actual object, + i.e. their ids do not match. + + Args: + expected: Expected object + actual: Actual object + msg: message + + Returns: + None + """ if id(expected) == id(actual): self.fail(msg) def assertThat(self, matcher: Matcher[Any], actual: Any, msg: Optional[str] = None): + """ + Provides matcher type assertion. A matcher is a functional interface + with a single abstract method `match` that takes an object (`actual`) + and returns True if the matching is successful. + + Args: + matcher: A matcher object + actual: The object to be matched + msg: message + + Returns: + None + """ if not matcher.match(actual): self.fail(msg) + + +class IsolatedAsyncIOTestCase(unittest.IsolatedAsyncioTestCase, TestCase): + ... diff --git a/pycommons/tests/condition.py b/pycommons/tests/condition.py index ced2870..153f4d7 100644 --- a/pycommons/tests/condition.py +++ b/pycommons/tests/condition.py @@ -2,7 +2,7 @@ import logging import unittest -__all__ = ["fails", "skip", "skip_if"] +__all__ = ["fails", "skip", "skip_if", "skip_unless", "flaky"] from typing import Callable, Optional from unittest import TestCase