Module integer_sequences.helper

Expand source code
from helper.helpers import (
    assert_equal,
    check_item_list,
    check_key_dict,
    loads,
    dumps,
    ROOTPATH,
    DATAPATH,
    LOGPATH,
    TESTPATH,
)

__all__ = [
    "check_item_list",
    "check_key_dict",
    "assert_equal",
    "loads",
    "dumps",
    "ROOTPATH",
    "DATAPATH",
    "LOGPATH",
    "TESTPATH",
]

Sub-modules

integer_sequences.helper.helpers

Functions

def assert_equal(expected: Any, result: Any) ‑> NoneType

Asserts that expected is equal to result. To be called from tests.

Parameters

expected: The expected outcome of some function call. result: The resulted outcome of some function call.

Raises an AssertionError when equality fails.

Expand source code
def assert_equal(expected: Any, result: Any) -> None:
    """
    Asserts that expected is equal to result. To be called from tests.

    Parameters:
        expected: The expected outcome of some function call.
        result: The resulted outcome of some function call.

    Raises an AssertionError when equality fails.
    """
    assert expected == result
def check_item_list(item: Any, lst: List[Any]) ‑> NoneType

Raises a MissingItem if a particular item is NOT contained in a particular lst.

Parameters

item: The item to check for. lst: The list to check in.

Raises a MissingItem exception if item not in lst.

Expand source code
def check_item_list(item: Any, lst: List[Any]) -> None:
    """
    Raises a ``MissingItem`` if a particular ``item`` is NOT contained in a particular ``lst``.

    Parameters:
        item: The item to check for.
        lst: The list to check in.

    Raises a MissingItem exception if ``item`` not in ``lst``.
    """
    if item not in lst:
        raise MissingItem(item, lst)
def check_key_dict(key: Any, dictionary: Dict[Any, Any]) ‑> NoneType

Raises a MissingItem if a particular key is NOT contained in a particular dictionary.

Parameters

key: The key to check for. dictionary: The dictionary to check in.

Raises a MissingItem exception if key not in dictionary.keys()

Expand source code
def check_key_dict(key: Any, dictionary: Dict[Any, Any]) -> None:
    """
    Raises a ``MissingItem`` if a particular ``key`` is NOT contained in a particular ``dictionary``.

    Parameters:
        key: The key to check for.
        dictionary: The dictionary to check in.

    Raises a MissingItem exception if ``key`` not in ``dictionary.keys()``
    """
    if key not in dictionary.keys():
        raise MissingItem(key, dictionary)
def dumps(filename: str, data: Any) ‑> bool

Dumps data to a file using pickle.

Returns true on success. Returns false on failure.

Expand source code
def dumps(filename: str, data: Any) -> bool:
    """
    Dumps data to a file using pickle.

    Returns true on success.
    Returns false on failure.
    """
    try:
        with open(f"{filename}.pkl", "wb") as file:
            dump(data, file)
        return True
    except OSError:
        return False
def loads(filename: str) ‑> Any

Loads data from a file using pickle.

Expand source code
def loads(filename: str) -> Any:
    """
    Loads data from a file using pickle.
    """
    with open(f"{filename}.pkl", "rb") as pickle:
        return load(pickle)