Skip to main content

Prod safe Python assert library

Project description

prod_assert

The What?

prod_assert is a Python library containing prod safe assert function. This library contains asserts functions as prod_assert (the base assert), assert_eq, assert_in, etc. Asserts in this library, by default, raise AssertionFailed excetption, with the option to raise AssertionError.

The Why?

A senior at work annoyed me by saying I can't use assert in prod, so here are asserts I can use in prod.

Example

from prod_assert import assert_eq

# Nothing happens
assert_eq(1, 1)

# Assert fails and raises AssertionFailde with the default message
assert_eq(1, 2)
### prod_assert._main.AssertionFailed: Condition 1 == 2 is false

# Assert fails and raises AssertionFailed with the custom message
assert_eq(1, 2, "One does not equal two")
### prod_assert._main.AssertionFailed: One does not equal two

# Assert fails and raises AssertionError with the default message
assert_eq(1, 2, assertion_exception=AssertionError)
### AssertionError: Condition 1 == 2 is false

Functions and Classes

class AssertionFailed(Exception):
    pass


AssertionException = Union[AssertionFailed, AssertionError]


def prod_assert(
    condition: bool,
    message: str,
    assertion_exception: AssertionException=AssertionFailed
) -> None:


def assert_eq(
    a: Any,
    b: Any,
    message: Optional[str]=None,
    assertion_exception: AssertionException=AssertionFailed
) -> None:
   

def assert_not_eq(
    a: Any,
    b: Any,
    message: Optional[str]=None,
    assertion_exception: AssertionException=AssertionFailed
) -> None:


def assert_true(
    a: Any,
    message: Optional[str]=None,
    assertion_exception: AssertionException=AssertionFailed
) -> None:
 

def assert_false(
    a: Any,
    message: Optional[str]=None,
    assertion_exception: AssertionException=AssertionFailed
) -> None:


def assert_is(
    a: Any,
    b: Any,
    message: Optional[str]=None,
    assertion_exception: AssertionException=AssertionFailed
) -> None:


def assert_is_not(
    a: Any,
    b: Any,
    message: Optional[str]=None,
    assertion_exception: AssertionException=AssertionFailed
) -> None:


def assert_is_none(
    a: Any,
    message: Optional[str]=None,
    assertion_exception: AssertionException=AssertionFailed
) -> None:


def assert_is_not_none(
    a: Any,
    message: Optional[str]=None,
    assertion_exception: AssertionException=AssertionFailed
) -> None:


def assert_in(
    a: Any,
    b: Container[Any],
    message: Optional[str]=None,
    assertion_exception: AssertionException=AssertionFailed
) -> None:


def assert_not_in(
    a: Any,
    b: Container[Any],
    message: Optional[str]=None,
    assertion_exception: AssertionException=AssertionFailed
) -> None:


def assert_is_instance(
    a: Any,
    b: Any,
    message: Optional[str]=None,
    assertion_exception: AssertionException=AssertionFailed
) -> None:


def assert_not_is_instance(
    a: Any,
    b: Any,
    message: Optional[str]=None,
    assertion_exception: AssertionException=AssertionFailed
) -> None:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

prod_assert-1.0.0.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

prod_assert-1.0.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file prod_assert-1.0.0.tar.gz.

File metadata

  • Download URL: prod_assert-1.0.0.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for prod_assert-1.0.0.tar.gz
Algorithm Hash digest
SHA256 df04ca52e84fc70a2e178f1770c91a5c0c4eab1e6dfe30d20b03799e804b5957
MD5 26cb837d4522c57f0ed982f3f4af24c9
BLAKE2b-256 451744f804d806449a32eb1ea051be3e605e67fa7ad114f913a7663a64ef0c1a

See more details on using hashes here.

File details

Details for the file prod_assert-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: prod_assert-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for prod_assert-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 57107f19a1fccd1b90e48c4d60fdfe62ca6daeed7d00282f397ea45ee0091c31
MD5 4ea88fe973c29eb146b6221ec8583ef2
BLAKE2b-256 5868422bb3b03290a34757c00ccb5486c8d221618f79933cf8df0b80018cf7b8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page