From 7891ccf65e308ad8a8dfab9b918cf0d7bfe4eba9 Mon Sep 17 00:00:00 2001 From: Shashank Sharma Date: Thu, 13 Jul 2023 20:55:18 +0530 Subject: [PATCH 1/2] Add docstrings, Fix relative paths --- pycommons/tests/__init__.py | 23 ++++++++++++++++++ pycommons/tests/case.py | 45 +++++++++++++++++++++++++++++++++++- pycommons/tests/condition.py | 2 +- 3 files changed, 68 insertions(+), 2 deletions(-) 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..42ad5ae 100644 --- a/pycommons/tests/case.py +++ b/pycommons/tests/case.py @@ -5,14 +5,57 @@ 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 From b97776ed206e4742aa1db2f98314a61980ee1f1d Mon Sep 17 00:00:00 2001 From: Shashank Sharma Date: Thu, 13 Jul 2023 20:56:44 +0530 Subject: [PATCH 2/2] Fix codeformat --- pycommons/tests/case.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/pycommons/tests/case.py b/pycommons/tests/case.py index 42ad5ae..11ce6b7 100644 --- a/pycommons/tests/case.py +++ b/pycommons/tests/case.py @@ -27,23 +27,25 @@ def assertSame(self, expected: Any, actual: Any, msg: Optional[str] = None) -> N 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. + 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 + Args: + expected: Expected object + actual: Actual object + msg: message - Returns: - None - """ + 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. + 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