Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

assertify

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

assertify

  • 3.0
  • PyPI
  • Socket score

Maintainers
1

Maintenance Code Style License: MIT codecov

assertify

assertify -- assert or (ver)ify -- is a Flexible, and Extendable python3.6+ library for evaluating an expression by returning False or raising an AssertionError or the given Exception if the expression is invalid.

Key Features:
  • Easy: Designed to make it easy to evaluate an expression and return True/False or raise an AssertionError or Exception.
  • Great Developer Experience: Being fully typed makes it great for editor support.
  • There is More!!!:
    • unittest_assertions: Assertify is built on top of the unittest_assertions, which is a library that converts the assertions from unittest to standalone assertions.

Installation

pip install assertify

Example

raises an appropriate exception by default.

Exception Example

AssertifyIsInstance will raise a TypeError by default, but you can also specify any other type of exception.

from assertifiers.identity import AssertifyIsInstance

is_instance = AssertifyIsInstance()
is_instance("example str", int)  # raise TypeError("'example str' is not an instance of <class 'int'>")

Assertion Example

Specify AssertionError to be raised

from assertifiers.identity import AssertifyIsInstance

is_instance = AssertifyIsInstance(raises=AssertionError)
is_instance("example str", int)  # raise AssertionError("'example str' is not an instance of <class 'int'>")

Boolean Example

If raises=None assertify will return a Boolean.

from assertifiers.identity import AssertifyIsInstance

is_instance = AssertifyIsInstance(raises=None)
print(is_instance("example str", int))  # False

Predicate (Partial Function) Example

from functools import partial
from assertifiers.identity import AssertifyIsInstances

is_instance = AssertifyIsInstances(must_be_instance_of=any)
predicate_is_instance = partial(is_instance,classes=[int,float])
print(predicate_is_instance(obj=7.62)) # True

Assertifiers

Comparison

AssertifierExpressionraises
AssertifyEqualassertify first == secondValueError
AssertifyNotEqualassertify first != SecondValueError
AssertifyAlmostEqualassertify first ~= secondValueError
AssertifyNotAlmostEqualassertify first !~= secondValueError
AssertifyCountEqualassertify len(first) == len(second)ValueError
AssertifyMultilineEqualassertify first.splitlines() == second.splitlines()ValueError
AssertifySequenceEqualassertify seq1 == seq2ValueError
AssertifyListEqualassertify list1 == list2ValueError
AssertifyTupleEqualassertify tuple1 == tuple2ValueError
AssertifySetEqualassertify set1 == set2ValueError
AssertifyDictEqualassertify dict1 == dict2ValueError
AssertifyLessassertify a < bValueError
AssertifyLessEqualassertify a <= bValueError
AssertifyGreaterassertify a > bValueError
AssertifyGreaterassertify a >= bValueError

Container

AssertifierExpressionraises
AssertifyInassertify member in containerValueError
AssertifyNotInassertify member not in containerValueError

Control

AssertifierExpressionraises
AssertifyRaisesassertify function raises expected_exceptionValueError
AssertifyWarnsassertify function warns expected_warningValueError
AssertifyLogsassertify logger(level)ValueError

Identity

AssertifierExpressionraises
AssertifyIsassertify exp1 is exp2ValueError
AssertifyIsNotassertify exp1 is not exp2ValueError
AssertifyIsNoneassertify obj is NoneValueError
AssertifyIsNotNoneassertify obj is not NoneValueError
AssertifyIsInstanceassertify isinstance(obj,class)TypeError
AssertifyIsInstancesassertify isinstance(obj,cls) for cls in classesTypeError
AssertifyIsNotInstanceassertify not isinstance(obj,class)TypeError
AssertifyIsNotInstancesassertify not isinstance(obj,cls) for cls in classesTypeError

Logic

AssertifierExpressionraises
AssertifyTrueassertify expr is TrueValueError
AssertifyFalseassertify expr is FalseValueError

Regex

AssertifierExpressionraises
AssertifyRaisesRegexassertify expected_regex in expected_exception_messageValueError
AssertifyWarnsRegexassertify expected_regex in expected_warning_messageValueError
AssertifyRegexassertify text in expected_regexValueError
AssertifyNotRegexassertify text not in expected_regexValueError

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc