Completed
Pull Request — master (#79)
by
unknown
30s
created

IsEqual   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 15
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __init__() 0 2 1
A describe_to() 0 7 3
A _matches() 0 2 1
1
__author__ = "Jon Reid"
2
__copyright__ = "Copyright 2011 hamcrest.org"
3
__license__ = "BSD, see License.txt"
4
5
from hamcrest.core.base_matcher import BaseMatcher
6
from hamcrest.core.matcher import Matcher
7
8
9
class IsEqual(BaseMatcher):
10
11
    def __init__(self, equals):
12
        self.object = equals
13
14
    def _matches(self, item):
15
        return item == self.object
16
17
    def describe_to(self, description):
18
        nested_matcher = isinstance(self.object, Matcher)
19
        if nested_matcher:
20
            description.append_text('<')
21
        description.append_description_of(self.object)
22
        if nested_matcher:
23
            description.append_text('>')
24
25
26
def equal_to(obj):
27
    """Matches if object is equal to a given object.
28
29
    :param obj: The object to compare against as the expected value.
30
31
    This matcher compares the evaluated object to ``obj`` for equality."""
32
    return IsEqual(obj)
33