MCPcopy Index your code
hub / github.com/python/cpython / test_pyfile_fromfd

Method test_pyfile_fromfd

Lib/test/test_capi/test_file.py:20–55  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

18
19class CAPIFileTest(unittest.TestCase):
20 def test_pyfile_fromfd(self):
21 # Test PyFile_FromFd() which is a thin wrapper to _io.open()
22 pyfile_fromfd = _testlimitedcapi.pyfile_fromfd
23 filename = __file__
24 with open(filename, "rb") as fp:
25 fd = fp.fileno()
26
27 # FileIO
28 fp.seek(0)
29 obj = pyfile_fromfd(fd, filename, "rb", 0, NULL, NULL, NULL, 0)
30 try:
31 self.assertIsInstance(obj, _io.FileIO)
32 self.assertEqual(obj.readline(), FIRST_LINE.encode())
33 finally:
34 obj.close()
35
36 # BufferedReader
37 fp.seek(0)
38 obj = pyfile_fromfd(fd, filename, "rb", 1024, NULL, NULL, NULL, 0)
39 try:
40 self.assertIsInstance(obj, _io.BufferedReader)
41 self.assertEqual(obj.readline(), FIRST_LINE.encode())
42 finally:
43 obj.close()
44
45 # TextIOWrapper
46 fp.seek(0)
47 obj = pyfile_fromfd(fd, filename, "r", 1,
48 "utf-8", "replace", NULL, 0)
49 try:
50 self.assertIsInstance(obj, _io.TextIOWrapper)
51 self.assertEqual(obj.encoding, "utf-8")
52 self.assertEqual(obj.errors, "replace")
53 self.assertEqual(obj.readline(), FIRST_LINE_NORM)
54 finally:
55 obj.close()
56
57 def test_pyfile_getline(self):
58 # Test PyFile_GetLine(file, n): call file.readline()

Callers

nothing calls this directly

Calls 8

assertIsInstanceMethod · 0.80
openFunction · 0.50
filenoMethod · 0.45
seekMethod · 0.45
assertEqualMethod · 0.45
readlineMethod · 0.45
encodeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected