This repository was archived by the owner on Sep 16, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff 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
78104sd = SD ()
79105sd_fat_fs = os .mkfat (sd )
@@ -157,6 +183,14 @@ def file_seek_test(path):
157183file_readline_test (f_path )
158184file_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+
160194os .remove (f_path )
161195os .remove (sd_path )
162196os .umount ("/sd" )
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments