Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions pycommons/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
47 changes: 46 additions & 1 deletion pycommons/tests/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
...
2 changes: 1 addition & 1 deletion pycommons/tests/condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down