Skip to content

Commit b678c37

Browse files
committed
fix(action): windows os does not allow to delete tmp file
1 parent d379032 commit b678c37

File tree

3 files changed

+12
-35
lines changed

3 files changed

+12
-35
lines changed

binding/python/tests/test_buffer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,3 @@ def test_missmatch_length_of_metadata():
233233
# this is not a valid since the metadata
234234
# size doe not match as it too big
235235
_ = load(buffer)
236-

binding/python/tests/test_np.py

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -104,26 +104,21 @@ def test_invalid_tensor_dict_raises_error():
104104
def test_save_file_and_load_file_consistency():
105105
tensor_dict = create_gpt2_numpy_dict(1)
106106
filename = ""
107-
with tempfile.NamedTemporaryFile(delete=False) as tmp:
107+
loaded_dict = {}
108+
with tempfile.NamedTemporaryFile() as tmp:
108109
filename = tmp.name
109-
110-
try:
111-
save_file(tensor_dict, filename)
112-
loaded_dict = load_file(filename)
113-
114-
for key, value in tensor_dict.items():
115-
assert _compare_np_array(loaded_dict[key], value)
116-
finally:
117-
if os.path.exists(filename):
118-
os.remove(filename)
110+
try:
111+
save_file(tensor_dict, filename)
112+
loaded_dict = load_file(filename)
113+
finally:
114+
for key, value in tensor_dict.items():
115+
assert _compare_np_array(loaded_dict[key], value)
119116

120117

121118
def test_safe_open_access_and_metadata():
122119
tensor_dict = create_gpt2_numpy_dict(1)
123-
with tempfile.NamedTemporaryFile(delete=False) as tmp:
120+
with tempfile.NamedTemporaryFile() as tmp:
124121
filename = tmp.name
125-
126-
try:
127122
# save file into tempfile
128123
save_file(tensor_dict, filename)
129124

@@ -132,22 +127,15 @@ def test_safe_open_access_and_metadata():
132127
assert model.get_tensor("h.0.ln_1.weight") is not None
133128
assert model.get_tensor("h.0.ln_1.bias") is not None
134129
assert model.metadata() is None
135-
finally:
136-
if os.path.exists(filename):
137-
os.remove(filename)
138130

139131

140132
def test_safe_open_access_with_metadata():
141133
tensor_dict = create_gpt2_numpy_dict(1)
142-
with tempfile.NamedTemporaryFile(delete=False) as tmp:
134+
with tempfile.NamedTemporaryFile() as tmp:
143135
filename = tmp.name
144136

145-
try:
146137
save_file(tensor_dict, filename, metadata={"hello": "world"})
147138
with safe_open(filename, "numpy") as model:
148139
assert model.get_tensor("h.0.ln_1.weight") is not None
149140
assert model.get_tensor("h.0.ln_1.bias") is not None
150141
assert model.metadata()["hello"] == "world"
151-
finally:
152-
if os.path.exists(filename):
153-
os.remove(filename)

binding/python/tests/test_pt.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,31 +106,21 @@ def test_pt_invalid_tensor_dict_raises_error():
106106
def test_pt_save_file_and_load_file_consistency():
107107
tensor_dict = create_gpt2_tensors_dict(1)
108108
filename = ""
109-
with tempfile.NamedTemporaryFile(delete=False) as tmp:
109+
with tempfile.NamedTemporaryFile() as tmp:
110110
filename = tmp.name
111-
112-
try:
113111
save_file(tensor_dict, filename)
114112
loaded_dict = load_file(filename)
115113

116114
for key, value in tensor_dict.items():
117115
assert _compare_torch_tensors(loaded_dict[key], value)
118-
finally:
119-
if os.path.exists(filename):
120-
os.remove(filename)
121116

122117

123118
def test_pt_safe_open_access_and_metadata():
124119
tensor_dict = create_gpt2_tensors_dict(1)
125-
with tempfile.NamedTemporaryFile(delete=False) as tmp:
120+
with tempfile.NamedTemporaryFile() as tmp:
126121
filename = tmp.name
127-
128-
try:
129122
save_file(tensor_dict, filename)
130123
with safe_open(filename, "pt") as model:
131124
assert model.get_tensor("h.0.ln_1.weight") is not None
132125
assert model.get_tensor("h.0.ln_1.bias") is not None
133126
assert model.metadata() is None
134-
finally:
135-
if os.path.exists(filename):
136-
os.remove(filename)

0 commit comments

Comments
 (0)