Completed
Pull Request — master (#71)
by
unknown
01:30
created

IsDictContainingKeyTest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 37
Duplicated Lines 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 37
loc 37
rs 10
wmc 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A testMatchesDictionaryContainingKey() 4 4 1
A testProvidesConvenientShortcutForMatchingWithEqualTo() 3 3 1
A testDescribeMismatch() 2 2 1
A testSuccessfulMatchDoesNotGenerateMismatchDescription() 2 2 1
A testMatchesAnyConformingDictionary() 3 3 1
A testDoesNotMatchEmptyDictionary() 2 2 1
A testMatchesSingletonDictionaryContainingKey() 3 3 1
A testHasReadableDescription() 2 2 1
A testDoesNotMatchDictionaryMissingKey() 3 3 1
A testMismatchDescriptionShowsActualArgument() 2 2 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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