Text Matchers¶
Matchers that perform text comparisons.
contains_string¶
-
class
hamcrest.library.text.stringcontains.StringContains(substring)¶ Bases:
hamcrest.library.text.substringmatcher.SubstringMatcher
-
hamcrest.library.text.stringcontains.contains_string(substring)¶ Matches if object is a string containing a given string.
- Parameters
string – The string to search for.
This matcher first checks whether the evaluated object is a string. If so, it checks whether it contains
string.Example:
contains_string("def")
will match “abcdefg”.
ends_with¶
-
class
hamcrest.library.text.stringendswith.StringEndsWith(substring)¶ Bases:
hamcrest.library.text.substringmatcher.SubstringMatcher
-
hamcrest.library.text.stringendswith.ends_with(string)¶ Matches if object is a string ending with a given string.
- Parameters
string – The string to search for.
This matcher first checks whether the evaluated object is a string. If so, it checks if
stringmatches the ending characters of the evaluated object.Example:
ends_with("bar")
will match “foobar”.
equal_to_ignoring_case¶
-
class
hamcrest.library.text.isequal_ignoring_case.IsEqualIgnoringCase(string)¶ Bases:
hamcrest.core.base_matcher.BaseMatcher-
describe_to(description)¶ Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters
description – The description to be built or appended to.
-
-
hamcrest.library.text.isequal_ignoring_case.equal_to_ignoring_case(string)¶ Matches if object is a string equal to a given string, ignoring case differences.
- Parameters
string – The string to compare against as the expected value.
This matcher first checks whether the evaluated object is a string. If so, it compares it with
string, ignoring differences of case.Example:
equal_to_ignoring_case("hello world")
will match “heLLo WorlD”.
equal_to_ignoring_whitespace¶
-
class
hamcrest.library.text.isequal_ignoring_whitespace.IsEqualIgnoringWhiteSpace(string)¶ Bases:
hamcrest.core.base_matcher.BaseMatcher-
describe_to(description)¶ Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters
description – The description to be built or appended to.
-
-
hamcrest.library.text.isequal_ignoring_whitespace.equal_to_ignoring_whitespace(string)¶ Matches if object is a string equal to a given string, ignoring differences in whitespace.
- Parameters
string – The string to compare against as the expected value.
This matcher first checks whether the evaluated object is a string. If so, it compares it with
string, ignoring differences in runs of whitespace.Example:
equal_to_ignoring_whitespace("hello world")
will match
"hello world".
matches_regexp¶
-
class
hamcrest.library.text.stringmatches.StringMatchesPattern(pattern)¶ Bases:
hamcrest.core.base_matcher.BaseMatcher-
describe_to(description)¶ Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters
description – The description to be built or appended to.
-
-
hamcrest.library.text.stringmatches.matches_regexp(pattern)¶ Matches if object is a string containing a match for a given regular expression.
- Parameters
pattern – The regular expression to search for.
This matcher first checks whether the evaluated object is a string. If so, it checks if the regular expression
patternmatches anywhere within the evaluated object.
starts_with¶
-
class
hamcrest.library.text.stringstartswith.StringStartsWith(substring)¶ Bases:
hamcrest.library.text.substringmatcher.SubstringMatcher
-
hamcrest.library.text.stringstartswith.starts_with(substring)¶ Matches if object is a string starting with a given string.
- Parameters
string – The string to search for.
This matcher first checks whether the evaluated object is a string. If so, it checks if
stringmatches the beginning characters of the evaluated object.Example:
starts_with("foo")
will match “foobar”.
string_contains_in_order¶
-
class
hamcrest.library.text.stringcontainsinorder.StringContainsInOrder(*substrings)¶ Bases:
hamcrest.core.base_matcher.BaseMatcher-
describe_to(description)¶ Generates a description of the object.
The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
- Parameters
description – The description to be built or appended to.
-
-
hamcrest.library.text.stringcontainsinorder.string_contains_in_order(string1[, string2[, ...]])¶ Matches if object is a string containing a given list of substrings in relative order.
- Parameters
string1,.. – A comma-separated list of strings.
This matcher first checks whether the evaluated object is a string. If so, it checks whether it contains a given list of strings, in relative order to each other. The searches are performed starting from the beginning of the evaluated string.
Example:
string_contains_in_order("bc", "fg", "jkl")
will match “abcdefghijklm”.