def test_ast_policy(self):
        'Policy: Keep tidy ASTs'

        a = Discard(Name('a'))
        empty = Stmt([])

        self.assertEqual(empty, Block('').ast)
        self.assertEqual(empty, Block(empty).ast)
        self.assertEqual(empty, Block(Module(None, empty)).ast)

        self.assertEqual(a, Block('a').ast)
        self.assertEqual(a, Block(a).ast)
        self.assertEqual(a, Block(Stmt([a])).ast)
        self.assertEqual(a, Block(Module(None, Stmt([a]))).ast)

        # Similar, except we don't use strings since Block does its own parsing
        b = Block()
        b.ast = empty
        self.assertEqual(b.ast, empty)
        b.ast = Module(None, empty)
        self.assertEqual(b.ast, empty)
        b.ast = a
        self.assertEqual(b.ast, a)
        b.ast = Stmt([a])
        self.assertEqual(b.ast, a)
        b.ast = Module(None, Stmt([a]))
        self.assertEqual(b.ast, a)
Beispiel #2
0
    def test_ast_policy(self):
        'Policy: Keep tidy ASTs'

        a = Discard(Name('a'))
        empty = Stmt([])

        self.assertEqual(empty, Block('').ast)
        self.assertEqual(empty, Block(empty).ast)
        self.assertEqual(empty, Block(Module(None, empty)).ast)

        self.assertEqual(a, Block('a').ast)
        self.assertEqual(a, Block(a).ast)
        self.assertEqual(a, Block(Stmt([a])).ast)
        self.assertEqual(a, Block(Module(None, Stmt([a]))).ast)

        # Similar, except we don't use strings since Block does its own parsing
        b = Block()
        b.ast = empty
        self.assertEqual(b.ast, empty)
        b.ast = Module(None, empty)
        self.assertEqual(b.ast, empty)
        b.ast = a
        self.assertEqual(b.ast, a)
        b.ast = Stmt([a])
        self.assertEqual(b.ast, a)
        b.ast = Module(None, Stmt([a]))
        self.assertEqual(b.ast, a)
    def test_caching_code(self):
        "Caching: '_code'"

        b, c = Block('a=2'), {}
        b._code
        b.ast = Block('a=3').ast
        b.execute(c)
        self.assertEqual(c['a'], 3)

        b, c = Block('a=2'), {}
        b._code
        b.sub_blocks = [Block('a=3')]
        b.execute(c)
        self.assertEqual(c['a'], 3)

        b, c = Block('a=3; a=2'), {}
        b._code
        b.sub_blocks.pop()
        b.execute(c)
        self.assertEqual(c['a'], 3)

        b, c = Block(''), {}
        b._code
        b.sub_blocks.append(Block('a=3'))
        b.sub_blocks = [Block('a=3')]
        b.execute(c)
        assert 'a' in c
Beispiel #4
0
    def test_caching_code(self):
        "Caching: '_code'"

        b,c = Block('a=2'), {}
        b._code
        b.ast = Block('a=3').ast
        b.execute(c)
        self.assertEqual(c['a'], 3)

        b,c = Block('a=2'), {}
        b._code
        b.sub_blocks = [Block('a=3')]
        b.execute(c)
        self.assertEqual(c['a'], 3)

        b,c = Block('a=3; a=2'), {}
        b._code
        b.sub_blocks.pop()
        b.execute(c)
        self.assertEqual(c['a'], 3)

        b,c = Block(''), {}
        b._code
        b.sub_blocks.append(Block('a=3'))
        b.sub_blocks = [Block('a=3')]
        b.execute(c)
        assert 'a' in c
    def test_caching_dep_graph_restrict(self):
        "Caching: '_dep_graph', 'restrict'"

        # '_dep_graph' determines the behavior of 'restrict', so we can test
        # them together.

        b = Block('a=2; b=a; z=a')
        self.assertSimilar(b.restrict(outputs='z'), Block('a=2; z=a'))
        b.sub_blocks = [Block('z=0')]
        self.assertSimilar(b.restrict(outputs='z'), Block('z=0'))

        b = Block('a=2; b=a; z=a')
        self.assertSimilar(b.restrict(outputs='z'), Block('a=2; z=a'))
        b.ast = Block('z=0').ast
        self.assertSimilar(b.restrict(outputs='z'), Block('z=0'))
Beispiel #6
0
    def test_caching_dep_graph_restrict(self):
        "Caching: '_dep_graph', 'restrict'"

        # '_dep_graph' determines the behavior of 'restrict', so we can test
        # them together.

        b = Block('a=2; b=a; z=a')
        self.assertSimilar(b.restrict(outputs='z'), Block('a=2; z=a'))
        b.sub_blocks = [Block('z=0')]
        self.assertSimilar(b.restrict(outputs='z'), Block('z=0'))

        b = Block('a=2; b=a; z=a')
        self.assertSimilar(b.restrict(outputs='z'), Block('a=2; z=a'))
        b.ast = Block('z=0').ast
        self.assertSimilar(b.restrict(outputs='z'), Block('z=0'))