1- fassert: Fuzzy assert
1+ ^ fassert$ : Fuzzy assert
22---------------------
33
4- Assert in your tests only a subset of data that matters
4+ Fuzzy assert in your tests only a subset of data that matters
55
66```
77from fassert import fassert
@@ -18,20 +18,75 @@ fassert(
1818) # key2: value2 is ignored as it's not defined in the template
1919
2020fassert(
21- {"key": "value"},
21+ {"key": "value", "abc": "value" },
2222 # You can nest and combine the fuzzy matching types in containers
2323 {re.compile(r"[a-z]{3}"): "value"}
2424)
2525
26+ fassert(
27+ [1, {"very": {"nested": {"dictionary": "data"}}}, {"not": "this"}],
28+ # Isn't this cool?
29+ [{"very": {re.compile(".{6}"): {"dictionary": lambda x: len(x) == 4}}}]
30+ )
31+
2632# Template can contain callables as well
2733fassert("value", lambda x: x == "value")
2834
2935try:
36+ fassert("expected", "to not match")
3037 fassert({"a": "b"}, {"c": "d"}) # This will fail, {"c":"d"} is not in the target data
38+ fassert([1, 2, 3], [4])
39+ fassert("string", b"string") # bytes != string in fassert
3140except AssertionError:
3241 pass # All the examples within the try block above will raise this exception
3342```
3443
3544In fassert, you can define a template to match your data against.
3645When you use a type that is a container (e.g. list, tuple, dict, etc...), then only the data that you defined in the template will be asserted.
3746All the addition data in the container will be ignored
47+
48+ Did you know this project is also dedicated to have ** 0 dependencies** on other packages?
49+
50+ Installation
51+ ------------
52+
53+ From PyPI:
54+ ` pip install fassert `
55+
56+ Locally:
57+ ```
58+ pip install .
59+
60+ # Run tests with:
61+ python -m unittest discover -s tests/
62+ ```
63+
64+
65+
66+ Advanced usage
67+ --------------
68+
69+ ` fassert ` function is equivalent in creating a default ` FuzzyAssert() ` object and calling match on it.
70+ You can configure some behaviour of the fuzzy matcher via the object attributes like so:
71+
72+ ```
73+ from fassert import FuzzyAssert
74+
75+ fasserter = FuzzyAssert()
76+ # Eval functions is turned on by default
77+ fasserter.match("value", lambda x: x == "value")
78+
79+ fasserter.eval_functions = False
80+ # This will now raise Assertion error
81+ fasserter.match("value", lambda x: x == "value")
82+
83+ ```
84+
85+ Bellow is an overview of the configurable options and their default values
86+
87+ | Name | Default value | Description |
88+ | -------------------------------| ---------------| ----------------------------------------------------------------------------------------|
89+ | eval_functions | True | Enable template matching as callable functions |
90+ | regex_allowed | True | Enable matching regexes from template agains strings in the data |
91+ | fuzzy_sequence_types | False | Ignore types of similar sequence types when matching the template (e.g. tuple vs list) |
92+ | check_minimum_sequence_length | True | Check that the data has a minimum length of greater or equal to the template |
0 commit comments