Beispiel #1
0
    def test_augmented_assignment(self):
        'Augmented assignment'

        equivalent_pairs = (
            ('a += b', 'a = a + b'),
            ('a |= b - c', 'a = a | (b - c)'),
            ('a.b += c.d', 'a.b = a.b + c.d'),
            ('a[i] += b[j]', 'a[i] = a[i] + b[j]'),
        )

        for c1, c2 in equivalent_pairs:
            ast1, ast2 = parse(c1), parse(c2)
            self.assertEqual(free_vars(ast1), free_vars(ast2))
            self.assertEqual(local_vars(ast1), local_vars(ast2))
            self.assertEqual(conditional_local_vars(ast1),
                             conditional_local_vars(ast2))
Beispiel #2
0
    def test_augmented_assignment(self):
        'Augmented assignment'

        equivalent_pairs = (
            ('a += b', 'a = a + b'),
            ('a |= b - c', 'a = a | (b - c)'),
            ('a.b += c.d', 'a.b = a.b + c.d'),
            ('a[i] += b[j]', 'a[i] = a[i] + b[j]'),
        )

        for c1,c2 in equivalent_pairs:
            ast1, ast2 = parse(c1), parse(c2)
            self.assertEqual(free_vars(ast1), free_vars(ast2))
            self.assertEqual(local_vars(ast1), local_vars(ast2))
            self.assertEqual(conditional_local_vars(ast1),
                             conditional_local_vars(ast2))
Beispiel #3
0
 def _base(self, code, free, locals=(), conditional_locals=()):
     ast = parse(code)
     self.assertEqual(set(free), set(free_vars(ast)))
     self.assertEqual(set(locals), set(local_vars(ast)))
     self.assertEqual(set(conditional_locals),
                      set(conditional_local_vars(ast)))
Beispiel #4
0
 def _base(self, code, free, locals=(), conditional_locals=()):
     ast = parse(code)
     self.assertEqual(set(free), set(free_vars(ast)))
     self.assertEqual(set(locals), set(local_vars(ast)))
     self.assertEqual(set(conditional_locals),
                      set(conditional_local_vars(ast)))