testHasReadableDescription()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 3
rs 10
1
from __future__ import absolute_import
2
3
from hamcrest.library.collection.isdict_containing import *
4
5
from hamcrest.core.core.isequal import equal_to
6
7
from hamcrest_unit_test.matcher_test import MatcherTest
8
from .quasidict import QuasiDictionary
9
import unittest
10
11
__author__ = "Jon Reid"
12
__copyright__ = "Copyright 2011 hamcrest.org"
13
__license__ = "BSD, see License.txt"
14
15
16
class IsDictContainingTest(MatcherTest):
17
18
    def testMatchesDictionaryContainingMatchingKeyAndValue(self):
19
        dict = {'a': 1, 'b': 2}
20
        self.assert_matches('has a:1', has_entry(equal_to('a'), equal_to(1)), dict)
21
        self.assert_matches('has b:2', has_entry(equal_to('b'), equal_to(2)), dict)
22
        self.assert_does_not_match('no c:3', has_entry(equal_to('c'), equal_to(3)), dict)
23
24
    def testProvidesConvenientShortcutForMatchingWithEqualTo(self):
25
        dict = {'a': 1, 'b': 2}
26
        self.assert_matches('has a:1', has_entry('a', equal_to(1)), dict)
27
        self.assert_matches('has b:2', has_entry(equal_to('b'), 2), dict)
28
        self.assert_does_not_match('no c:3', has_entry('c', 3), dict)
29
30
    def testMatchesAnyConformingDictionary(self):
31
        self.assert_matches('quasi-dictionary', has_entry(1, '1'), QuasiDictionary())
32
        self.assert_does_not_match('non-dictionary', has_entry(1, '1'), object())
33
34
    def testHasReadableDescription(self):
35
        self.assert_description("a dictionary containing ['a': <1>]",
36
                                has_entry('a', 1))
37
38
    def testSuccessfulMatchDoesNotGenerateMismatchDescription(self):
39
        self.assert_no_mismatch_description(has_entry('a', 1), {'a': 1})
40
41
    def testMismatchDescriptionShowsActualArgument(self):
42
        self.assert_mismatch_description("was 'bad'", has_entry('a', 1), 'bad')
43
44
    def testDescribeMismatch(self):
45
        self.assert_describe_mismatch("was 'bad'", has_entry('a', 1), 'bad')
46
47
48
if __name__ == '__main__':
49
    unittest.main()
50