Lines Matching refs:f
24 self.f = _FileIO(TESTFN, 'w')
27 if self.f:
28 self.f.close()
33 p = proxy(self.f)
35 self.assertEqual(self.f.tell(), p.tell())
36 self.f.close()
37 self.f = None
41 self.f.write(bytes(range(20)))
42 self.assertEqual(self.f.tell(), 20)
43 self.f.seek(0)
44 self.assertEqual(self.f.tell(), 0)
45 self.f.seek(10)
46 self.assertEqual(self.f.tell(), 10)
47 self.f.seek(5, 1)
48 self.assertEqual(self.f.tell(), 15)
49 self.f.seek(-5, 1)
50 self.assertEqual(self.f.tell(), 10)
51 self.f.seek(-5, 2)
52 self.assertEqual(self.f.tell(), 15)
56 f = self.f
58 self.assertEqual(f.mode, "wb")
59 self.assertEqual(f.closed, False)
64 setattr, f, attr, 'oops')
68 self.f.write(b"\x01\x02")
69 self.f.close()
71 self.f = _FileIO(TESTFN, 'r')
72 n = self.f.readinto(a)
77 self.f.writelines(l)
78 self.f.close()
79 self.f = _FileIO(TESTFN, 'rb')
80 buf = self.f.read()
85 self.f.writelines(l)
86 self.f.close()
87 self.f = _FileIO(TESTFN, 'rb')
88 buf = self.f.read()
92 self.assertRaises(TypeError, self.f.writelines, [1, 2, 3])
93 self.assertRaises(TypeError, self.f.writelines, None)
96 self.f.write(b"hi\nbye\nabc")
97 self.f.close()
98 self.f = _FileIO(TESTFN, 'r')
99 self.assertEqual(self.f.read(None), b"hi\nbye\nabc")
100 self.f.seek(0)
101 self.assertEqual(self.f.readline(None), b"hi\n")
102 self.assertEqual(self.f.readlines(None), [b"bye\n", b"abc"])
105 self.assertEqual(repr(self.f), "<_io.FileIO name=%r mode='%s'>"
106 % (self.f.name, self.f.mode))
107 del self.f.name
108 self.assertEqual(repr(self.f), "<_io.FileIO fd=%r mode='%s'>"
109 % (self.f.fileno(), self.f.mode))
110 self.f.close()
111 self.assertEqual(repr(self.f), "<_io.FileIO [closed]>")
114 f = self.f
115 self.assertFalse(f.isatty())
116 self.assertFalse(f.closed)
118 self.assertRaises(ValueError, f.read, 10) # Open for reading
119 f.close()
120 self.assertTrue(f.closed)
121 f = _FileIO(TESTFN, 'r')
122 self.assertRaises(TypeError, f.readinto, "")
123 self.assertFalse(f.closed)
124 f.close()
125 self.assertTrue(f.closed)
134 self.f.close()
135 self.assertTrue(self.f.closed)
138 method = getattr(self.f, methodname)
142 self.assertRaises(ValueError, self.f.readinto) # XXX should be TypeError?
143 self.assertRaises(ValueError, self.f.readinto, bytearray(1))
144 self.assertRaises(ValueError, self.f.seek)
145 self.assertRaises(ValueError, self.f.seek, 0)
146 self.assertRaises(ValueError, self.f.write)
147 self.assertRaises(ValueError, self.f.write, b'')
148 self.assertRaises(TypeError, self.f.writelines)
149 self.assertRaises(ValueError, self.f.writelines, b'')
177 f = self.f
178 os.close(f.fileno())
180 func(self, f)
183 self.f.close()
192 f = self.f
193 os.close(f.fileno())
195 func(self, f)
202 self.f.close()
208 def testErrnoOnClose(self, f): argument
209 f.close()
212 def testErrnoOnClosedWrite(self, f): argument
213 f.write('a')
216 def testErrnoOnClosedSeek(self, f): argument
217 f.seek(0)
220 def testErrnoOnClosedTell(self, f): argument
221 f.tell()
224 def testErrnoOnClosedTruncate(self, f): argument
225 f.truncate(0)
228 def testErrnoOnClosedSeekable(self, f): argument
229 f.seekable()
232 def testErrnoOnClosedReadable(self, f): argument
233 f.readable()
236 def testErrnoOnClosedWritable(self, f): argument
237 f.writable()
240 def testErrnoOnClosedFileno(self, f): argument
241 f.fileno()
244 def testErrnoOnClosedIsatty(self, f): argument
245 self.assertEqual(f.isatty(), False)
249 self.f.close()
252 self.f = _FileIO(TESTFN, 'r')
253 os.close(self.f.fileno())
254 return self.f
257 def testErrnoOnClosedRead(self, f): argument
258 f = self.ReopenForRead()
259 f.read(1)
262 def testErrnoOnClosedReadall(self, f): argument
263 f = self.ReopenForRead()
264 f.readall()
267 def testErrnoOnClosedReadinto(self, f): argument
268 f = self.ReopenForRead()
270 f.readinto(a)
276 f = _FileIO(TESTFN, "w")
277 self.assertEqual(f.readable(), False)
278 self.assertEqual(f.writable(), True)
279 self.assertEqual(f.seekable(), True)
280 f.close()
282 f = _FileIO(TESTFN, "r")
283 self.assertEqual(f.readable(), True)
284 self.assertEqual(f.writable(), False)
285 self.assertEqual(f.seekable(), True)
286 f.close()
288 f = _FileIO(TESTFN, "a+")
289 self.assertEqual(f.readable(), True)
290 self.assertEqual(f.writable(), True)
291 self.assertEqual(f.seekable(), True)
292 self.assertEqual(f.isatty(), False)
293 f.close()
300 f = _FileIO("/dev/tty", "a")
307 self.assertEqual(f.readable(), False)
308 self.assertEqual(f.writable(), True)
313 self.assertEqual(f.seekable(), False)
314 self.assertEqual(f.isatty(), True)
315 f.close()
321 f = _FileIO(TESTFN, mode)
325 f.close()
337 with _FileIO(TESTFN, modes[0]) as f:
338 self.assertEqual(f.mode, modes[1])
345 f = _FileIO(str(TESTFN), "w")
346 f.close()
355 f = _FileIO(fn, "w")
357 f.write(b"abc")
358 f.close()
359 with open(TESTFN, "rb") as f:
360 self.assertEqual(f.read(), b"abc")
387 f = _FileIO(TESTFN, bad_mode)
396 f.close()
400 f = _FileIO(TESTFN, 'w')
401 f.write(bytes(bytearray(range(10))))
402 self.assertEqual(f.tell(), 10)
403 f.truncate(5)
404 self.assertEqual(f.tell(), 10)
405 self.assertEqual(f.seek(0, os.SEEK_END), 5)
406 f.truncate(15)
407 self.assertEqual(f.tell(), 5)
408 self.assertEqual(f.seek(0, os.SEEK_END), 15)
409 f.close()
415 f = _FileIO(TESTFN, 'w')
416 f.write(bytes(range(11)))
417 f.close()
419 f = _FileIO(TESTFN,'r+')
420 data = f.read(5)
423 if f.tell() != 5:
424 self.fail("File pos after read wrong %d" % f.tell())
426 f.truncate()
427 if f.tell() != 5:
428 self.fail("File pos after ftruncate wrong %d" % f.tell())
430 f.close()
442 f = open(TESTFN, 'wb')
443 f.write(b'spam')
444 f.close()
445 f = open(TESTFN, 'ab')
446 f.write(b'eggs')
447 f.close()
448 f = open(TESTFN, 'rb')
449 d = f.read()
450 f.close()