__init__()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 2
rs 10
1
from hamcrest.library.text.substringmatcher import SubstringMatcher
2
from hamcrest.core.helpers.hasmethod import hasmethod
3
4
__author__ = "Jon Reid"
5
__copyright__ = "Copyright 2011 hamcrest.org"
6
__license__ = "BSD, see License.txt"
7
8
9
class StringEndsWith(SubstringMatcher):
10
11
    def __init__(self, substring):
12
        super(StringEndsWith, self).__init__(substring)
13
14
    def _matches(self, item):
15
        if not hasmethod(item, 'endswith'):
16
            return False
17
        return item.endswith(self.substring)
18
19
    def relationship(self):
20
        return 'ending with'
21
22
23
def ends_with(string):
24
    """Matches if object is a string ending with a given string.
25
26
    :param string: The string to search for.
27
28
    This matcher first checks whether the evaluated object is a string. If so,
29
    it checks if ``string`` matches the ending characters of the evaluated
30
    object.
31
32
    Example::
33
34
        ends_with("bar")
35
36
    will match "foobar".
37
38
    """
39
    return StringEndsWith(string)
40