src.hamcrest.library.text.StringEndsWith   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 12
Duplicated Lines 0 %
Metric Value
dl 0
loc 12
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A relationship() 0 2 1
A __init__() 0 2 1
A _matches() 0 4 2
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