Ausgabe der neuen DB Einträge
This commit is contained in:
parent
bad48e1627
commit
cfbbb9ee3d
2399 changed files with 843193 additions and 43 deletions
|
|
@ -0,0 +1,13 @@
|
|||
"""Matchers that perform text comparisons."""
|
||||
|
||||
from .isequal_ignoring_case import equal_to_ignoring_case
|
||||
from .isequal_ignoring_whitespace import equal_to_ignoring_whitespace
|
||||
from .stringcontains import contains_string
|
||||
from .stringcontainsinorder import string_contains_in_order
|
||||
from .stringendswith import ends_with
|
||||
from .stringmatches import matches_regexp
|
||||
from .stringstartswith import starts_with
|
||||
|
||||
__author__ = "Jon Reid"
|
||||
__copyright__ = "Copyright 2011 hamcrest.org"
|
||||
__license__ = "BSD, see License.txt"
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
from hamcrest.core.base_matcher import BaseMatcher
|
||||
from hamcrest.core.description import Description
|
||||
from hamcrest.core.matcher import Matcher
|
||||
|
||||
__author__ = "Jon Reid"
|
||||
__copyright__ = "Copyright 2011 hamcrest.org"
|
||||
__license__ = "BSD, see License.txt"
|
||||
|
||||
|
||||
class IsEqualIgnoringCase(BaseMatcher[str]):
|
||||
def __init__(self, string: str) -> None:
|
||||
if not isinstance(string, str):
|
||||
raise TypeError("IsEqualIgnoringCase requires string")
|
||||
self.original_string = string
|
||||
self.lowered_string = string.lower()
|
||||
|
||||
def _matches(self, item: str) -> bool:
|
||||
if not isinstance(item, str):
|
||||
return False
|
||||
return self.lowered_string == item.lower()
|
||||
|
||||
def describe_to(self, description: Description) -> None:
|
||||
description.append_description_of(self.original_string).append_text(" ignoring case")
|
||||
|
||||
|
||||
def equal_to_ignoring_case(string: str) -> Matcher[str]:
|
||||
"""Matches if object is a string equal to a given string, ignoring case
|
||||
differences.
|
||||
|
||||
:param 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".
|
||||
|
||||
"""
|
||||
return IsEqualIgnoringCase(string)
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
from hamcrest.core.base_matcher import BaseMatcher
|
||||
from hamcrest.core.description import Description
|
||||
from hamcrest.core.matcher import Matcher
|
||||
|
||||
__author__ = "Jon Reid"
|
||||
__copyright__ = "Copyright 2011 hamcrest.org"
|
||||
__license__ = "BSD, see License.txt"
|
||||
|
||||
|
||||
def stripspace(string: str) -> str:
|
||||
result = ""
|
||||
last_was_space = True
|
||||
for character in string:
|
||||
if character.isspace():
|
||||
if not last_was_space:
|
||||
result += " "
|
||||
last_was_space = True
|
||||
else:
|
||||
result += character
|
||||
last_was_space = False
|
||||
return result.strip()
|
||||
|
||||
|
||||
class IsEqualIgnoringWhiteSpace(BaseMatcher[str]):
|
||||
def __init__(self, string) -> None:
|
||||
if not isinstance(string, str):
|
||||
raise TypeError("IsEqualIgnoringWhiteSpace requires string")
|
||||
self.original_string = string
|
||||
self.stripped_string = stripspace(string)
|
||||
|
||||
def _matches(self, item: str) -> bool:
|
||||
if not isinstance(item, str):
|
||||
return False
|
||||
return self.stripped_string == stripspace(item)
|
||||
|
||||
def describe_to(self, description: Description) -> None:
|
||||
description.append_description_of(self.original_string).append_text(" ignoring whitespace")
|
||||
|
||||
|
||||
def equal_to_ignoring_whitespace(string: str) -> Matcher[str]:
|
||||
"""Matches if object is a string equal to a given string, ignoring
|
||||
differences in whitespace.
|
||||
|
||||
:param 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"``.
|
||||
|
||||
"""
|
||||
return IsEqualIgnoringWhiteSpace(string)
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
from hamcrest.core.helpers.hasmethod import hasmethod
|
||||
from hamcrest.core.matcher import Matcher
|
||||
from hamcrest.library.text.substringmatcher import SubstringMatcher
|
||||
|
||||
__author__ = "Jon Reid"
|
||||
__copyright__ = "Copyright 2011 hamcrest.org"
|
||||
__license__ = "BSD, see License.txt"
|
||||
|
||||
|
||||
class StringContains(SubstringMatcher):
|
||||
def __init__(self, substring) -> None:
|
||||
super(StringContains, self).__init__(substring)
|
||||
|
||||
def _matches(self, item: str) -> bool:
|
||||
if not hasmethod(item, "find"):
|
||||
return False
|
||||
return item.find(self.substring) >= 0
|
||||
|
||||
def relationship(self):
|
||||
return "containing"
|
||||
|
||||
|
||||
def contains_string(substring: str) -> Matcher[str]:
|
||||
"""Matches if object is a string containing a given string.
|
||||
|
||||
:param 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".
|
||||
|
||||
"""
|
||||
return StringContains(substring)
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
from hamcrest.core.base_matcher import BaseMatcher
|
||||
from hamcrest.core.description import Description
|
||||
from hamcrest.core.helpers.hasmethod import hasmethod
|
||||
from hamcrest.core.matcher import Matcher
|
||||
|
||||
__author__ = "Romilly Cocking"
|
||||
__copyright__ = "Copyright 2011 hamcrest.org"
|
||||
__license__ = "BSD, see License.txt"
|
||||
|
||||
|
||||
class StringContainsInOrder(BaseMatcher[str]):
|
||||
def __init__(self, *substrings) -> None:
|
||||
for substring in substrings:
|
||||
if not isinstance(substring, str):
|
||||
raise TypeError(self.__class__.__name__ + " requires string arguments")
|
||||
self.substrings = substrings
|
||||
|
||||
def _matches(self, item: str) -> bool:
|
||||
if not hasmethod(item, "find"):
|
||||
return False
|
||||
from_index = 0
|
||||
for substring in self.substrings:
|
||||
from_index = item.find(substring, from_index)
|
||||
if from_index == -1:
|
||||
return False
|
||||
return True
|
||||
|
||||
def describe_to(self, description: Description) -> None:
|
||||
description.append_list("a string containing ", ", ", " in order", self.substrings)
|
||||
|
||||
|
||||
def string_contains_in_order(*substrings: str) -> Matcher[str]:
|
||||
"""Matches if object is a string containing a given list of substrings in
|
||||
relative order.
|
||||
|
||||
:param 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".
|
||||
|
||||
"""
|
||||
return StringContainsInOrder(*substrings)
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
from hamcrest.core.helpers.hasmethod import hasmethod
|
||||
from hamcrest.core.matcher import Matcher
|
||||
from hamcrest.library.text.substringmatcher import SubstringMatcher
|
||||
|
||||
__author__ = "Jon Reid"
|
||||
__copyright__ = "Copyright 2011 hamcrest.org"
|
||||
__license__ = "BSD, see License.txt"
|
||||
|
||||
|
||||
class StringEndsWith(SubstringMatcher):
|
||||
def __init__(self, substring) -> None:
|
||||
super(StringEndsWith, self).__init__(substring)
|
||||
|
||||
def _matches(self, item: str) -> bool:
|
||||
if not hasmethod(item, "endswith"):
|
||||
return False
|
||||
return item.endswith(self.substring)
|
||||
|
||||
def relationship(self):
|
||||
return "ending with"
|
||||
|
||||
|
||||
def ends_with(string: str) -> Matcher[str]:
|
||||
"""Matches if object is a string ending with a given string.
|
||||
|
||||
:param string: The string to search for.
|
||||
|
||||
This matcher first checks whether the evaluated object is a string. If so,
|
||||
it checks if ``string`` matches the ending characters of the evaluated
|
||||
object.
|
||||
|
||||
Example::
|
||||
|
||||
ends_with("bar")
|
||||
|
||||
will match "foobar".
|
||||
|
||||
"""
|
||||
return StringEndsWith(string)
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
import re
|
||||
from typing import Pattern, Union
|
||||
|
||||
from hamcrest.core.base_matcher import BaseMatcher
|
||||
from hamcrest.core.description import Description
|
||||
from hamcrest.core.matcher import Matcher
|
||||
|
||||
__author__ = "Chris Rose"
|
||||
__copyright__ = "Copyright 2011 hamcrest.org"
|
||||
__license__ = "BSD, see License.txt"
|
||||
|
||||
|
||||
class StringMatchesPattern(BaseMatcher[str]):
|
||||
def __init__(self, pattern) -> None:
|
||||
self.pattern = pattern
|
||||
|
||||
def describe_to(self, description: Description) -> None:
|
||||
description.append_text("a string matching '").append_text(
|
||||
self.pattern.pattern
|
||||
).append_text("'")
|
||||
|
||||
def _matches(self, item: str) -> bool:
|
||||
return self.pattern.search(item) is not None
|
||||
|
||||
|
||||
def matches_regexp(pattern: Union[str, Pattern[str]]) -> Matcher[str]:
|
||||
"""Matches if object is a string containing a match for a given regular
|
||||
expression.
|
||||
|
||||
:param 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 ``pattern`` matches anywhere within the
|
||||
evaluated object.
|
||||
|
||||
"""
|
||||
if isinstance(pattern, str):
|
||||
pattern = re.compile(pattern)
|
||||
|
||||
return StringMatchesPattern(pattern)
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
from hamcrest.core.helpers.hasmethod import hasmethod
|
||||
from hamcrest.core.matcher import Matcher
|
||||
from hamcrest.library.text.substringmatcher import SubstringMatcher
|
||||
|
||||
__author__ = "Jon Reid"
|
||||
__copyright__ = "Copyright 2011 hamcrest.org"
|
||||
__license__ = "BSD, see License.txt"
|
||||
|
||||
|
||||
class StringStartsWith(SubstringMatcher):
|
||||
def __init__(self, substring) -> None:
|
||||
super(StringStartsWith, self).__init__(substring)
|
||||
|
||||
def _matches(self, item: str) -> bool:
|
||||
if not hasmethod(item, "startswith"):
|
||||
return False
|
||||
return item.startswith(self.substring)
|
||||
|
||||
def relationship(self):
|
||||
return "starting with"
|
||||
|
||||
|
||||
def starts_with(substring: str) -> Matcher[str]:
|
||||
"""Matches if object is a string starting with a given string.
|
||||
|
||||
:param string: The string to search for.
|
||||
|
||||
This matcher first checks whether the evaluated object is a string. If so,
|
||||
it checks if ``string`` matches the beginning characters of the evaluated
|
||||
object.
|
||||
|
||||
Example::
|
||||
|
||||
starts_with("foo")
|
||||
|
||||
will match "foobar".
|
||||
|
||||
"""
|
||||
return StringStartsWith(substring)
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
from abc import ABCMeta, abstractmethod
|
||||
|
||||
from hamcrest.core.base_matcher import BaseMatcher
|
||||
from hamcrest.core.description import Description
|
||||
|
||||
__author__ = "Jon Reid"
|
||||
__copyright__ = "Copyright 2011 hamcrest.org"
|
||||
__license__ = "BSD, see License.txt"
|
||||
|
||||
|
||||
class SubstringMatcher(BaseMatcher[str], metaclass=ABCMeta):
|
||||
def __init__(self, substring) -> None:
|
||||
if not isinstance(substring, str):
|
||||
raise TypeError(self.__class__.__name__ + " requires string")
|
||||
self.substring = substring
|
||||
|
||||
def describe_to(self, description: Description) -> None:
|
||||
description.append_text("a string ").append_text(self.relationship()).append_text(
|
||||
" "
|
||||
).append_description_of(self.substring)
|
||||
|
||||
@abstractmethod
|
||||
def relationship(self):
|
||||
...
|
||||
Loading…
Add table
Add a link
Reference in a new issue