コード例 #1
0
ファイル: test_lib_utils.py プロジェクト: eaudeweb/naaya
 def test6(self):
     "recursive attribute setting/getting on drawings"
     from reportlab.graphics.charts.barcharts import sampleH1
     drawing = sampleH1()
     recursiveSetAttr(drawing, 'barchart.valueAxis.valueMax', 72)
     theMax = recursiveGetAttr(drawing, 'barchart.valueAxis.valueMax')
     assert theMax == 72
コード例 #2
0
ファイル: test_lib_utils.py プロジェクト: zilhua/reportlab
 def test6(self):
     "recursive attribute setting/getting on drawings"
     from reportlab.graphics.charts.barcharts import sampleH1
     drawing = sampleH1()
     recursiveSetAttr(drawing, 'barchart.valueAxis.valueMax', 72)
     theMax = recursiveGetAttr(drawing, 'barchart.valueAxis.valueMax')
     assert theMax == 72
コード例 #3
0
ファイル: test_lib_utils.py プロジェクト: eaudeweb/naaya
    def test5(self):
        "recursive attribute setting/getting on modules"
        import reportlab.lib.units
        inch = recursiveGetAttr(reportlab, 'lib.units.inch')
        assert inch == 72

        recursiveSetAttr(reportlab, 'lib.units.cubit', 18*inch)
        cubit = recursiveGetAttr(reportlab, 'lib.units.cubit')
        assert cubit == 18*inch
コード例 #4
0
ファイル: test_lib_utils.py プロジェクト: zilhua/reportlab
    def test5(self):
        "recursive attribute setting/getting on modules"
        import reportlab.lib.units
        inch = recursiveGetAttr(reportlab, 'lib.units.inch')
        assert inch == 72

        recursiveSetAttr(reportlab, 'lib.units.cubit', 18 * inch)
        cubit = recursiveGetAttr(reportlab, 'lib.units.cubit')
        assert cubit == 18 * inch
コード例 #5
0
    def test_person_example(self):
        bob = RaccessPerson(name="Bob", age=31, friends=[])
        jill = RaccessPerson(name="Jill", age=29, friends=[bob])
        jack = RaccessPerson(name="Jack", age=28, friends=[bob, jill])

        # Nothing new
        self.assertEqual(recursiveGetAttr(bob, 'age'), 31)

        # Lists
        self.assertEqual(recursiveGetAttr(jill, 'friends[0].name'), 'Bob')
        self.assertEqual(recursiveGetAttr(jack, 'friends[-1].age'), 29)

        # Dict lookups
        self.assertEqual(recursiveGetAttr(jack, 'settings["style"]["width"]'),
                         200)

        # Combination of lookups
        self.assertEqual(recursiveGetAttr(jack, 'settings["themes"][-2]'),
                         'light')
        self.assertEqual(
            recursiveGetAttr(jack, 'friends[-1].settings["themes"][1]'),
            'dark')

        # Setattr
        #recursiveSetAttr(bob, 'settings["style"]["width"]', 400)
        #self.assertEqual(recursiveGetAttr(bob, 'settings["style"]["width"]') ,400)

        # Nested objects
        recursiveSetAttr(bob, 'friends', [jack, jill])
        self.assertEqual(recursiveGetAttr(jack, 'friends[0].friends[0]'), jack)

        recursiveSetAttr(jill, 'friends[0].age', 32)
        self.assertEqual(bob.age, 32)

        # Deletion
        #recursiveDelAttr(jill, 'friends[0]')
        #self.assertEqual(len(jill.friends) ,0)

        recursiveDelAttr(jill, 'age')
        assert not hasattr(jill, 'age')

        recursiveDelAttr(bob, 'friends[0].age')
        assert not hasattr(jack, 'age')

        # Unsupported
        #with self.assertRaises(NotImplementedError) as e:
        #   recursiveGetAttr(bob, 'friends[0+1]')

        # Nice try, function calls are not allowed
        #with self.assertRaises(ValueError):
        #   recursiveGetAttr(bob, 'friends.pop(0)')

        # Must be an expression
        with self.assertRaises(SyntaxError):
            recursiveGetAttr(bob, 'friends = []')

        # Must be an expression
        with self.assertRaises(SyntaxError):
            recursiveGetAttr(bob, 'friends..')

        # Must be an expression
        with self.assertRaises(KeyError):
            recursiveGetAttr(bob, 'settings["DoesNotExist"]')

        # Must be an expression
        with self.assertRaises(IndexError):
            recursiveGetAttr(bob, 'friends[100]')