Completed
Pull Request — master (#80)
by
unknown
02:25
created

tests.hamcrest_unit_test.collection.IsDictContainingKeyTest   A

Complexity

Total Complexity 10

Size/Duplication

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

10 Methods

Rating   Name   Duplication   Size   Complexity  
A IsDictContainingKeyTest.testMatchesDictionaryContainingKey() 4 4 1
A IsDictContainingKeyTest.testProvidesConvenientShortcutForMatchingWithEqualTo() 3 3 1
A IsDictContainingKeyTest.testDescribeMismatch() 2 2 1
A IsDictContainingKeyTest.testSuccessfulMatchDoesNotGenerateMismatchDescription() 2 2 1
A IsDictContainingKeyTest.testMatchesAnyConformingDictionary() 3 3 1
A IsDictContainingKeyTest.testDoesNotMatchEmptyDictionary() 2 2 1
A IsDictContainingKeyTest.testMatchesSingletonDictionaryContainingKey() 3 3 1
A IsDictContainingKeyTest.testHasReadableDescription() 2 2 1
A IsDictContainingKeyTest.testDoesNotMatchDictionaryMissingKey() 3 3 1
A IsDictContainingKeyTest.testMismatchDescriptionShowsActualArgument() 2 2 1
1
from __future__ import absolute_import
2
3
from hamcrest.library.collection.isdict_containingkey import *
4
5
from hamcrest.core.core.isequal import equal_to
6
from hamcrest_unit_test.matcher_test import MatcherTest
7
from .quasidict import QuasiDictionary
8
import unittest
9
10
__author__ = "Jon Reid"
11
__copyright__ = "Copyright 2011 hamcrest.org"
12
__license__ = "BSD, see License.txt"
13
14
15 View Code Duplication
class IsDictContainingKeyTest(MatcherTest):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
16
17
    def testMatchesSingletonDictionaryContainingKey(self):
18
        dict = {'a': 1}
19
        self.assert_matches('same single key', has_key(equal_to('a')), dict)
20
21
    def testMatchesDictionaryContainingKey(self):
22
        dict = {'a': 1, 'b': 2, 'c': 3}
23
        self.assert_matches('Matches a', has_key(equal_to('a')), dict)
24
        self.assert_matches('Matches c', has_key(equal_to('c')), dict)
25
26
    def testProvidesConvenientShortcutForMatchingWithEqualTo(self):
27
        dict = {'a': 1, 'b': 2, 'c': 3}
28
        self.assert_matches('Matches c', has_key('c'), dict)
29
30
    def testDoesNotMatchEmptyDictionary(self):
31
        self.assert_does_not_match('empty', has_key('foo'), {});
32
33
    def testDoesNotMatchDictionaryMissingKey(self):
34
        dict = {'a': 1, 'b': 2, 'c': 3}
35
        self.assert_does_not_match('no matching key', has_key('d'), dict)
36
37
    def testMatchesAnyConformingDictionary(self):
38
        self.assert_matches('quasi-dictionary', has_key(1), QuasiDictionary())
39
        self.assert_does_not_match('non-dictionary', has_key(1), object())
40
41
    def testHasReadableDescription(self):
42
        self.assert_description("a dictionary containing key 'a'", has_key('a'))
43
44
    def testSuccessfulMatchDoesNotGenerateMismatchDescription(self):
45
        self.assert_no_mismatch_description(has_key('a'), {'a': 1})
46
47
    def testMismatchDescriptionShowsActualArgument(self):
48
        self.assert_mismatch_description("was 'bad'", has_key('a'), 'bad')
49
50
    def testDescribeMismatch(self):
51
        self.assert_describe_mismatch("was 'bad'", has_key('a'), 'bad')
52
53
54
if __name__ == '__main__':
55
    unittest.main()
56