def test_getmap_iwad(self): """As above, but pretend it's an IWAD.""" with open('t/colormap.wad','rb') as fh: wad = fh.read() iwad = io.BytesIO(b'I' + wad[1:]) lump = getmap(iwad) self.assertEqual(len(lump), 256*34)
def test_getmap_notwad(self): """As above, but corrupt the WAD magic. It will treat it as a raw lump""" with open('t/colormap.wad','rb') as fh: wad = fh.read() iwad = io.BytesIO(b'?' + wad[1:]) lump = getmap(iwad) self.assertEqual(len(lump), 256*34) iwad.seek(0) self.assertEqual(lump, iwad.read(256*34))
def test_getmap_longlump(self): """Long lump""" fh = io.BytesIO(bytes(35*256)) lump = getmap(fh) self.assertEqual(34*256, len(lump))
def test_getmap_trunclmp(self): """Short lump""" fh = io.BytesIO(bytes(32)) with self.assertRaises(IOError): getmap(fh)
def test_getmap_truncwad(self): """WAD with a COLORMAP lump which claims to be the right length but isn't""" fh = io.BytesIO(struct.pack('<4sll4sll8s', b'PWAD', 1, 12, b'CRAP', 34*256, 12, b'COLORMAP')) with self.assertRaises(IOError): getmap(fh)
def test_getmap_shortwad(self): """WAD with a COLORMAP lump which is too short""" fh = io.BytesIO(struct.pack('<4sll4sll8s', b'PWAD', 1, 12, b'CRAP', 4, 12, b'COLORMAP')) with self.assertRaises(IOError): getmap(fh)
def test_getmap_emptywad(self): """A WAD without a COLORMAP lump""" fh = io.BytesIO(struct.pack('<4sllll8s', b'PWAD', 1, 12, 0, 12, b'VOIDLUMP')) with self.assertRaises(IOError): getmap(fh)
def test_getmap_wad(self): with open('t/colormap.wad','rb') as fh: lump = getmap(fh) self.assertEqual(len(lump), 256*34)
def test_getmap_lmp(self): with open('t/colormap.lmp','rb') as fh: lump = fh.read() fh.seek(0) self.assertEqual(getmap(fh), lump)