Esempio n. 1
0
    def testProtocol(self):
        def _generator():
            yield "a"

        single = lazy_repetition.LazyRepetition(_generator)
        self.assertEqual(list(repeated.getvalues(single)), ["a"])
        self.assertEqual(repeated.getvalue(single), "a")

        def _generator():
            yield "a"
            yield "b"

        double = lazy_repetition.LazyRepetition(_generator)
        self.assertEqual(list(repeated.getvalues(double)), ["a", "b"])
        self.assertEqual(repeated.getvalue(double), "a")
Esempio n. 2
0
    def testScalarCompare(self):
        def _generator():
            yield 1

        l = lazy_repetition.LazyRepetition(_generator)
        self.assertTrue(l.value_eq(1))

        self.assertEqual(int, l.value_type())
Esempio n. 3
0
    def testCompare(self):
        def _generator():
            yield 1
            yield 2
            yield 3

        self.assertEqual(lazy_repetition.LazyRepetition(_generator),
                         repeated.meld(1, 2, 3))
Esempio n. 4
0
    def testApply(self):
        def _generator():
            yield 1
            yield 2

        l = lazy_repetition.LazyRepetition(_generator)
        self.assertItemsEqual(
            l.value_apply(lambda x: x * 2).getvalues(), [2, 4])
Esempio n. 5
0
    def testRestarting(self):
        def _generator():
            yield "a"
            yield "b"
            yield "c"
            yield "d"

        l = lazy_repetition.LazyRepetition(_generator)

        # But still iterate from idx 0.
        self.assertItemsEqual(l.getvalues(), ("a", "b", "c", "d"))

        # Second iteration should still work!
        self.assertItemsEqual(l.getvalues(), ("a", "b", "c", "d"))