Example #1
0
 def set_tag(tag):
     # Extra depth to account for this function frame
     state = fiber.get_state(depth=1)
     if state is None:
         state = set()
         fiber.set_state(state, depth=1)
     state.add(tag)
Example #2
0
    def testFiberState(self):

        def depth1():
            state = fiber.get_state()
            self.assertNotEqual(None, state)
            self.assertTrue("root" in state)

            state.add("depth1 in")

            sub_state = depth2()
            self.assertEqual(state, sub_state)
            self.assertTrue("depth2 in" in state)
            self.assertTrue("depth2 out" in state)
            self.assertTrue("depth3" in state)

            state.add("depth1 out")
            return state

        def depth2():
            state = fiber.get_state()
            self.assertNotEqual(None, state)
            self.assertTrue("root" in state)
            self.assertTrue("depth1 in" in state)

            state.add("depth2 in")

            sub_state = depth3()
            self.assertEqual(state, sub_state)
            self.assertTrue("depth3" in state)

            state.add("depth2 out")
            return state

        def depth3():
            state = fiber.get_state()
            self.assertNotEqual(None, state)
            self.assertTrue("root" in state)
            self.assertTrue("depth1 in" in state)
            self.assertTrue("depth2 in" in state)

            state.add("depth3")
            return state

        self.assertEqual(None, fiber.get_state())
        state = set(["root"])
        fiber.set_state(state)
        self.assertEqual(state, fiber.get_state())
        sub_state = depth1()
        # check that all states are reference to the same instance
        self.assertEqual(state, sub_state)

        self.assertTrue("root" in state)
        self.assertTrue("depth1 in" in state)
        self.assertTrue("depth1 out" in state)
        self.assertTrue("depth2 in" in state)
        self.assertTrue("depth2 out" in state)
        self.assertTrue("depth3" in state)