コード例 #1
0
    def testPushPeekPopObj(self):
        t_stack = traceable_stack.TraceableStack()
        t_stack.push_obj(42.0)
        t_stack.push_obj('hope')

        expected_lifo_peek = ['hope', 42.0]
        self.assertEqual(expected_lifo_peek, list(t_stack.peek_objs()))

        self.assertEqual('hope', t_stack.pop_obj())
        self.assertEqual(42.0, t_stack.pop_obj())
コード例 #2
0
    def testPushPopPreserveLifoOrdering(self):
        t_stack = traceable_stack.TraceableStack()
        t_stack.push_obj(0)
        t_stack.push_obj(1)
        t_stack.push_obj(2)
        t_stack.push_obj(3)

        obj_3 = t_stack.pop_obj()
        obj_2 = t_stack.pop_obj()
        obj_1 = t_stack.pop_obj()
        obj_0 = t_stack.pop_obj()

        self.assertEqual(3, obj_3)
        self.assertEqual(2, obj_2)
        self.assertEqual(1, obj_1)
        self.assertEqual(0, obj_0)
コード例 #3
0
    def testPushObjSetsFilenameAndLineInfoForCaller(self):
        t_stack = traceable_stack.TraceableStack()

        # We expect that the line number recorded for the 1-object will come from
        # the call to t_stack.push_obj(1).  Do not separate the next two lines!
        placeholder_1 = lambda x: x
        t_stack.push_obj(1)

        # We expect that the line number recorded for the 2-object will come from
        # the call to call_push_obj() and _not_ the call to t_stack.push_obj().
        def call_push_obj(obj):
            t_stack.push_obj(obj, offset=1)

        # Do not separate the next two lines!
        placeholder_2 = lambda x: x
        call_push_obj(2)

        expected_lineno_1 = inspect.getsourcelines(placeholder_1)[1] + 1
        expected_lineno_2 = inspect.getsourcelines(placeholder_2)[1] + 1

        t_obj_2, t_obj_1 = t_stack.peek_traceable_objs()
        self.assertEqual(expected_lineno_2, t_obj_2.lineno)
        self.assertEqual(expected_lineno_1, t_obj_1.lineno)
コード例 #4
0
 def testPushPeekTopObj(self):
     t_stack = traceable_stack.TraceableStack()
     t_stack.push_obj(42.0)
     t_stack.push_obj('hope')
     self.assertEqual('hope', t_stack.peek_top_obj())