Add pytest unit testing framework
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
"""This module provides utility fixtures for testing."""
|
||||
from typing import Tuple
|
||||
|
||||
from _pytest.fixtures import FixtureRequest
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture(params=[True, False])
|
||||
def boolean(request: FixtureRequest) -> bool:
|
||||
return request.param
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def boolean1(boolean: bool) -> Tuple[bool]:
|
||||
return (boolean,)
|
||||
|
||||
|
||||
@pytest.fixture(params=[True, False])
|
||||
def boolean2(request: FixtureRequest, boolean: bool) -> Tuple[bool, bool]:
|
||||
return (boolean, request.param)
|
||||
|
||||
|
||||
@pytest.fixture(params=[True, False])
|
||||
def boolean3(
|
||||
request: FixtureRequest, boolean2: Tuple[bool, bool]
|
||||
) -> Tuple[bool, bool, bool]:
|
||||
return (boolean2[0], boolean2[1], request.param)
|
||||
|
||||
|
||||
# …
|
||||
@@ -0,0 +1,24 @@
|
||||
"""This module provides utility functions for testing."""
|
||||
from typing import Generator, Tuple
|
||||
from unittest.mock import Mock
|
||||
|
||||
|
||||
def AsyncMock(*args, **kwargs):
|
||||
"""Mocks a asyncronous coroutine which can be called with 'await'."""
|
||||
m = Mock(*args, **kwargs)
|
||||
|
||||
async def mock_coro(*args, **kwargs):
|
||||
return m(*args, **kwargs)
|
||||
|
||||
mock_coro.mock = m
|
||||
return mock_coro
|
||||
|
||||
|
||||
def list_true_once_each(length: int) -> Generator[Tuple[bool, ...], None, None]:
|
||||
"""Yields tuples of bools with exactly one entry being True, starting left.
|
||||
|
||||
Args:
|
||||
length: Length of the resulting tuples
|
||||
"""
|
||||
for i in range(length):
|
||||
yield tuple(i == j for j in range(length))
|
||||
Reference in New Issue
Block a user