def test_expand_tsv(self): """Test basic expansion functionality.""" x = Expander() x.load_table(BASIC_TSV, "basic") x.expand_tsv(datafile("src.tsv"), column_map={'c1': 'basic'}, in_place=True)
def setUp(self): oi = OntolIndexer() p = datafile("nucleus.json") oi.load_from_files([p]) oi.gen_name2id() self.expander.load_pairs(oi.pairs, table=TBL) self.expander.default_table = TBL
class CacheState(): # graphics grhuffman = [] pictable = [] grsegs = [] # map RLEWtag = None maphandle = datafile('GAMEMAPS') mapheaderseg = [] mapsegs = []
def setup_graphics_file(): with datafile('VGADICT') as handle: node = HuffNode() while handle.readinto(node): state.grhuffman.append(node) node = HuffNode() with datafile('VGAHEAD') as handle: data = handle.read() grstarts = [] di = 0 for i in range(gfx.NUMCHUNKS + 1): val = data[di] | data[di + 1] << 8 | data[ di + 2] << 16; grstarts.append(-1 if val == 0x00FFFFFF else val) di += 3 with datafile('VGAGRAPH') as grhandle: # load the pic and sprite headers into the arrays in the data segment grhandle.seek(grstarts[0]) chunkexplen = readctype(grhandle) chunkcomplen = grstarts[1] - grstarts[0] - 4 source = grhandle.read(chunkcomplen) pictable_bytes = huff_expand(source, gfx.NUMPICS * ctypes.sizeof(Picture)) pictable_bytes = BytesIO(pictable_bytes) pic = Picture() while pictable_bytes.readinto(pic): state.pictable.append(pic) pic = Picture() # instead of loading graphics on demand, load them all on startup for chunk in range(gfx.NUMCHUNKS): if chunk == 135: # this one is not defined in gfx continue grseg = load_graphic(grhandle, grstarts, chunk) state.grsegs.append(grseg)
def setup_map_file(): with datafile('MAPHEAD') as handle: bytes_read, state.RLEWtag = readctype(handle, ctypes.c_ushort) header_offsets = [] length = NUM_MAPS * 4 while length: bytes_read, offset = readctype(handle) length -= bytes_read header_offsets.append(offset) for pos in header_offsets: if pos < 0: # $FFFFFFFF start is a sparse map continue state.maphandle.seek(pos) map_header = MapHeader() state.maphandle.readinto(map_header) state.mapheaderseg.append(map_header)
def startup(): with datafile('VSWAP') as handle: _, chunks_in_file = readctype(handle, ctypes.c_ushort) _, pm_sprite_start = readctype(handle, ctypes.c_ushort) _, pm_sound_start = readctype(handle, ctypes.c_ushort) t_page_offsets = ctypes.c_uint32 * (chunks_in_file + 1) _, page_offsets = readctype(handle, t_page_offsets) t_page_lengths = ctypes.c_ushort * chunks_in_file _, page_lengths = readctype(handle, t_page_lengths) # load textures, sprites and sounds into memory # all fit in memory so we skip the paging mechanism for i in range(chunks_in_file): if not page_offsets[i]: # sparse page continue # Use specified page length, when next page is sparse page. # Otherwise, calculate size from the offset difference between this and the next page. size = page_offsets[i + 1] - page_offsets[i] if not page_offsets[i + 1]: size = page_lengths[i] handle.seek(page_offsets[i]) value = handle.read(size) if i < pm_sprite_start: state.textures.append(value) elif i < pm_sound_start: # for sprites we parse the CompShape struct as well bio = BytesIO(value) comp_shape = CompShape() bio.readinto(comp_shape) state.sprites.append((comp_shape, value)) else: value = handle.read(size) state.sounds.append(value)
# -*- coding: utf-8 -*- """Test the module can be imported.""" import unittest from term_expando import Expander from util import datafile BASIC_TSV = datafile("basic.tsv") expected = {'a': 'a1|a2|a3'} class TestExpand(unittest.TestCase): """A test case for import tests.""" def test_expand(self): """Test basic expansion functionality.""" x = Expander() t = 'my' x.load_table(BASIC_TSV, t) for k in ['a', 'b', 'c', 'unknown']: print(f'Exp({k}) == {x.expand_term(k,t)}') for k, v in expected.items(): assert x.expand_term(k, t) == v def test_expand_arr(self): """Test basic expansion functionality.""" x = Expander() print(f'Expander = {x}') t = 'my' x.load_table(BASIC_TSV, t, valsep='|')
def test_expand_gaf(self): """Test basic expansion functionality.""" x = Expander() x.load_table(datafile("go-small-id2name.tsv")) x.expand_tsv(datafile("pombase-small.gaf"), in_place=True)