GithubHelp home page GithubHelp logo

tybruno / unittest_assertions Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 242 KB

Thin wrapper around the python builtin unittest library allowing developers to use builtin assertions for non-unittest use cases.

License: MIT License

Python 100.00%
unittest python assertify wrapper verification verify functional-testing

unittest_assertions's Introduction

Code Style License: MIT Linting and Testing codecov

unittest_assertions

Thin wrapper around the python builtin unittest allowing developers to use the builtin assertions for non-unittest use cases.

Key Features:

  • Easy: Designed to make it be simple allowing developers to use the builtin unittest assertions for their own use cases.
  • Great Developer Experience: Being fully typed, documented, and tested makes it great for editor support and extension.
  • There is More!!!:
    • assertify: Simple, Flexible, and Extendable python3.6+ library to evaluate an expression and return True/False or raise an AssertionError or Exception.

Installation

pip install unittest-assertions

Examples

from unittest_assertions.identity import AssertIsInstance

assert_is_instance = AssertIsInstance(msg="Raised an AssertionError")
assert_is_instance("example str", int) # raise AssertionError("'example str' is not an instance of <class 'int'> : Raised an AssertionError")
from unittest_assertions import AssertEqual

assert_equal = AssertEqual()
assert_equal(1, 1)
assert_equal(first="hello", second="hello")
from unittest_assertions import AssertNotIn
assert_in = AssertNotIn()
assert_in(member=1, container=[5,2,3])

Asserters

Container

Asserter Expression
AssertIn assert member in container
AssertNotIn assert member not in container

Control

Asserter Expression
AssertRaises assert function raises expected_exception
AssertWarns assert function warns expected_warning
AssertLogs assert logger(level)

Equality

Asserter Expression
AssertEqual assert first == second
AssertNotEqual assert first != second
AssertAlmostEqual assert first ~= second
AssertNotAlmostEqual assert first !~= second
AssertCountEqual assert Counter(list(first) == Counter(list(second))
AssertMultilineEqual assert first.splitlines() == second.splitlines()
AssertSequenceEqual assert seq1 == seq2
AssertListEqual assert list1 == list2
AssertTupleEqual assert tuple1 == tuple2
AssertSetEqual assert set1 == set2
AssertDictEqual assert dict1 == dict2
AssertLess assert a < b
AssertLessEqual assert a <= b
AssertGreater assert a > b
AssertGreater assert a >= b

Identity

Asserter Expression
AssertTrue assert expr is True
AssertFalse assert expr is False
AssertIs assert exp1 is exp2
AssertIsNot assert exp1 is not exp2
AssertIsNone assert obj is None
AssertIsNotNone assert obj is not None
AssertIsInstance assert isinstance(obj,class)
AssertIsNotInstance assert not isinstance(obj,class)

Regex

Asserter Expression
AssertRaisesRegex assert expected_regex in expected_exception_message
AssertWarnsRegex assert expected_regex in expected_warning_message
AssertRegex assert text in expected_regex
AssertNotRegex assert text not in expected_regex

unittest_assertions's People

Contributors

tybruno avatar

Stargazers

 avatar 虫师 avatar Braden Mars avatar

Watchers

James Cloos avatar  avatar

unittest_assertions's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.