Socket
Socket
Sign inDemoInstall

assertive

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

assertive

A small assertion library for testing


Maintainers
1

Assertive

Assertive is a testing library that provides declarative assertions to you python tests.

Core of assertive

Assertive is built on two core concepts:

  1. Criteria
  2. Assertions

Criteria

Criteria are declarative statements that can be used with assert statements to give a richer test experience.

assert 5 == is_greater_than(4)
assert 5 == is_odd()
assert 5 != is_even()

Criteria can also be composed with logical operators to give a richer experience in writing tests

assert 5 == is_greater_than(4) & is_less_than(6) # Using AND
assert 5 == is_even() | is_less_than(6) # Using OR
assert 5 == is_even() ^ is_odd() # Using XOR
assert 5 == ~is_even()  # Using INVERT

Assertions

Criteria can be used with python's inbuilt assert statement or you can also use Assertions from the assertive library. The key difference between assert and Assertions is that Assertions give a more detailed Assertion Error when the test fails.

To use Assertions you simple use the assert_that() function

assert_that(5).matches(is_greater_than(4))
assert_that(5).matches(is_odd())
assert_that(5).matches(is_greater_than(4) & is_odd())
assert_that(5).does_not_match(is_even())

assert 5 == is_greater_than(4)
assert 5 == is_odd()
assert 5 == is_greater_than(4) & is_odd()
assert 5 != is_even()

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