提交 34735e96 编写于 作者: Z zhhsplendid

Fix unittest, test=develop

上级 ea2ad88f
...@@ -65,7 +65,7 @@ class TestOriginInfo(unittest.TestCase): ...@@ -65,7 +65,7 @@ class TestOriginInfo(unittest.TestCase):
self.func = simple_func self.func = simple_func
def set_static_lineno(self): def set_static_lineno(self):
self.static_abs_lineno_list = [2, 3, 4] self.static_abs_lineno_list = [3, 4, 5]
def set_dygraph_info(self): def set_dygraph_info(self):
self.line_num = 3 self.line_num = 3
...@@ -149,7 +149,7 @@ class TestOriginInfoWithNestedFunc(TestOriginInfo): ...@@ -149,7 +149,7 @@ class TestOriginInfoWithNestedFunc(TestOriginInfo):
self.func = nested_func self.func = nested_func
def set_static_lineno(self): def set_static_lineno(self):
self.static_abs_lineno_list = [2, 4, 5, 6, 7] self.static_abs_lineno_list = [3, 5, 6, 7, 8]
def set_dygraph_info(self): def set_dygraph_info(self):
self.line_num = 5 self.line_num = 5
...@@ -174,7 +174,7 @@ class TestOriginInfoWithDecoratedFunc(TestOriginInfo): ...@@ -174,7 +174,7 @@ class TestOriginInfoWithDecoratedFunc(TestOriginInfo):
self.func = decorated_func self.func = decorated_func
def set_static_lineno(self): def set_static_lineno(self):
self.static_abs_lineno_list = [2, 3] self.static_abs_lineno_list = [3, 4]
def set_dygraph_info(self): def set_dygraph_info(self):
self.line_num = 2 self.line_num = 2
...@@ -208,7 +208,7 @@ class TestOriginInfoWithDecoratedFunc2(TestOriginInfo): ...@@ -208,7 +208,7 @@ class TestOriginInfoWithDecoratedFunc2(TestOriginInfo):
self.func = decorated_func2 self.func = decorated_func2
def set_static_lineno(self): def set_static_lineno(self):
self.static_abs_lineno_list = [2, 3] self.static_abs_lineno_list = [3, 4]
def set_dygraph_info(self): def set_dygraph_info(self):
self.line_num = 2 self.line_num = 2
......
...@@ -63,11 +63,9 @@ def get_source_code(func): ...@@ -63,11 +63,9 @@ def get_source_code(func):
class StaticCode1(): class StaticCode1():
# TODO: Transform return statement # TODO: Transform return statement
def dyfunc_with_if_else(x_v, label=None): def dyfunc_with_if_else(x_v, label=None):
__return_1 = fluid.layers.fill_constant( __return_1 = paddle.fill_constant(shape=[1], dtype='bool', value=False)
shape=[1], dtype='bool', value=False) __return_0 = paddle.fill_constant(shape=[1], dtype='bool', value=False)
__return_0 = fluid.layers.fill_constant( __return_value_init_0 = paddle.fill_constant(
shape=[1], dtype='bool', value=False)
__return_value_init_0 = fluid.layers.fill_constant(
shape=[1], dtype='float64', value=0.0) shape=[1], dtype='float64', value=0.0)
__return_value_0 = __return_value_init_0 __return_value_0 = __return_value_init_0
...@@ -79,13 +77,13 @@ class StaticCode1(): ...@@ -79,13 +77,13 @@ class StaticCode1():
x_v = x_v + 1 x_v = x_v + 1
return x_v return x_v
x_v = fluid.dygraph.dygraph_to_static.convert_operators.convert_ifelse( x_v = paddle.jit.dygraph_to_static.convert_operators.convert_ifelse(
fluid.layers.mean(x_v)[0] > 5, true_fn_0, false_fn_0, (x_v, ), fluid.layers.mean(x_v)[0] > 5, true_fn_0, false_fn_0, (x_v, ),
(x_v, ), (x_v, )) (x_v, ), (x_v, ))
def true_fn_1(__return_0, __return_value_0, label, x_v): def true_fn_1(__return_0, __return_value_0, label, x_v):
loss = fluid.layers.cross_entropy(x_v, label) loss = fluid.layers.cross_entropy(x_v, label)
__return_0 = fluid.layers.fill_constant( __return_0 = paddle.fill_constant(
shape=[1], dtype='bool', value=True) shape=[1], dtype='bool', value=True)
__return_value_0 = loss __return_value_0 = loss
return __return_0, __return_value_0 return __return_0, __return_value_0
...@@ -94,13 +92,13 @@ class StaticCode1(): ...@@ -94,13 +92,13 @@ class StaticCode1():
return __return_0, __return_value_0 return __return_0, __return_value_0
__return_0, __return_value_0 = ( __return_0, __return_value_0 = (
fluid.dygraph.dygraph_to_static.convert_operators.convert_ifelse( paddle.jit.dygraph_to_static.convert_operators.convert_ifelse(
label is not None, true_fn_1, false_fn_1, label is not None, true_fn_1, false_fn_1,
(__return_0, __return_value_0, label, x_v), (__return_0, __return_value_0, label, x_v),
(__return_0, __return_value_0), (__return_0, __return_value_0))) (__return_0, __return_value_0), (__return_0, __return_value_0)))
def true_fn_2(__return_1, __return_value_0, x_v): def true_fn_2(__return_1, __return_value_0, x_v):
__return_1 = fluid.layers.fill_constant( __return_1 = paddle.fill_constant(
shape=[1], dtype='bool', value=True) shape=[1], dtype='bool', value=True)
__return_value_0 = x_v __return_value_0 = x_v
return __return_1, __return_value_0 return __return_1, __return_value_0
...@@ -109,8 +107,8 @@ class StaticCode1(): ...@@ -109,8 +107,8 @@ class StaticCode1():
return __return_1, __return_value_0 return __return_1, __return_value_0
__return_1, __return_value_0 = ( __return_1, __return_value_0 = (
fluid.dygraph.dygraph_to_static.convert_operators.convert_ifelse( paddle.jit.dygraph_to_static.convert_operators.convert_ifelse(
fluid.dygraph.dygraph_to_static.convert_operators. paddle.jit.dygraph_to_static.convert_operators.
convert_logical_not(__return_0), true_fn_2, false_fn_2, convert_logical_not(__return_0), true_fn_2, false_fn_2,
(__return_1, __return_value_0, x_v), (__return_1, __return_value_0, x_v),
(__return_1, __return_value_0), (__return_1, __return_value_0))) (__return_1, __return_value_0), (__return_1, __return_value_0)))
...@@ -120,11 +118,9 @@ class StaticCode1(): ...@@ -120,11 +118,9 @@ class StaticCode1():
class StaticCode2(): class StaticCode2():
# TODO: Transform return statement # TODO: Transform return statement
def dyfunc_with_if_else(x_v, label=None): def dyfunc_with_if_else(x_v, label=None):
__return_3 = fluid.layers.fill_constant( __return_3 = paddle.fill_constant(shape=[1], dtype='bool', value=False)
shape=[1], dtype='bool', value=False) __return_2 = paddle.fill_constant(shape=[1], dtype='bool', value=False)
__return_2 = fluid.layers.fill_constant( __return_value_init_1 = paddle.fill_constant(
shape=[1], dtype='bool', value=False)
__return_value_init_1 = fluid.layers.fill_constant(
shape=[1], dtype='float64', value=0.0) shape=[1], dtype='float64', value=0.0)
__return_value_1 = __return_value_init_1 __return_value_1 = __return_value_init_1
...@@ -136,13 +132,13 @@ class StaticCode2(): ...@@ -136,13 +132,13 @@ class StaticCode2():
x_v = x_v + 1 x_v = x_v + 1
return x_v return x_v
x_v = fluid.dygraph.dygraph_to_static.convert_operators.convert_ifelse( x_v = paddle.jit.dygraph_to_static.convert_operators.convert_ifelse(
fluid.layers.mean(x_v)[0] > 5, true_fn_3, false_fn_3, (x_v, ), fluid.layers.mean(x_v)[0] > 5, true_fn_3, false_fn_3, (x_v, ),
(x_v, ), (x_v, )) (x_v, ), (x_v, ))
def true_fn_4(__return_2, __return_value_1, label, x_v): def true_fn_4(__return_2, __return_value_1, label, x_v):
loss = fluid.layers.cross_entropy(x_v, label) loss = fluid.layers.cross_entropy(x_v, label)
__return_2 = fluid.layers.fill_constant( __return_2 = paddle.fill_constant(
shape=[1], dtype='bool', value=True) shape=[1], dtype='bool', value=True)
__return_value_1 = loss __return_value_1 = loss
return __return_2, __return_value_1 return __return_2, __return_value_1
...@@ -151,13 +147,13 @@ class StaticCode2(): ...@@ -151,13 +147,13 @@ class StaticCode2():
return __return_2, __return_value_1 return __return_2, __return_value_1
__return_2, __return_value_1 = ( __return_2, __return_value_1 = (
fluid.dygraph.dygraph_to_static.convert_operators.convert_ifelse( paddle.jit.dygraph_to_static.convert_operators.convert_ifelse(
label is not None, true_fn_4, false_fn_4, label is not None, true_fn_4, false_fn_4,
(__return_2, __return_value_1, label, x_v), (__return_2, __return_value_1, label, x_v),
(__return_2, __return_value_1), (__return_2, __return_value_1))) (__return_2, __return_value_1), (__return_2, __return_value_1)))
def true_fn_5(__return_3, __return_value_1, x_v): def true_fn_5(__return_3, __return_value_1, x_v):
__return_3 = fluid.layers.fill_constant( __return_3 = paddle.fill_constant(
shape=[1], dtype='bool', value=True) shape=[1], dtype='bool', value=True)
__return_value_1 = x_v __return_value_1 = x_v
return __return_3, __return_value_1 return __return_3, __return_value_1
...@@ -166,8 +162,8 @@ class StaticCode2(): ...@@ -166,8 +162,8 @@ class StaticCode2():
return __return_3, __return_value_1 return __return_3, __return_value_1
__return_3, __return_value_1 = ( __return_3, __return_value_1 = (
fluid.dygraph.dygraph_to_static.convert_operators.convert_ifelse( paddle.jit.dygraph_to_static.convert_operators.convert_ifelse(
fluid.dygraph.dygraph_to_static.convert_operators. paddle.jit.dygraph_to_static.convert_operators.
convert_logical_not(__return_2), true_fn_5, false_fn_5, convert_logical_not(__return_2), true_fn_5, false_fn_5,
(__return_3, __return_value_1, x_v), (__return_3, __return_value_1, x_v),
(__return_3, __return_value_1), (__return_3, __return_value_1))) (__return_3, __return_value_1), (__return_3, __return_value_1)))
......
...@@ -51,24 +51,24 @@ class TestDataLayerNotCheck(unittest.TestCase): ...@@ -51,24 +51,24 @@ class TestDataLayerNotCheck(unittest.TestCase):
class TestVariableTransFunc(unittest.TestCase): class TestVariableTransFunc(unittest.TestCase):
def test_create_fill_constant_node(self): def test_create_fill_constant_node(self):
node = create_fill_constant_node("a", 1.0) node = create_fill_constant_node("a", 1.0)
source = "a = fluid.layers.fill_constant(shape=[1], dtype='float64', value=1.0)" source = "a = paddle.fill_constant(shape=[1], dtype='float64', value=1.0)"
self.assertEqual(ast_to_source_code(node).strip(), source) self.assertEqual(ast_to_source_code(node).strip(), source)
node = create_fill_constant_node("b", True) node = create_fill_constant_node("b", True)
source = "b = fluid.layers.fill_constant(shape=[1], dtype='bool', value=True)" source = "b = paddle.fill_constant(shape=[1], dtype='bool', value=True)"
self.assertEqual(ast_to_source_code(node).strip(), source) self.assertEqual(ast_to_source_code(node).strip(), source)
if six.PY2: if six.PY2:
node = create_fill_constant_node("c", 214) node = create_fill_constant_node("c", 214)
source = "c = fluid.layers.fill_constant(shape=[1], dtype='int32', value=214)" source = "c = paddle.fill_constant(shape=[1], dtype='int32', value=214)"
self.assertEqual(ast_to_source_code(node).strip(), source) self.assertEqual(ast_to_source_code(node).strip(), source)
node = create_fill_constant_node("d", long(10086)) node = create_fill_constant_node("d", long(10086))
source = "d = fluid.layers.fill_constant(shape=[1], dtype='int64', value=10086)" source = "d = paddle.fill_constant(shape=[1], dtype='int64', value=10086)"
self.assertEqual(ast_to_source_code(node).strip(), source) self.assertEqual(ast_to_source_code(node).strip(), source)
else: else:
node = create_fill_constant_node("c", 4293) node = create_fill_constant_node("c", 4293)
source = "c = fluid.layers.fill_constant(shape=[1], dtype='int64', value=4293)" source = "c = paddle.fill_constant(shape=[1], dtype='int64', value=4293)"
self.assertEqual(ast_to_source_code(node).strip(), source) self.assertEqual(ast_to_source_code(node).strip(), source)
self.assertIsNone(create_fill_constant_node("e", None)) self.assertIsNone(create_fill_constant_node("e", None))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册