0.10.0 - 2020/01/07
is_decimalwas added which validates if an object is an instance ofdecimal.Decimal.is_numberwas modified to also consider instances ofdecimal.Decimalas numbers.
0.9.0 - 2020/01/07
Explanationobjects now have a new attributesdatawhich holds the data that was used to generate the explanation. Foris_transformedand any of it's subclasses this will contain the transformed data. For classes likeis_dict_wherewhere other predicates are ran on parts of it's data it will replace these parts with the data on the explanation of that result.Explanationobjects now have a new methodby_paththat yields tuples of(path, subexplanation).Explanationobjects now have a more human readable result when you callrepr.- Added
is_blankandis_not_blankwherevalueis consideredblankif and only ifnot valueholds. - Added
is_prefor adding preconditions to predicates. - Using
is_ifwithelse_valid=Falseis now deprecated, in this case you should be usingis_preinstead. - Changed
if_matchso that it now always usessearchinstead ofmatchorfullmatchbased on thefullparameter to find the match. Behaviour of match and fullmatch can still be achieved by using the^and$characters in your pattern. - Added the
match_as_dataoption tois_matchwhich when set toTruewill replace the explanation objectsdataattribute with the match object. - Added the
is_decodable_json_wherepredicate which is a combination ofis_decodable_whereandis_json_wheresince these two are often used together. - Changed
is_withso that if a non callable value is provided as a transform function it will be changed into a function that always returns this value. - Added
is_with_contextwhich is similar tois_withbut operators on the current context instead of the data. - Changed
Wrapper.wrapto return whatever it wrapped. - Added
is_if.casesandis_when.casesas a shorthand for creating long if ... elif ... elif ... else structures without having to nest. - Added
default_contexttoutilsto easily specify default values for the predicate context. - Fixed
utils.Wrapperincorrectly calling the wrapped predicate so that prerequisites were ignored.
0.8.0 - 2019/04/10
- Refactored automatic predicate conversion to convert
dict,tuple, andlistinstances tois_dict_where,is_tuple_where, andis_list_whererespectively. For normal data this should be functionally equivalent but now you can nest other predicates inside this data. - Moved
to_predfromis_eqto it's own module. - Simplify
assert_validinto just an assertion function instead of a function generator.
0.7.1 - 2018/07/03
- Refactored
is_json_where, andis_json. - Added
is_bytes,is_decodable_where, andis_decodable.
0.7.0 - 2018/03/01
- Made assertions generated by
assert_validaccept context arguments. These will then be forwarded to the underlying predicate. Theassert_validclass itself also accepts a context argument in it's constructor that serves as a base context for the generated assertion. - Simplified
is_tranformedandis_json_wherea bit. This change is backwards incompatible. - Simplified
utils.Wrapperto only wrap predicates. This way predicate testing using isinstance works for wrapper predicates as well.
0.6.0 - 2018/01/17
Wrapperclass has been updated, it now doesn't just wrap function calls but also underlying attributes of the wrapped object. You now change what is wrapped by callingWrapper.wrap(obj)instead ofWrapper.func = obj.- The dict predicates (
is_dict_where,is_superdict_where,is_subdict_where) saw a small overhaul in how their explanation objects work. Instead of just giving an explanation that the keys are incorrect with details about which keys are extra and which are missing the explanation now gives explanation objects that statenot_allowedormissingfor these keys while also evaluating the keys that were present and could be evaluated. is_iterable_whereand it's subclasses (is_tuple_of,is_list_of) saw a small overhaul in how their explanation objects work. Instead of just giving an explanation that the length is incorrect the explanation now gives explanation objects that stateoverflowormissingfor when data is too long or too short for the incorrect indexes while also evaluating the elements that were present and could be evaluated.- Transform methods were added to
is_cond, withtrans_condandtrans_predyou can alter the data before it gets entered into the conds or preds respectively. By default they just do nothing with the data. is_withwas added. Here you specify a dict of keys mapping to functions and a predicate that then stores the output of that function when the data gets entered for that key. Then in the following predicate you can useGet-objects to reference to that specific key. See the tests for a good example.is_bytewas added which checks for an int in range 0 to 255.
0.5.1 - 2018/01/12
- Fix bug where
is_dict_ofdidn't check if the value was a dict beforehand but only if it was iterable, thus leading to an exception being thrown when a value was evaluated that was iterable but not a dict.
0.5.0 - 2018/01/12
- Introduction of this changelog.
is_dict_wherenow also accepts two dicts as arguments to indicate required and optional keys respectively.- The
dictmethod onExplanationobjects now has an extra keyword argumentinclude_details=Trueto specify if you want it to put the details in the dict. Also if the details are some kind of structure made up out of dicts, lists and tuples it now traverses these structures to also convert allExplanationobjects within them to dicts. (Small breaking change) Wrapperutility class introduced, this just wraps a function that you can change at any moment by setting thefunc-attribute. Useful for when you want some kind of recursion in your predicate structure.- Predicate classes
is_optionalandis_nullablewere added, given a predicate they become a predicate that holds when either the given predicate holds or the value isNone. There are two versions becauseis_optionalandis_nullableuseis_noneandis_nullunder the hood respectively. is_condnow wraps its conds and preds withis_eqwhen they are not callable. Consistency :)- Almost complete rewrite without breaking any compatibility making all
predicates be instances of a subclass of
is_valid.base.Predicateinstead of loose functions. This allows for some neat small things:- You can now use
~predinstead ofis_not(pred), alsois_not(is_not(pred))just gives backprednow. - You can now use
pred1 | pred2instead ofis_any(pred1, pred2), alsois_any(pred1, is_any(pred2, pred3))does the same asis_any(pred1, pred2, pred3)now. - You can now use
pred1 & pred2instead ofis_all(pred1, pred2), alsois_all(pred1, is_all(pred2, pred3))does the same asis_all(pred1, pred2, pred3)now. - You can now use
pred.explain(value)instead ofpred(value, explain=True).
- You can now use
0.4.0 - 2017/11/26
- Latest version before introduction of this changelog.