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

MatcherTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 19
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A assert_description() 0 2 1
A assert_mismatch_description() 0 2 1
A assert_matches() 0 2 1
A assert_does_not_match() 0 2 1
A assert_no_mismatch_description() 0 2 1
A assert_describe_mismatch() 0 2 1
1
from hamcrest.core.string_description import StringDescription
2
3
try:
4
    from unittest import skipIf
5
    import unittest
6
except ImportError:
7
    import unittest2 as unittest
8
9
import logging
10
11
log = logging.getLogger(__name__)
12
13
__author__ = "Jon Reid"
14
__copyright__ = "Copyright 2011 hamcrest.org"
15
__license__ = "BSD, see License.txt"
16
__tracebackhide__ = True
17
18
19
class MatcherTest(unittest.TestCase):
20
21
    def assert_matches(self, message, matcher, arg):
22
        assert_matches(matcher, arg, message)
23
24
    def assert_does_not_match(self, message, matcher, arg):
25
        assert_does_not_match(matcher, arg, message)
26
27
    def assert_description(self, expected, matcher):
28
        assert_description(expected, matcher)
29
30
    def assert_no_mismatch_description(self, matcher, arg):
31
        assert_no_mismatch_description(matcher, arg)
32
33
    def assert_mismatch_description(self, expected, matcher, arg):
34
        assert_mismatch_description(expected, matcher, arg)
35
36
    def assert_describe_mismatch(self, expected, matcher, arg):
37
        assert_describe_mismatch(expected, matcher, arg)
38
39
40
def assert_matches(matcher, arg, message):
41
    try:
42
        assert matcher.matches(arg), message
43
    except AssertionError:
44
        description = StringDescription()
45
        matcher.describe_mismatch(arg, description)
46
        log.error(str(description))
47
        raise
48
49
50
def assert_does_not_match(matcher, arg, message):
51
    assert not matcher.matches(arg), message
52
53
54
def assert_description(expected, matcher):
55
    description = StringDescription()
56
    description.append_description_of(matcher)
57
    assert expected == str(description)
58
59
60
def assert_no_mismatch_description(matcher, arg):
61
    description = StringDescription()
62
    result = matcher.matches(arg, description)
63
    assert result, 'Precondition: Matcher should match item'
64
    assert '' == str(description), 'Expected no mismatch description'
65
66
67
def assert_mismatch_description(expected, matcher, arg):
68
    description = StringDescription()
69
    result = matcher.matches(arg, description)
70
    assert not result, 'Precondition: Matcher should not match item'
71
    assert expected == str(description)
72
73
74
def assert_describe_mismatch(expected, matcher, arg):
75
    description = StringDescription()
76
    matcher.describe_mismatch(arg, description)
77
    assert expected == str(description)
78