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

Method test_context_manager_with_open_file

Lib/test/audiotests.py:96–113  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

94 pass
95
96 def test_context_manager_with_open_file(self):
97 with open(TESTFN, 'wb') as testfile:
98 with self.module.open(testfile) as f:
99 f.setnchannels(self.nchannels)
100 f.setsampwidth(self.sampwidth)
101 f.setframerate(self.framerate)
102 f.setcomptype(self.comptype, self.compname)
103 self.assertEqual(testfile.closed, self.close_fd)
104 with open(TESTFN, 'rb') as testfile:
105 with self.module.open(testfile) as f:
106 self.assertFalse(f.getfp().closed)
107 params = f.getparams()
108 self.assertEqual(params.nchannels, self.nchannels)
109 self.assertEqual(params.sampwidth, self.sampwidth)
110 self.assertEqual(params.framerate, self.framerate)
111 if not self.close_fd:
112 self.assertIsNone(f.getfp())
113 self.assertEqual(testfile.closed, self.close_fd)
114
115 def test_context_manager_with_filename(self):
116 # If the file doesn't get closed, this test won't fail, but it will

Callers

nothing calls this directly

Calls 11

setnchannelsMethod · 0.80
setsampwidthMethod · 0.80
setframerateMethod · 0.80
setcomptypeMethod · 0.80
assertFalseMethod · 0.80
getfpMethod · 0.80
assertIsNoneMethod · 0.80
openFunction · 0.50
openMethod · 0.45
assertEqualMethod · 0.45
getparamsMethod · 0.45

Tested by

no test coverage detected