Пример #1
0
    def test_get_set(self):
        """
        Test getting and setting values within an object.
        """

        apple = Fruit(8, 'red')

        self.assertEqual(getl(apple, A.size), 8)

        setl(apple, A.color, 'yellow')
        self.assertEqual(apple.color, 'yellow')
Пример #2
0
    def test_nested(self):
        """
        Test lens nesting.
        """

        class Color(object):
            def __init__(self, red, green, blue):
                self.red = red
                self.green = green
                self.blue = blue

        apple = Fruit(8, Color(1.0, 0.5, 0.0))

        self.assertEqual(getl(apple, A.color * A.red), 1.0)

        setl(apple, A.color * A.green, 1.0)
        self.assertEqual(apple.color.green, 1.0)