test_scope.py 1.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
import paddle.v2.framework.core
import unittest


class TestScope(unittest.TestCase):
    def test_create_destroy(self):
        paddle_c = paddle.v2.framework.core
        scope = paddle_c.Scope(None)
        self.assertIsNotNone(scope)
        scope_with_parent = paddle_c.Scope(scope)
        self.assertIsNotNone(scope_with_parent)

    def test_none_variable(self):
        paddle_c = paddle.v2.framework.core
        scope = paddle_c.Scope(None)
        self.assertIsNone(scope.get_var("test"))

    def test_create_var_get_var(self):
        paddle_c = paddle.v2.framework.core
        scope = paddle_c.Scope(None)
        var_a = scope.create_var("var_a")
        self.assertIsNotNone(var_a)
        self.assertIsNotNone(scope.get_var('var_a'))
        scope2 = paddle_c.Scope(scope)
        self.assertIsNotNone(scope2.get_var('var_a'))

    def test_var_get_int(self):
        paddle_c = paddle.v2.framework.core
        scope = paddle_c.Scope(None)
        var = scope.create_var("test_int")
        var.set_int(10)
        self.assertTrue(var.is_int())
        self.assertEqual(10, var.get_int())


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