Lines Matching refs:f
24 self.f = self.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')
71 fst = os.fstat(self.f.fileno())
73 self.assertEqual(self.f._blksize, blksize)
77 self.f.write(bytes([1, 2, 0, 255]))
78 self.f.close()
81 with self.FileIO(TESTFN, 'r') as f:
82 n = f.readinto(ba)
87 self.f.write(bytes([1, 2, 0, 255]))
88 self.f.close()
91 with self.FileIO(TESTFN, 'r') as f:
92 n = f.readinto(m)
97 with self.FileIO(TESTFN, 'r') as f:
98 n = f.readinto(m)
103 self.f.write(bytes([1, 2, 0, 255]))
104 self.f.close()
107 with self.FileIO(TESTFN, 'r') as f:
108 n = f.readinto(a)
113 with self.FileIO(TESTFN, 'r') as f:
114 n = f.readinto(a)
119 with self.FileIO(TESTFN, 'r') as f:
120 n = f.readinto(a)
126 self.f.writelines(l)
127 self.f.close()
128 self.f = self.FileIO(TESTFN, 'rb')
129 buf = self.f.read()
134 self.f.writelines(l)
135 self.f.close()
136 self.f = self.FileIO(TESTFN, 'rb')
137 buf = self.f.read()
141 self.assertRaises(TypeError, self.f.writelines, [1, 2, 3])
142 self.assertRaises(TypeError, self.f.writelines, None)
143 self.assertRaises(TypeError, self.f.writelines, "abc")
146 self.f.write(b"hi\nbye\nabc")
147 self.f.close()
148 self.f = self.FileIO(TESTFN, 'r')
149 self.assertEqual(self.f.read(None), b"hi\nbye\nabc")
150 self.f.seek(0)
151 self.assertEqual(self.f.readline(None), b"hi\n")
152 self.assertEqual(self.f.readlines(None), [b"bye\n", b"abc"])
155 self.assertRaises(TypeError, self.f.write, "Hello!")
158 self.assertEqual(repr(self.f),
160 (self.modulename, self.f.name, self.f.mode))
161 del self.f.name
162 self.assertEqual(repr(self.f),
164 (self.modulename, self.f.fileno(), self.f.mode))
165 self.f.close()
166 self.assertEqual(repr(self.f),
172 with self.FileIO(fd, 'r', closefd=False) as f:
173 self.assertEqual(repr(f),
175 (self.modulename, f.name, f.mode))
181 with swap_attr(self.f, 'name', self.f):
183 repr(self.f) # Should not crash
186 f = self.f
187 self.assertFalse(f.isatty())
188 self.assertFalse(f.closed)
190 self.assertRaises(ValueError, f.read, 10) # Open for reading
191 f.close()
192 self.assertTrue(f.closed)
193 f = self.FileIO(TESTFN, 'r')
194 self.assertRaises(TypeError, f.readinto, "")
195 self.assertFalse(f.closed)
196 f.close()
197 self.assertTrue(f.closed)
204 self.f.close()
205 self.assertTrue(self.f.closed)
208 method = getattr(self.f, methodname)
212 self.assertRaises(TypeError, self.f.readinto)
213 self.assertRaises(ValueError, self.f.readinto, bytearray(1))
214 self.assertRaises(TypeError, self.f.seek)
215 self.assertRaises(ValueError, self.f.seek, 0)
216 self.assertRaises(TypeError, self.f.write)
217 self.assertRaises(ValueError, self.f.write, b'')
218 self.assertRaises(TypeError, self.f.writelines)
219 self.assertRaises(ValueError, self.f.writelines, b'')
247 f = self.f
248 os.close(f.fileno())
250 func(self, f)
253 self.f.close()
262 f = self.f
263 os.close(f.fileno())
265 func(self, f)
272 self.f.close()
278 def testErrnoOnClose(self, f): argument
279 f.close()
282 def testErrnoOnClosedWrite(self, f): argument
283 f.write(b'a')
286 def testErrnoOnClosedSeek(self, f): argument
287 f.seek(0)
290 def testErrnoOnClosedTell(self, f): argument
291 f.tell()
294 def testErrnoOnClosedTruncate(self, f): argument
295 f.truncate(0)
298 def testErrnoOnClosedSeekable(self, f): argument
299 f.seekable()
302 def testErrnoOnClosedReadable(self, f): argument
303 f.readable()
306 def testErrnoOnClosedWritable(self, f): argument
307 f.writable()
310 def testErrnoOnClosedFileno(self, f): argument
311 f.fileno()
314 def testErrnoOnClosedIsatty(self, f): argument
315 self.assertEqual(f.isatty(), False)
319 self.f.close()
322 self.f = self.FileIO(TESTFN, 'r')
323 os.close(self.f.fileno())
324 return self.f
327 def testErrnoOnClosedRead(self, f): argument
328 f = self.ReopenForRead()
329 f.read(1)
332 def testErrnoOnClosedReadall(self, f): argument
333 f = self.ReopenForRead()
334 f.readall()
337 def testErrnoOnClosedReadinto(self, f): argument
338 f = self.ReopenForRead()
340 f.readinto(a)
355 f = self.FileIO(TESTFN, "w")
356 self.assertEqual(f.readable(), False)
357 self.assertEqual(f.writable(), True)
358 self.assertEqual(f.seekable(), True)
359 f.close()
361 f = self.FileIO(TESTFN, "r")
362 self.assertEqual(f.readable(), True)
363 self.assertEqual(f.writable(), False)
364 self.assertEqual(f.seekable(), True)
365 f.close()
367 f = self.FileIO(TESTFN, "a+")
368 self.assertEqual(f.readable(), True)
369 self.assertEqual(f.writable(), True)
370 self.assertEqual(f.seekable(), True)
371 self.assertEqual(f.isatty(), False)
372 f.close()
376 f = self.FileIO("/dev/tty", "a")
383 self.assertEqual(f.readable(), False)
384 self.assertEqual(f.writable(), True)
389 self.assertEqual(f.seekable(), False)
390 self.assertEqual(f.isatty(), True)
391 f.close()
399 f = self.FileIO(TESTFN, mode)
403 f.close()
415 with self.FileIO(TESTFN, modes[0]) as f:
416 self.assertEqual(f.mode, modes[1])
423 f = self.FileIO(str(TESTFN), "w")
424 f.close()
433 f = self.FileIO(fn, "w")
435 f.write(b"abc")
436 f.close()
437 with open(TESTFN, "rb") as f:
438 self.assertEqual(f.read(), b"abc")
450 f = self.FileIO(fn, "w")
452 f.write(b"abc")
453 f.close()
454 with open(TESTFN_UNICODE, "rb") as f:
455 self.assertEqual(f.read(), b"abc")
475 f = self.FileIO(TESTFN, bad_mode)
484 f.close()
488 f = self.FileIO(TESTFN, 'w')
489 f.write(bytes(bytearray(range(10))))
490 self.assertEqual(f.tell(), 10)
491 f.truncate(5)
492 self.assertEqual(f.tell(), 10)
493 self.assertEqual(f.seek(0, io.SEEK_END), 5)
494 f.truncate(15)
495 self.assertEqual(f.tell(), 5)
496 self.assertEqual(f.seek(0, io.SEEK_END), 15)
497 f.close()
503 f = self.FileIO(TESTFN, 'w')
504 f.write(bytes(range(11)))
505 f.close()
507 f = self.FileIO(TESTFN,'r+')
508 data = f.read(5)
511 if f.tell() != 5:
512 self.fail("File pos after read wrong %d" % f.tell())
514 f.truncate()
515 if f.tell() != 5:
516 self.fail("File pos after ftruncate wrong %d" % f.tell())
518 f.close()
530 f = open(TESTFN, 'wb')
531 f.write(b'spam')
532 f.close()
533 f = open(TESTFN, 'ab')
534 f.write(b'eggs')
535 f.close()
536 f = open(TESTFN, 'rb')
537 d = f.read()
538 f.close()