Пример #1
0
    def test_stack_settings(self):
        """test settings aggregation"""
        kv1 = KeyValueStoreModifier({'one': {'one': 1,
                                             'two': 2},
                                     'two': 2})

        stack = ContextStack()
        ctx = Context('first')
        ctx.set_settings(kv1)
        stack.push(ctx)

        kv2 = KeyValueStoreModifier({'one': {'one': '1',
                                             'three': 3},
                                     'two': {'one': 1, 'foo': 2},
                                     'three': 3})

        assert stack.settings().data().to_dict() == kv1.data()

        ctx = Context('second')
        ctx.set_settings(kv2)
        stack.push(ctx)

        kvd = stack.settings().data()
        assert kvd.one.one == '1'
        assert kvd.one.three == 3
        assert kvd.one.two == 2
        assert kvd.three == 3
        assert kvd.two.one == 1

        # popping the previous context should bring the original one back
        stack.pop()
        kvd = stack.settings().data()
        assert kvd.to_dict() == kv1.data()