test_protobuf_descs.py 1.4 KB
Newer Older
Y
Update  
Yu Yang 已提交
1 2 3 4 5 6 7 8 9 10 11
import unittest
import paddle.v2.framework.core as core


class TestProgramDesc(unittest.TestCase):
    def test_instance(self):
        program_desc = core.ProgramDesc.instance()
        self.assertIsNotNone(program_desc)
        del program_desc
        program_desc = core.ProgramDesc.instance()
        self.assertIsNotNone(program_desc)
Y
Yu Yang 已提交
12
        self.assertIsNotNone(program_desc.root_block())
Y
Update  
Yu Yang 已提交
13 14
        del program_desc

Y
Yu Yang 已提交
15 16 17
    def test_append_block(self):
        prog_desc = core.ProgramDesc.__create_program_desc__()
        self.assertIsNotNone(prog_desc)
F
fengjiayi 已提交
18 19 20
        block_root = prog_desc.root_block()
        self.assertEqual(block_root.id(), 0)
        block1 = prog_desc.append_block(block_root)
Y
Yu Yang 已提交
21 22
        block2 = prog_desc.append_block(block1)
        self.assertEqual(block1.id(), block2.parent())
F
fengjiayi 已提交
23 24 25
        self.assertEqual(block_root.id(), block1.parent())
        block3 = prog_desc.append_block(block_root)
        self.assertEqual(block3.parent(), block_root.id())
26
        self.assertEqual(prog_desc.block(1).id(), 1)
F
fengjiayi 已提交
27 28 29 30 31 32 33 34 35 36 37


class TestVarDesc(unittest.TestCase):
    def test_shape(self):
        program_desc = core.ProgramDesc.instance()
        block = program_desc.root_block()
        var = block.new_var()
        src_shape = [3, 2, 10, 8]
        var.set_shape(src_shape)
        res_shape = var.shape()
        self.assertEqual(src_shape, res_shape)
Y
Yu Yang 已提交
38

Y
Update  
Yu Yang 已提交
39 40 41

if __name__ == '__main__':
    unittest.main()