drslump / pyshould

Should style asserts based on pyhamcrest
MIT License
38 stars 7 forks source link

please provide example for instring #41

Closed shvasude closed 4 years ago

shvasude commented 4 years ago

I have a string and i have to assert String which is in string of the variable str

like in python, do we have an example for "in" operator in pyshould: str="Example String" if "Example" in str: return True else: return False

drslump commented 4 years ago

this should work

test_str = "My Example String"
test_str | should.have_substring("Example")
shvasude commented 4 years ago

Thanks for this. Curious to know the implementation of have_substring, i don't see in matchers.py that i usually see for other matchers

drslump commented 4 years ago

Actually most matchers are just defined as aliases to the underlying Hamcrest implementation if no customization is required

https://github.com/drslump/pyshould/blob/master/pyshould/matchers.py#L206-L208

For a quick look at all the registered matchers you can run on a terminal python -m pyshould to dump their help.

shvasude commented 4 years ago

Thanks. Helps