Beispiel #1
0
    def test_compress_after_push(self):
        succession = Succession(compress=lambda items: [sum(items)])

        from_start = succession.iter()

        for i in [1, 2, 3, 4, 5]:
            succession.push(i)
        succession.close()

        from_end = succession.iter()

        self.assertEqual(list(from_start), [1, 2, 3, 4, 5])
        self.assertEqual(list(from_end), [15])
Beispiel #2
0
    def test_zero_timeout(self):
        succession = Succession()

        for i in [1, 2, 3, 4, 5]:
            succession.push(i)

        self.assertEqual(list(succession.iter(timeout=0)), [1, 2, 3, 4, 5])
Beispiel #3
0
    def test_compress(self):
        def accumulate(start, new):
            return [sum(start) + new]

        succession = Succession(compress=accumulate)

        from_start = succession.iter()

        for i in [1, 2, 3, 4, 5]:
            succession.push(i)
        succession.close()

        from_end = succession.iter()

        self.assertEqual(list(from_start), [1, 2, 3, 4, 5])
        self.assertEqual(list(from_end), [15])
Beispiel #4
0
    def test_drop_after_push(self):
        succession = Succession(compress=lambda hd: [])

        from_start = succession.iter()

        for i in [1, 2, 3]:
            succession.push(i)

        from_middle = succession.iter()

        for i in [4, 5, 6]:
            succession.push(i)

        succession.close()

        from_end = succession.iter()

        self.assertEqual(list(from_start), [1, 2, 3, 4, 5, 6])
        self.assertEqual(list(from_middle), [4, 5, 6])
        self.assertEqual(list(from_end), [])
Beispiel #5
0
    def test_nonzero_timeout(self):
        succession = Succession()

        for i in [1, 2, 3, 4, 5]:
            succession.push(i)

        result = []
        try:
            for item in succession.iter(timeout=0.01):
                result.append(item)
        except TimeoutError:
            self.assertEqual(result, [1, 2, 3, 4, 5])
        else:  # pragma:  no cover
            self.fail()