Ejemplo n.º 1
0
    def testIdentity(self):
        """Does identity pass on return values unchanged?
        """
        # Succeed after 5 iterations.
        after = 5
        tree = owyl.identity(owyl.succeedAfter(after=after))

        v = owyl.visit(tree)
        for x in xrange(after):
            self.assertEqual(v.next(), None)
        self.assertEqual(v.next(), True)

        v = owyl.visit(tree)
        for x in xrange(after):
            self.assertEqual(v.next(), None)
        self.assertEqual(v.next(), True)

        tree = owyl.identity(owyl.failAfter(after=after))

        v = owyl.visit(tree)
        for x in xrange(after):
            self.assertEqual(v.next(), None)
        self.assertEqual(v.next(), False)

        v = owyl.visit(tree)
        for x in xrange(after):
            self.assertEqual(v.next(), None)
        self.assertEqual(v.next(), False)
Ejemplo n.º 2
0
    def testIdentity(self):
        """Does identity pass on return values unchanged?
        """
        # Succeed after 5 iterations.
        after = 5
        tree = owyl.identity(owyl.succeedAfter(after=after))

        v = owyl.visit(tree)
        for x in xrange(after):
            self.assertEqual(v.next(), None)
        self.assertEqual(v.next(), True)

        v = owyl.visit(tree)
        for x in xrange(after):
            self.assertEqual(v.next(), None)
        self.assertEqual(v.next(), True)

        tree = owyl.identity(owyl.failAfter(after=after))

        v = owyl.visit(tree)
        for x in xrange(after):
            self.assertEqual(v.next(), None)
        self.assertEqual(v.next(), False)

        v = owyl.visit(tree)
        for x in xrange(after):
            self.assertEqual(v.next(), None)
        self.assertEqual(v.next(), False)
Ejemplo n.º 3
0
    def testParallel_DelayedSuccess(self):
        """Can parallel succeed if child succeeds later (one succeeds)?
        """
        # Succeed after 5 iterations.
        after = 5
        tree = owyl.parallel(owyl.fail(),
                             owyl.succeedAfter(after=after),
                             policy=owyl.PARALLEL_SUCCESS.REQUIRE_ONE)
        v = owyl.visit(tree)
        results = [x for x in v if x is not None]
        self.assertEqual(results, [True])

        v = owyl.visit(tree)
        results = [x for x in v if x is not None]
        self.assertEqual(results, [True])