def test_save_base_csv_symmetric(writer: DataReaderWriter): data = DataMap() data.insert(create_entry_en('test1')) data.insert(create_entry_en('test2')) groups = ['name', 'description'] writer.save_base_map_csv('testbase.csv', data, groups=groups) new_data = writer.load_base_csv('testbase.csv', groups=groups) assert data.to_list() == new_data.to_list(), "saved data didn't match"
def test_save_base_csv_symmetric(writer: DataReaderWriter): # Note: CSVs do not save typing info, so everything is strings data = DataMap() data.insert(create_entry_en('test1', {'id': '1'})) data.insert(create_entry_en('test2', {'id': '2'})) groups = ['name', 'description'] writer.save_base_map_csv('testbase.csv', data, groups=groups) new_data = writer.load_base_csv('testbase.csv', languages, groups=groups) assert data.to_list() == new_data.to_list(), "saved data didn't match"
def test_save_data_csv_symmetric_listmode(writer: DataReaderWriter): basedata = DataMap() basedata.add_entry(1, create_entry_en('test1')) basedata.add_entry(2, create_entry_en('test2')) extdata = DataMap() extdata.add_entry(1, {**basedata[1], 'data': [{'data': 'test1'}]}) extdata.add_entry(2, { **basedata[2], 'data': [{ 'data': 'test2' }, { 'data': 'test2ext' }] }) writer.save_data_csv('testdatasym.csv', extdata, key='data') new_data = writer.load_data_csv(basedata.copy(), 'testdatasym.csv', key='data', leaftype="list") assert extdata.to_dict() == new_data.to_dict(), "expected data to match"
def test_save_data_csv_symmetric_listmode(writer: DataReaderWriter): basedata = DataMap() basedata.add_entry(1, create_entry_en('test1')) basedata.add_entry(2, create_entry_en('test2')) extdata = DataMap() extdata.add_entry(1, {**basedata[1], 'data': [{'a': 'test1'}]}) extdata.add_entry(2, { **basedata[2], 'data': [{ 'a': 'test2' }, { 'a': 'test2ext' }] }) writer.save_data_csv('testdatasym.csv', extdata, key='data') new_data = (DataStitcher(writer).use_base(basedata.copy()).add_csv( 'testdatasym.csv', key='data').get()) old_data = extdata.to_dict() abc = new_data.to_dict() assert extdata.to_dict() == new_data.to_dict(), "expected data to match"
from os.path import abspath, join, dirname from mhdata.io import DataMap, DataReaderWriter from mhdata.io.csv import save_csv from mhdata.load import load_data, cfg, schema writer = DataReaderWriter(required_languages=cfg.required_languages, languages=cfg.supported_languages, data_path=join(dirname(abspath(__file__)), '../../source_data/')) # Implementation commented out due to new structure # uncomment it and remake it once we want to resort rewards. # def repair_rewards(): # data = load_data() # for monster_id, monster_entry in data.monster_map.items(): # # If there are no rewards, skip # if 'rewards' not in monster_entry: # continue # old_rewards = monster_entry['rewards'] # # Store all conditions for the monster here. # # Any still here at the end print a warning # all_conditions = set(old_rewards.keys()) # # add all results to this phase here # new_rewards = {} # # now iterate on the conditions map. We're trying to match the order
def writer(tmpdir): "Returns a reader/writer pointed to a temporary directory created for the test" return DataReaderWriter(data_path=tmpdir, languages=['en'])
def make_writer(): return DataReaderWriter(languages=data.supported_languages, data_path='source_data/')
def create_artifact_writer(): import mhdata.cfg as cfg return DataReaderWriter(languages=list(cfg.supported_languages), data_path=path.join(path.dirname(__file__), '../../../artifacts/'))