Package: conjecture
ConjectureA pythonic assertion library.🛠 InstallingPoetrypoetry add conjecturepippip install conjecture🎓 UsageBasicA basic assertion.>>>importconjecture>>>assert5==conjecture.has(lambdav:v<10)>>>assert5==conjecture.has(lambdav:v>10)Traceback (most recent call last):File"<stdin>", line1, in<module>AssertionErrorBuilt-in conjecturesGeneralMatching none.>>>importconjecture>>>assertNone==conjecture.none()Matching anything.>>>importconjecture>>>assertNone==conjecture.anything()>>>assert123==conjecture.anything()>>>assert"abc"==conjecture.anything()MappingMatching keys.>>>importconjecture>>>assert{"a":1}==conjecture.has_key("a")>>>assert{"a":1}==conjecture.has_key("a",of=1)>>>assert{"a":1}==conjecture.has_key("a",of=conjecture.less_than(5))ObjectMatching instances of a class.>>>importconjecture>>>assert123==conjecture.instance_of(int)>>>assert"abc"==conjecture.instance_of((str,bytes))Matching values.>>>importconjecture>>>assert123==conjecture.equal_to(123)>>>assert"abc"==conjecture.equal_to("abc")Matching attributes.>>>importconjecture>>>assert1==conjecture.has_attribute("__class__")>>>assert1==conjecture.has_attribute("__class__",of=int)>>>assert1==conjecture.has_attribute("__class__",of=conjecture.instance_of(type))Rich orderingMatching lesser values.>>>importconjecture>>>assert5==conjecture.greater_than(1)>>>assert5==conjecture.greater_than_or_equal_to(1)Matching greater values.>>>importconjecture>>>assert1==conjecture.less_than(5)>>>assert1==conjecture.less_than_or_equal_to(5)SizeMatching empty collections.>>>importconjecture>>>assertlist()==conjecture.empty()>>>assertset()==conjecture.empty()>>>asserttuple()==conjecture.empty()>>>assertdict()==conjecture.empty()Matching length of collections.>>>importconjecture>>>assert[1,2,3,4,5]==conjecture.length_of(5)>>>assert[1,2,3]==conjecture.length_of(conjecture.less_than(5))StringMatching string prefixes.>>>importconjecture>>>assert"foo bar baz"==conjecture.prefixed_with("foo")>>>assertb"foo bar baz"==conjecture.prefixed_with(b"foo")Matching string suffixes.>>>importconjecture>>>assert"foo bar baz"==conjecture.suffixed_with("baz")>>>assertb"foo bar baz"==conjecture.suffixed_with(b"baz")Combined conjecturesMatching all conditions.>>>importconjecture>>>assert5==conjecture.has(lambdav:v<=5)&conjecture.has(lambdav:v=>5)>>>assert6==conjecture.has(lambdav:v<=5)&conjecture.has(lambdav:v=>5)Traceback (most recent call last):File"<stdin>", line1, in<module>AssertionError>>>assert5==conjecture.all_of(...conjecture.has(lambdav:v<=5),...conjecture.has(lambdav:v=>5)...)>>>assert6==conjecture.all_of(...conjecture.has(lambdav:v<=5),...conjecture.has(lambdav:v=>5)...)Traceback (most recent call last):File"<stdin>", line1, in<module>AssertionErrorMatching any conditions.>>>importconjecture>>>assert0==conjecture.has(lambdav:v==5)|conjecture.has(lambdav:v==0)>>>assert5==conjecture.has(lambdav:v==5)|conjecture.has(lambdav:v==0)>>>assert6==conjecture.has(lambdav:v==5)|conjecture.has(lambdav:v==0)Traceback (most recent call last):File"<stdin>", line1, in<module>AssertionError>>>assert5==conjecture.any_of(...conjecture.has(lambdav:v==5),...conjecture.has(lambdav:v==0)...)>>>assert6==conjecture.any_of(...conjecture.has(lambdav:v==5),...conjecture.has(lambdav:v==0)...)Traceback (most recent call last):File"<stdin>", line1, in<module>AssertionErrorNegationA negative assertion.>>>importconjecture>>>assert5!=conjecture.has(lambdav:v==10)>>>assert5==~conjecture.has(lambdav:v==10)>>>assert10==~conjecture.has(lambdav:v==10)Traceback (most recent call last):File"<stdin>", line1, in<module>AssertionError⚖️ LicenceThis project is licensed under theMIT licence.All documentation and images are licenced under theCreative Commons Attribution-ShareAlike 4.0 International License.📝 MetaThis project usesSemantic Versioning.