Пример #1
0
    def test_from_block(self):
        m = self.model()

        comp = m.v0
        pred_stack = [
            (self.get_attribute, 'v0'),
        ]
        self.assertCorrectStack(comp, pred_stack, context=m)

        comp = m.b.b1[2].b.b2[1, 'a', 1]
        pred_stack = [
            (self.get_item, (1, 'a', 1)),
            (self.get_attribute, 'b2'),
            (self.get_attribute, 'b'),
            (self.get_item, 2),
            (self.get_attribute, 'b1'),
            (self.get_attribute, 'b'),
        ]
        self.assertCorrectStack(comp, pred_stack, context=m)

        comp = m.b.b1[2].b.b2[1, 'a', 1].b.v2['b', 2]
        pred_stack = [
            (self.get_item, ('b', 2)),
            (self.get_attribute, 'v2'),
            (self.get_attribute, 'b'),
            (self.get_item, (1, 'a', 1)),
            (self.get_attribute, 'b2'),
            (self.get_attribute, 'b'),
            (self.get_item, 2),
        ]
        self.assertCorrectStack(comp, pred_stack, context=m.b.b1)

        comp = m.b.b1[2].b.b2
        pred_stack = [
            (self.get_attribute, 'b2'),
            (self.get_attribute, 'b'),
            (self.get_item, 2),
        ]
        self.assertCorrectStack(comp, pred_stack, context=m.b.b1)

        comp = m.b.b1[2]
        pred_stack = [
            (self.get_item, 2),
        ]
        self.assertCorrectStack(comp, pred_stack, context=m.b.b1)

        comp = m.b.b1
        act_stack = get_component_call_stack(comp, context=m.b.b1)
        self.assertEqual(len(act_stack), 0)
Пример #2
0
    def test_from_blockdata(self):

        m = self.model()

        context = m.b.b1[3].b.b2[2, 'b', 2]
        comp = m.b.b1[3].b.b2[2, 'b', 2].b
        pred_stack = [
            (self.get_attribute, 'b'),
        ]
        self.assertCorrectStack(comp, pred_stack, context=context)

        comp = m.b.b1[3].b.b2[2, 'b', 2].b.v2['a', 1]
        pred_stack = [
            (self.get_item, ('a', 1)),
            (self.get_attribute, 'v2'),
            (self.get_attribute, 'b'),
        ]
        self.assertCorrectStack(comp, pred_stack, context=context)

        context = m.b.b1[3]
        comp = m.b.b1[3]
        act_stack = get_component_call_stack(comp, context=context)
        self.assertEqual(len(act_stack), 0)
Пример #3
0
 def assertCorrectStack(self, comp, pred_stack, context=None):
     act_stack = get_component_call_stack(comp, context=None)
     self.assertSameStack(pred_stack, act_stack)