test_scope.py 1.1 KB
Newer Older
1 2 3 4 5 6 7
import paddle.v2.framework.core
import unittest


class TestScope(unittest.TestCase):
    def test_create_destroy(self):
        paddle_c = paddle.v2.framework.core
Y
Yu Yang 已提交
8
        scope = paddle_c.Scope()
9
        self.assertIsNotNone(scope)
Y
Yu Yang 已提交
10
        scope_with_parent = scope.new_scope()
11 12 13 14
        self.assertIsNotNone(scope_with_parent)

    def test_none_variable(self):
        paddle_c = paddle.v2.framework.core
Y
Yu Yang 已提交
15 16
        scope = paddle_c.Scope()
        self.assertIsNone(scope.find_var("test"))
17 18 19

    def test_create_var_get_var(self):
        paddle_c = paddle.v2.framework.core
Y
Yu Yang 已提交
20
        scope = paddle_c.Scope()
D
dongzhihong 已提交
21
        var_a = scope.var("var_a")
22
        self.assertIsNotNone(var_a)
Y
Yu Yang 已提交
23 24 25
        self.assertIsNotNone(scope.find_var('var_a'))
        scope2 = scope.new_scope()
        self.assertIsNotNone(scope2.find_var('var_a'))
26 27 28

    def test_var_get_int(self):
        paddle_c = paddle.v2.framework.core
Y
Yu Yang 已提交
29
        scope = paddle_c.Scope()
D
dongzhihong 已提交
30
        var = scope.var("test_int")
31 32 33 34 35 36 37
        var.set_int(10)
        self.assertTrue(var.is_int())
        self.assertEqual(10, var.get_int())


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