Skip to main content

Integrity Check

This package is the python version of a cross-language api for runtime internal tests.

How to use

Install the package (pip install integrity-check)

At the top of one of your python source code files put from integrity_check import Integrity

then you can do things like:

Integrity.check(a == b, "expected {} to be same as {}", a, b)
or
Integrity.check(a == b, a, b)
or even just
Integrity.check(a == b)

The main function is check, but the full list of functions is:

    check(condition, *msg)
    checkNotNone(test, *msg)
    checkIsBool(test, *msg)
    checkIsBoolOrNone(test, *msg)
    checkIsString(test, *msg)
    checkIsStringOrNone(test, *msg)
    checkStringNotNoneOrEmpty(test, *msg)
    checkIsValidNumber(test, *msg)
    checkIsValidNumberOrNone(test, *msg)
    checkIsFunction(test, *msg)
    checkIsFunctionOrNone(test, *msg)

    fail(*msg)

In all cases the *msg parameters work like this:

check*(test) - the exception will contain a default message
check*(test, var1) - the message will be just the string representaiton of var1
check*(test, var1, var2, ... varN) - the message will be the string representaitons of the vars in the format "var1, var2, ..., varN"
check*(test, "the vars are {} {}", var1, var2) - the message will substitute the string representations of va1, var2 into the {}
check*(test, var1, var2, " and {} ", var3) - the message will be "var1, var2 and var3"

there can be as many message parameters as you like. Note that if a variable is a string and happens to contain {} then it will be used in subsequent substitutions.

Example

from integrity_check import Integrity

def myComplicatedFunction(aNumber, callback, aName):
    Integrity.checkIsValidNumberOrNone(aNumber)
    Integrity.checkIsFunction(callback)
    Integrity.checkStringNotNoneOrEmpty(aName)

    handle = callback(aName)
    Integrity.checkNotNone(handle, "expected valid handle, aName was {}", aName)

    diameter = someOtherFunction(handle)
    Integrity.check(diameter >= 0, "expected non-negative diameter, was {}", diameter)

What are the advantages of using Integrity?

Consistent api across languages

If you jump around from one language to another, it is nice to have a consistent way of testing your assumptions regardless of what language you are in. For example:

Python: Integrity.check(a == b, "some text {}", a)
JavaScript: Integrity.check(a == b, "some text {}", a)
C#: Integrity.Check(a == b, "some text {}", a)

There are minor consession made to language conventions. For example, in c# the function names are capitalised.

Delayed and safe string building

The components of the message string are only used if the integrity check fails. This means that the execution time of the check is minimised. The building of the string is guarenteed not to error.

Compact format

If you did not use Integrity (or similar), and wrote the check out by hand, it would look something like:

if(a != b):
	raise ValueError("some text " + str(a))

note that there is potentional for the creation of the message within ValueError(~) to cause a problem, if, for example, the developer forgot to put str() around an int.

Metadata

Release files for integrity-check 1.3.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for integrity-check 1.3.4
File Size Uploaded Provenance Actions
integrity-check-1.3.4.tar.gz 4.4 kB Without provenance Details for integrity-check-1.3.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for integrity-check 1.3.4
File Interpreter ABI Platform Actions
integrity_check-1.3.4-py3-none-any.whl Python 3 none any Details for integrity_check-1.3.4-py3-none-any.whl

Total release size: 9.7 kB

Release files / integrity-check-1.3.4.tar.gz

Download URL integrity-check-1.3.4.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
549bb5a08c3d363a1cad3b51ed7270249b6846cab12be0882e15aa29f17562fe
BLAKE2b-256 checksum
How to use checksums
18b3015b8d40700dce9d1d4db09d0aa73ab83a946173d464cbf256614572658e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

Release files / integrity_check-1.3.4-py3-none-any.whl

Download URL integrity_check-1.3.4-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
73a0c5654a44937ed091fef88085b8debe375afc833f0728b934dfac9fb4fa83
BLAKE2b-256 checksum
How to use checksums
9b6ca60acec80d2ab31587d0ac1883f1cd00708bb014da83b91a1d7f39f4218b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

Security for integrity-check 1.3.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page