Completed
Pull Request — master (#75)
by Cézar
01:32
created

tests.hamcrest_unit_test.collection.BaseQuasiDictionaryIterator   A

Complexity

Total Complexity 4

Size/Duplication

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A BaseQuasiDictionaryIterator.__iter__() 0 2 1
A BaseQuasiDictionaryIterator.__init__() 0 2 1
A BaseQuasiDictionaryIterator.__next__() 0 6 2
1
__author__ = "Jon Reid"
2
__copyright__ = "Copyright 2011 hamcrest.org"
3
__license__ = "BSD, see License.txt"
4
5
import six
6
7
8
class QuasiDictionary(object):
9
    def items(self):
10
        return QuasiDictionaryItemIterator()
11
12
    def keys(self):
13
        return QuasiDictionaryKeyIterator()
14
15
    def values(self):
16
        return QuasiDictionaryValueIterator()
17
18
19
class BaseQuasiDictionaryIterator(six.Iterator):
20
    def __init__(self):
21
        self.index = 1
22
23
    def __iter__(self):
24
        return self
25
26
    def __next__(self):
27
        if self.index >= 3:
28
            raise StopIteration
29
        result = self.indexToResult()
30
        self.index += 1
31
        return result
32
33
34
class QuasiDictionaryItemIterator(BaseQuasiDictionaryIterator):
35
    def indexToResult(self):
36
        return (self.index, str(self.index))
37
38
39
class QuasiDictionaryKeyIterator(BaseQuasiDictionaryIterator):
40
    def indexToResult(self):
41
        return self.index
42
43
44
class QuasiDictionaryValueIterator(BaseQuasiDictionaryIterator):
45
    def indexToResult(self):
46
        return str(self.index)
47