diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2012-12-29 20:54:49 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2012-12-29 20:54:49 (GMT) |
commit | 44c66c72c9045a7824d07175cfc07845e4d7d28a (patch) | |
tree | a88a17bd7c1a4fb9542d5d9a4f7d91c80eb303e4 /Lib/test/test_aifc.py | |
parent | ff2840a76f04c8846e8ad5b7e8379998ab3e87a6 (diff) | |
download | cpython-44c66c72c9045a7824d07175cfc07845e4d7d28a.zip cpython-44c66c72c9045a7824d07175cfc07845e4d7d28a.tar.gz cpython-44c66c72c9045a7824d07175cfc07845e4d7d28a.tar.bz2 |
Issue #16486: Make aifc files work with 'with' as context managers.
Diffstat (limited to 'Lib/test/test_aifc.py')
-rw-r--r-- | Lib/test/test_aifc.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_aifc.py b/Lib/test/test_aifc.py index 9c0e7b9..34589f2 100644 --- a/Lib/test/test_aifc.py +++ b/Lib/test/test_aifc.py @@ -43,6 +43,18 @@ class AIFCTest(unittest.TestCase): (2, 2, 48000, 14400, b'NONE', b'not compressed'), ) + def test_context_manager(self): + with open(self.sndfilepath, 'rb') as testfile: + with aifc.open(testfile) as f: + pass + self.assertEqual(testfile.closed, True) + with open(TESTFN, 'wb') as testfile: + with self.assertRaises(aifc.Error): + with aifc.open(testfile, 'wb') as fout: + pass + self.assertEqual(testfile.closed, True) + fout.close() # do nothing + def test_read(self): f = self.f = aifc.open(self.sndfilepath) self.assertEqual(f.readframes(0), b'') |