|
1
|
|
|
from __future__ import absolute_import |
|
2
|
|
|
|
|
3
|
|
|
from hamcrest.library.collection.is_empty import * |
|
4
|
|
|
|
|
5
|
|
|
from hamcrest_unit_test.matcher_test import MatcherTest |
|
6
|
|
|
from .sequencemixin import GeneratorForm, SequenceForm |
|
7
|
|
|
|
|
8
|
|
|
__author__ = "Chris Rose" |
|
9
|
|
|
__copyright__ = "Copyright 2012 hamcrest.org" |
|
10
|
|
|
__license__ = "BSD, see License.txt" |
|
11
|
|
|
|
|
12
|
|
|
class LengthHaver(object): |
|
13
|
|
|
|
|
14
|
|
|
def __init__(self, len_): |
|
15
|
|
|
self._len = len_ |
|
16
|
|
|
|
|
17
|
|
|
def __len__(self): |
|
18
|
|
|
return self._len |
|
19
|
|
|
|
|
20
|
|
|
class EmptyCollectionTest(MatcherTest): |
|
21
|
|
|
|
|
22
|
|
|
def testReturnsTrueForEmptyStandardCollections(self): |
|
23
|
|
|
matcher = empty() |
|
24
|
|
|
self.assert_matches('empty tuple', matcher, ()) |
|
25
|
|
|
self.assert_matches('empty list', matcher, []) |
|
26
|
|
|
self.assert_matches('emtpy dictionary', matcher, {}) |
|
27
|
|
|
|
|
28
|
|
|
def testReturnsTrueForEmptyCollectionLike(self): |
|
29
|
|
|
matcher = empty() |
|
30
|
|
|
self.assert_matches('empty protocol object', matcher, LengthHaver(0)) |
|
31
|
|
|
|
|
32
|
|
|
def testReturnsFalseForNonEmptyStandardCollections(self): |
|
33
|
|
|
matcher = empty() |
|
34
|
|
|
self.assert_does_not_match('non-empty tuple', matcher, (1,)) |
|
35
|
|
|
self.assert_does_not_match('non-empty list', matcher, [1]) |
|
36
|
|
|
self.assert_does_not_match('emtpy dictionary', matcher, {1:2}) |
|
37
|
|
|
|
|
38
|
|
|
def testReturnsFalseForNonEmptyCollectionLike(self): |
|
39
|
|
|
matcher = empty() |
|
40
|
|
|
self.assert_does_not_match('non-empty protocol object', matcher, LengthHaver(1)) |
|
41
|
|
|
|
|
42
|
|
|
def testHasReadableDescription(self): |
|
43
|
|
|
self.assert_description("an empty collection", empty()) |
|
44
|
|
|
|
|
45
|
|
|
def testSuccessfulMatchDoesNotGenerateMismatchDescription(self): |
|
46
|
|
|
self.assert_no_mismatch_description(empty(), []) |
|
47
|
|
|
|
|
48
|
|
|
def testDescribeMismatch(self): |
|
49
|
|
|
self.assert_mismatch_description("has 3 item(s)", empty(), [1,2,3]) |
|
50
|
|
|
self.assert_mismatch_description("does not support length", empty(), 1) |
|
51
|
|
|
|