Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 933b370

Browse files
geza-pycompeter-pycom
authored andcommitted
Add the modified functionality to the regression tests
1 parent bd5d405 commit 933b370

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

tests/esp32/fs_file.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,32 @@ def file_seek_test(path):
7474
print("{0}, f.tell(): {1}".format(path, f.tell()))
7575
f.close()
7676

77+
def file_double_close_test(path):
78+
f = open(path)
79+
# Nothing should be printed out
80+
f.close()
81+
f.close()
82+
f.close()
83+
84+
def file_operations_after_close_test(path):
85+
f = open(path, "rw")
86+
f.close()
87+
try:
88+
f.read()
89+
except Exception as e:
90+
print("{0}, Exception after f.read: {1}".format(path, e))
91+
try:
92+
f.write("aaa")
93+
except Exception as e:
94+
print("{0}, Exception after f.write: {1}".format(path, e))
95+
try:
96+
f.flush()
97+
except Exception as e:
98+
print("{0}, Exception after f.flush: {1}".format(path, e))
99+
# No exception should be dropped
100+
f.seek(12)
101+
f.tell()
102+
77103

78104
sd = SD()
79105
sd_fat_fs = os.mkfat(sd)
@@ -157,6 +183,14 @@ def file_seek_test(path):
157183
file_readline_test(f_path)
158184
file_readline_test(sd_path)
159185

186+
#Test multiple file.close
187+
file_double_close_test(f_path)
188+
file_double_close_test(sd_path)
189+
190+
#Test other operations after file.close()
191+
file_operations_after_close_test(f_path)
192+
file_operations_after_close_test(sd_path)
193+
160194
os.remove(f_path)
161195
os.remove(sd_path)
162196
os.umount("/sd")

tests/esp32/fs_file.py.exp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,9 @@ bytearray(b'0123456789')
6666
/sd/t.txt, f.readline(10): 01234
6767

6868
/sd/t.txt, f.readlines(): ['01234\n', '56789']
69+
/flash/t.txt, Exception after f.read: [Errno 22] EINVAL
70+
/flash/t.txt, Exception after f.write: [Errno 22] EINVAL
71+
/flash/t.txt, Exception after f.flush: [Errno 22] EINVAL
72+
/sd/t.txt, Exception after f.read: [Errno 22] EINVAL
73+
/sd/t.txt, Exception after f.write: [Errno 22] EINVAL
74+
/sd/t.txt, Exception after f.flush: [Errno 22] EINVAL

0 commit comments

Comments
 (0)