def test_dem(self):
d0 = dem.Dem.open('./test_data/test.dem')
d0.close()
d0.save(self.buff)
self.buff.seek(0)
b = io.BufferedReader(self.buff)
d1 = dem.Dem.open(b)
self.assertEqual(d1.cd_track, '2', 'Cd track should be 2')
self.assertEqual(len(d1.message_blocks), 168, 'The demo should have 168 message blocks')
last_message_of_first_block = d1.message_blocks[0].messages[-1]
self.assertTrue(isinstance(last_message_of_first_block, dem.SignOnNum), 'The last message of the first block should be a SignOnNum')
self.assertEqual(last_message_of_first_block.sign_on, 1, 'Sign on value should be 1')
self.assertTrue(isinstance(d1.message_blocks[-1].messages[0], dem.Disconnect), 'The last message should be a Disconnect')
self.assertFalse(d1.fp.closed, 'File should be open')
fp = d1.fp
d1.close()
self.assertTrue(fp.closed, 'File should be closed')
self.assertIsNone(d1.fp, 'File pointer should be cleaned up')
评论列表
文章目录