Skip to content

Commit

Permalink
fix test_paddle_save_load and test_paddle_save_load_binary (#32949)
Browse files Browse the repository at this point in the history
* fix test_paddle_save_load and test_paddle_save_load_binary

* fix unittest:test_paddle_save_load and test_paddle_save_load_binary

* delete *.pyc

* add comment for unittest
  • Loading branch information
hbwx24 authored May 19, 2021
1 parent 7896b51 commit 6f8de31
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
9 changes: 4 additions & 5 deletions python/paddle/fluid/tests/unittests/test_paddle_save_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,11 +412,10 @@ def test_save_load_complex_object_dygraph_save(self):
]
obj2 = {'k1': obj1, 'k2': state_dict, 'epoch': 123}
obj3 = (paddle.randn(
[5, 4], dtype='float32'), np.ndarray(
[3, 4], dtype="float32"), {
"state_dict": state_dict,
"opt": state_dict
})
[5, 4], dtype='float32'), np.random.randn(3, 4).astype("float32"), {
"state_dict": state_dict,
"opt": state_dict
})
obj4 = (np.random.randn(5, 6), (123, ))

path1 = "test_save_load_any_complex_object_dygraph/obj1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import os
import sys
import six
import platform

import paddle
import paddle.nn as nn
Expand Down Expand Up @@ -162,12 +163,13 @@ def test_save_load_lod_tensor(self):
with self.assertRaises(NotImplementedError):
path = 'test_save_load_error/temp'
paddle.save({}, path, use_binary_format=True)

with self.assertRaises(ValueError):
path = 'test_save_load_error/temp'
with open(path, "w") as f:
f.write('\0')
paddle.load(path)
# On the Windows platform, when parsing a string that can't be parsed as a `Program`, `desc_.ParseFromString` has a timeout risk.
if 'Windows' != platform.system():
with self.assertRaises(ValueError):
path = 'test_save_load_error/temp'
with open(path, "w") as f:
f.write('\0')
paddle.load(path)

with self.assertRaises(ValueError):
temp_lod = fluid.core.LoDTensor()
Expand Down

0 comments on commit 6f8de31

Please sign in to comment.