示例#1
0
    def test_lazy_prop(self):

        zcalcs = [0]

        def calcz():
            zcalcs[0] += 1
            return 33

        s = conf.Settings()
        s.add_config({
            "Z": conf.prop_lazy(calcz),
        })

        self.assertEqual(33, s.Z)
        self.assertEqual(33, s.Z)
        self.assertEqual(33, s.Z)
        self.assertEqual(1, zcalcs[0])
示例#2
0
    def test_lazy_prop(self):

        zcalcs = [0]

        def calcz():
            zcalcs[0] += 1
            return 33

        s = conf.Settings()
        s.add_config({
            "Z": conf.prop_lazy(calcz),
        })

        self.assertEqual(33, s.Z)
        self.assertEqual(33, s.Z)
        self.assertEqual(33, s.Z)
        self.assertEqual(1, zcalcs[0])
示例#3
0
    def test_magic_props(self):

        zcalcs = [0]

        def calcz():
            zcalcs[0] += 1
            return 33

        s = conf.Settings()
        s.add_config({
            "A": 3,
            "B": conf.prop_dynamic(lambda x: x.A + 10),
            "Z": conf.prop_lazy(calcz),
        })

        self.assertEqual(33, s.Z)
        self.assertEqual(33, s.Z)
        self.assertEqual(33, s.Z)
        self.assertEqual(1, zcalcs[0])
示例#4
0
    def test_magic_props(self):

        zcalcs = [0]

        def calcz():
            zcalcs[0] += 1
            return 33

        s = conf.Settings()
        s.add_config({
            "A": 3,
            "B": conf.prop_dynamic(lambda x: x.A + 10),
            "Z": conf.prop_lazy(calcz),
        })

        self.assertEqual(33, s.Z)
        self.assertEqual(33, s.Z)
        self.assertEqual(33, s.Z)
        self.assertEqual(1, zcalcs[0])