1
|
|
|
from __future__ import absolute_import |
2
|
|
|
|
3
|
|
|
from hamcrest.library.collection.isdict_containingvalue 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 IsDictContainingValueTest(MatcherTest): |
|
|
|
|
16
|
|
|
|
17
|
|
|
def testMatchesSingletonDictionaryContainingValue(self): |
18
|
|
|
dict = {'a': 1} |
19
|
|
|
self.assert_matches('same single value', has_value(equal_to(1)), dict) |
20
|
|
|
|
21
|
|
|
def testMatchesDictionaryContainingValue(self): |
22
|
|
|
dict = {'a': 1, 'b': 2, 'c': 3} |
23
|
|
|
self.assert_matches('Matches 1', has_value(equal_to(1)), dict) |
24
|
|
|
self.assert_matches('Matches 3', has_value(equal_to(3)), dict) |
25
|
|
|
|
26
|
|
|
def testProvidesConvenientShortcutForMatchingWithEqualTo(self): |
27
|
|
|
dict = {'a': 1, 'b': 2, 'c': 3} |
28
|
|
|
self.assert_matches('Matches 3', has_value(3), dict) |
29
|
|
|
|
30
|
|
|
def testDoesNotMatchEmptyDictionary(self): |
31
|
|
|
self.assert_does_not_match('empty', has_value(1), {}); |
32
|
|
|
|
33
|
|
|
def testDoesNotMatchDictionaryMissingValue(self): |
34
|
|
|
dict = {'a': 1, 'b': 2, 'c': 3} |
35
|
|
|
self.assert_does_not_match('no matching value', has_value(4), dict) |
36
|
|
|
|
37
|
|
|
def testMatchesAnyConformingDictionary(self): |
38
|
|
|
self.assert_matches('quasi-dictionary', has_value('1'), QuasiDictionary()) |
39
|
|
|
self.assert_does_not_match('non-dictionary', has_value('1'), object()) |
40
|
|
|
|
41
|
|
|
def testHasReadableDescription(self): |
42
|
|
|
self.assert_description("a dictionary containing value 'a'", has_value('a')) |
43
|
|
|
|
44
|
|
|
def testSuccessfulMatchDoesNotGenerateMismatchDescription(self): |
45
|
|
|
self.assert_no_mismatch_description(has_value(1), {'a': 1}) |
46
|
|
|
|
47
|
|
|
def testMismatchDescriptionShowsActualArgument(self): |
48
|
|
|
self.assert_mismatch_description("was 'bad'", has_value(1), 'bad') |
49
|
|
|
|
50
|
|
|
def testDescribeMismatch(self): |
51
|
|
|
self.assert_describe_mismatch("was 'bad'", has_value(1), 'bad') |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
if __name__ == '__main__': |
55
|
|
|
unittest.main() |
56
|
|
|
|