Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
Organize testing
Browse files Browse the repository at this point in the history
  • Loading branch information
gouzil committed Sep 24, 2023
1 parent fcce34e commit b7b402c
Showing 1 changed file with 41 additions and 47 deletions.
88 changes: 41 additions & 47 deletions tests/test_19_closure.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,33 +167,24 @@ def closure():
return closure


class TestClosure(TestCaseBase):
def test_closure(self):
self.assert_results(foo, 1, paddle.to_tensor(2))
self.assert_results(foo2, paddle.to_tensor(2))
self.assert_results(foo3, paddle.to_tensor(2))
self.assert_results(foo5, paddle.to_tensor(2))

def test_global(self):
self.assert_results_with_global_check(
test_global, ["global_z"], paddle.to_tensor(2)
)

def test_lambda(self):
with strict_mode_guard(0):
self.assert_results(
lambda_closure, paddle.to_tensor(2), paddle.to_tensor(1)
)
def non_local_test(t: paddle.Tensor):
a = 1

def test_numpy(self):
self.assert_results(numpy_sum, paddle.to_tensor(1))
def func1():
nonlocal a
t = a
a = 2
return t

def test_del_deref(self):
self.assert_results(closure_del)
def func2():
nonlocal a
a = 1
return a

def test_decorator(self):
self.assert_results(test_builtin_decorator)
self.assert_results(foo6, paddle.to_tensor(2))
t += func1() # add 2
t += func2() # add 1
t += a # add 1
return t


# Side Effect.
Expand All @@ -214,40 +205,43 @@ def test_slice_in_for_loop(x, iter_num=3):
return out


class TestExecutor3(TestCaseBase):
class TestClosure(TestCaseBase):
def test_closure(self):
tx = paddle.to_tensor([1.0, 2.0, 3.0])
# need side effect of list.
# self.assert_results(test_slice_in_for_loop, tx)

self.assert_results(foo, 1, paddle.to_tensor(2))
self.assert_results(foo2, paddle.to_tensor(2))
self.assert_results(foo3, paddle.to_tensor(2))
self.assert_results(foo5, paddle.to_tensor(2))

def non_local_test(t: paddle.Tensor):
a = 1
def test_global(self):
self.assert_results_with_global_check(
test_global, ["global_z"], paddle.to_tensor(2)
)

def func1():
nonlocal a
t = a
a = 2
return t
def test_lambda(self):
with strict_mode_guard(0):
self.assert_results(
lambda_closure, paddle.to_tensor(2), paddle.to_tensor(1)
)

def func2():
nonlocal a
a = 1
return a
def test_numpy(self):
self.assert_results(numpy_sum, paddle.to_tensor(1))

t += func1() # add 2
t += func2() # add 1
t += a # add 1
return t
def test_del_deref(self):
self.assert_results(closure_del)

def test_decorator(self):
self.assert_results(test_builtin_decorator)
self.assert_results(foo6, paddle.to_tensor(2))

class TestExecutor4(TestCaseBase):
def test_closure(self):
def test_nolocal(self):
tx = paddle.to_tensor([1.0])
self.assert_results(non_local_test, tx)

def test_side_effect(self):
tx = paddle.to_tensor([1.0, 2.0, 3.0])
# need side effect of list.
self.assert_results_with_side_effects(test_slice_in_for_loop, tx)

class TestCreateClosure(TestCaseBase):
def test_create_closure(self):
closure = create_closure()
self.assert_results(closure)
Expand Down

0 comments on commit b7b402c

Please sign in to comment.