File: quasidict.py

package info (click to toggle)
pyhamcrest 1.6-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 556 kB
  • sloc: python: 2,938; makefile: 2
file content (44 lines) | stat: -rw-r--r-- 1,013 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
__author__ = "Jon Reid"
__copyright__ = "Copyright 2011 hamcrest.org"
__license__ = "BSD, see License.txt"


class QuasiDictionary:
    def items(self):
        return QuasiDictionaryItemIterator()

    def keys(self):
        return QuasiDictionaryKeyIterator()

    def values(self):
        return QuasiDictionaryValueIterator()


class BaseQuasiDictionaryIterator:
    def __init__(self):
        self.index = 1

    def __iter__(self):
        return self

    def next(self):
        if self.index >= 3:
            raise StopIteration
        result = self.indexToResult()
        self.index += 1
        return result


class QuasiDictionaryItemIterator(BaseQuasiDictionaryIterator):
    def indexToResult(self):
        return (self.index, str(self.index))


class QuasiDictionaryKeyIterator(BaseQuasiDictionaryIterator):
    def indexToResult(self):
        return self.index


class QuasiDictionaryValueIterator(BaseQuasiDictionaryIterator):
    def indexToResult(self):
        return str(self.index)