def _no_maps(self): mapcount = unitsync.GetMapCount() if mapcount == 0: if not self.checked_count: sys.stderr.write( 'No maps found, skipping extended map function checks\n') self.checked_count = True return mapcount == 0
def test_map_checksum(self): mapcount = unitsync.GetMapCount() if self._no_maps(): return for mapidx in testRange(mapcount): checksum = unitsync.GetMapChecksum(mapidx) self.assertTrue(checksum > 0) self.assertEqual( checksum, unitsync.GetMapChecksumFromName(unitsync.GetMapName(mapidx)))
def test_map_archives(self): mapcount = unitsync.GetMapCount() if self._no_maps(): return for mapidx in testRange(mapcount): mapname = unitsync.GetMapName(mapidx) self.assertTrue(unitsync.GetMapArchiveCount(mapname)) archivename = unitsync.GetMapArchiveName(0) self.assertTrue(None != archivename) unitsync.AddArchive(archivename) self.assertTrue(unitsync.OpenFileVFS(archivename)) unitsync.RemoveAllArchives()
def test_map_attributes(self): mapcount = unitsync.GetMapCount() self.assertEqual(None, unitsync.GetMapName(mapcount)) if self._no_maps(): return for mapidx in testRange(mapcount): mapname = unitsync.GetMapName(mapidx) self.assertTrue(None != mapname) for func in [ 'GetMapWidth', 'GetMapHeight', 'GetMapTidalStrength', 'GetMapWindMin', 'GetMapWindMax', 'GetMapGravity', 'GetMapResourceCount', 'GetMapPosCount' ]: self.assertTrue(-1 < getattr(unitsync, func)(mapidx)) for func in [ 'GetMapName', 'GetMapFileName', 'GetMapDescription', 'GetMapAuthor' ]: self.assertTrue(None != getattr(unitsync, func)(mapidx)) mapoptcount = unitsync.GetMapOptionCount(mapname) self.optiontest(mapoptcount)
def test_minimap(self): mapcount = unitsync.GetMapCount() if self._no_maps(): return for mapidx in testRange(mapcount): for miplevel in range(9): #max miplevel is 8 #miplevel = 2 mapname = unitsync.GetMapName(mapidx) minimap = unitsync.GetMinimap(mapname, miplevel) self.assertTrue(None != minimap) if testMinimap: size = (1 << (10 - miplevel), 1 << (10 - miplevel)) arr = numpy.frombuffer(minimap, numpy.uint16).astype(numpy.uint32) arr = 0xFF000000 + ((arr & 0xF800) >> 8) + ( (arr & 0x07E0) << 5) + ((arr & 0x001F) << 19) image = Image.frombuffer('RGBA', size, arr, 'raw', 'RGBA', 0, 1) image.save( os.path.join( tempfile.gettempdir(), 'pyusync_%s_mip-%02d.png' % (mapname, miplevel)))