diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-01-17 16:13:04 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-01-17 16:13:04 (GMT) |
commit | 03757ec4a571df0e871bd9136cae9d08841f8a6a (patch) | |
tree | a541ba154d20e6ecfe9503ce4e0af61c72236908 /Lib/test/test_aifc.py | |
parent | c77bb65deb6aa3c281243e0408efcb44be8a026e (diff) | |
download | cpython-03757ec4a571df0e871bd9136cae9d08841f8a6a.zip cpython-03757ec4a571df0e871bd9136cae9d08841f8a6a.tar.gz cpython-03757ec4a571df0e871bd9136cae9d08841f8a6a.tar.bz2 |
Issue #13589: Fix some serialization primitives in the aifc module.
Patch by Oleg Plakhotnyuk.
Diffstat (limited to 'Lib/test/test_aifc.py')
-rw-r--r-- | Lib/test/test_aifc.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/Lib/test/test_aifc.py b/Lib/test/test_aifc.py index 085b949..236f9b6 100644 --- a/Lib/test/test_aifc.py +++ b/Lib/test/test_aifc.py @@ -144,8 +144,45 @@ class AIFCTest(unittest.TestCase): self.assertRaises(aifc.Error, f.getmark, 3) +class AIFCLowLevelTest(unittest.TestCase): + + def test_read_written(self): + def read_written(self, what): + f = io.BytesIO() + getattr(aifc, '_write_' + what)(f, x) + f.seek(0) + return getattr(aifc, '_read_' + what)(f) + for x in (-1, 0, 0.1, 1): + self.assertEqual(read_written(x, 'float'), x) + for x in (float('NaN'), float('Inf')): + self.assertEqual(read_written(x, 'float'), aifc._HUGE_VAL) + for x in (b'', b'foo', b'a' * 255): + self.assertEqual(read_written(x, 'string'), x) + for x in (-0x7FFFFFFF, -1, 0, 1, 0x7FFFFFFF): + self.assertEqual(read_written(x, 'long'), x) + for x in (0, 1, 0xFFFFFFFF): + self.assertEqual(read_written(x, 'ulong'), x) + for x in (-0x7FFF, -1, 0, 1, 0x7FFF): + self.assertEqual(read_written(x, 'short'), x) + for x in (0, 1, 0xFFFF): + self.assertEqual(read_written(x, 'ushort'), x) + + def test_read_raises(self): + f = io.BytesIO(b'\x00') + self.assertRaises(EOFError, aifc._read_ulong, f) + self.assertRaises(EOFError, aifc._read_long, f) + self.assertRaises(EOFError, aifc._read_ushort, f) + self.assertRaises(EOFError, aifc._read_short, f) + + def test_write_long_string_raises(self): + f = io.BytesIO() + with self.assertRaises(ValueError): + aifc._write_string(f, b'too long' * 255) + + def test_main(): run_unittest(AIFCTest) + run_unittest(AIFCLowLevelTest) if __name__ == "__main__": |