Package: verify
Verify is a painless assertion library for Python.LinksProject:https://github.com/dgilland/verifyDocumentation:http://verify.readthedocs.orgPyPI:https://pypi.python.org/pypi/verify/TravisCI:https://travis-ci.org/dgilland/verifyQuickstartInstall using pip:pip install verifyVerify some value using multiple assertions:fromverifyimportexpect,Not,Truthy,Falsy,Less,Greaterexpect(5*5,Truthy(),Not(Falsy),Greater(15),Less(30))Verify using your own assert functions:defis_just_right(value):assertvalue=='just right','Not just right!'# Passesexpect('just right',is_just_right)# Failstry:expect('too cold',is_just_right)exceptAssertionError:raiseNOTE:The assert function should return a truthy value, otherwise,expectwill treat the falsy return from the function as an indication that it failed and subsequently raise it’s ownAssertionError.Verify using your own predicate functions:defis_awesome(value):return'awesome'invaluedefis_more_awesome(value):returnvalue>'awesome'expect('so awesome',is_awesome,is_more_awesome)Verify using chaining syntax:expect(1).Truthy().Number().NotBoolean().Not(is_awesome)Verify withoutexpectsince theverifyassertions can be used on their own:importverify# These would pass.verify.Truthy(1)verify.Equal(2,2)verify.Greater(3,2)# These would fail with an AssertionErrorverify.Truthy(0)verify.Equal(2,3)verify.Greater(2,3)If you’d prefer to seeassertbeing used, allverifyassertions will returnTrueif noAssertionErroris raised:assertTruthy(1)assertexpect(1,Truthy(),Number())Multiple Syntax StylesThere are several syntax styles available to help construct more natural sounding assertion chains.Expect…To BeUseexpectwith theto_bealiases. All Pascal case assertions haveto_be_*andto_not_be_*prefixes (with a few expections).expect(something).to_be_int().to_be_less_or_equal(5).to_be_greater_or_equal(1)expect(something_else).to_not_be_float().to_be_number()Ensure…IsUseensurewithisaliases. All Pascal case assertions haveis_*andis_not_*prefixes (with a few expections).ensure(something).is_int().is_less_or_equal(5).is_greater_or_equal(1)ensure(something_else).is_not_float().is_number()ClassicalUseexpectorensurewith the Pascal case assertions.ensure(something).Int().LessOrEqual(5).GreaterOrEqual(1)expect(something_else).Float().Number()NOTE:While it’s suggested to not mix styles, each of the assertion syntaxes are available with bothexpectandensure. So you can callexpect(..).is_int()as well asensure(..).to_be_int().Naming Convention ExceptionsAs mentioned above, there are some assertions that have nonstandard aliases:Not:not_,does_not,to_fail, andfailsPredicate:does,to_pass, andpassesAll:all_,does_all, andpasses_allNotAll:not_all,does_not_all, andfails_allAny:any_,does_any, andpasses_anyNotAny:not_any,does_not_any, andfails_anyMatch:to_match,is_matchandmatchesNotMatch:to_not_match,is_not_matchanddoes_not_matchIs:to_beandis_Contains:to_containandcontainsNotContains:to_not_containanddoes_not_containContainsOnly:to_contain_onlyandcontains_onlyNotContainsOnly:to_not_contain_onlyanddoes_not_contain_onlyLength:to_have_lengthandhas_lengthNotLength:to_not_have_lengthanddoes_not_have_lengthValidatorsAll of the validators inverifyare callables that can be used in two contexts:By themselves as inEqual(a, b)which will raise anAssertionErrorif false.In combination withexpectas inexpect(a, Equal(b))which could also raise anAssertionError.The available validators are:ValidatorDescriptionTruthyAssert thatbool(a).FalsyAssert thatnot bool(a).NotAssert that a callable doesn’t raise anAssertionError.PredicateAssert thatpredicate(a).AllAssert that all of the list of predicates evaluateaas truthy.NotAllAssertnot All.AnyAssert that any of the list of predicates evaluateaas truthy.NotAnyAssertnot Any.EqualAssert thata == b.NotEqualAssertnot Equal.MatchAssert thatamatches regular expressionb.NotMatchAssertnot Match.IsAssert thata is b.IsNotAssertnot Is.IsTrueAssert thata is True.IsNotTrueAssertnot IsTrue.IsFalseAssert thata is False.IsNotFalseAssertnot IsFalse.IsNoneAssert thata is None.IsNotNoneAssertnot IsNone.TypeAssert thatisinstance(a, b).NotTypeAssertnot Type.BooleanAssert thatisinstance(a, bool).NotBooleanAssertnot Boolean.StringAssert thatisinstance(a, (str, unicode)).NotStringAssertnot String.DictAssert thatisinstance(a, dict).NotDictAssertnot Dict.ListAssert thatisinstance(a, list).NotListAssertnot List.TupleAssert thatisinstance(a, tuple).NotTupleAssertnot Tuple.DateAssert thatisinstance(a, datetime.date).NotDateAssertnot Date.DateStringAssert thatamatches the datetime format stringb.NotDateStringAssertnot DateString.IntAssert thatisinstance(a, int).NotIntAssertnot Int.FloatAssert thatisinstance(a, float).NotFloatAssertnot Float.NumberAssert thatisinstance(a, (int, float, Decimal, long)).NotNumberAssertnot Number.InAssert thata in b.NotInAssertnot In.ContainsAssert thatb in a.NotContainsAssertnot Contains.ContainsOnlyAssert that values frombare the only ones contained ina.NotContainsOnlyAssertnot ContainsOnly.SubsetAssert thatais a subset ofb.NotSubsetAssertnot Subset.SupersetAssert thatais a superset ofb.NotSupersetAssertnot Superset.UniqueAssert thatacontains unique items.NotUniqueAssertnot Unique.LengthAssert thatb <= len(a) <= c.NotLengthAssert thatnot Length.Greater/GreaterThanAssert thata > b.GreaterEqual/GreaterOrEqualAssert thata >= b.Less/LessThanAssert thata < b.LessEqual/LessOrEqualAssert thata <= b.BetweenAssert thatb <= a <= c.NotBetweenAssertnot Between.PositiveAssert thata > 0.NegativeAssert thata < 0.EvenAssert thata % 2 == 0.OddAssert thata % 2 != 1.MonotoneAssert thatais monotonic with respect tob().IncreasingAssert thatais monotonically increasing.StrictlyIncreasingAssert thatais strictly increasing.DecreasingAssert thatais monotonically decreasing.StrictlyDecreasingAssert thatais strictly decreasing.For more details, please see the full documentation athttp://verify.readthedocs.org.