def test_simple_round_trip(): sample_data = { "game": 2, "game_name": "Metroid Prime 2: Echoes", "resource_database": { "items": [], "events": [], "tricks": [], "damage": [], "versions": [], "misc": [], "difficulty": [], }, "starting_location": { "world_asset_id": 1006255871, "area_asset_id": 1655756413 }, "initial_states": { "Default": [] }, "victory_condition": [], "dock_weakness_database": { "door": [], "portal": [] }, "pickup_database": { "pickups": {}, "original_indices": [], }, "worlds": [], } s = io.StringIO() s_io: TextIO = s json.dump( { "pickup_database": sample_data["pickup_database"], "starting_location": sample_data["starting_location"], "initial_states": sample_data["initial_states"], "victory_condition": sample_data["victory_condition"], }, s) b = io.BytesIO() b_io: BinaryIO = b binary_data.encode(sample_data, b_io) s.seek(0) b.seek(0) decoded = binary_data.decode(b_io, s_io) assert sample_data == decoded
def test_simple_round_trip(): sample_data = { "game": "prime2", "resource_database": { "items": [], "energy_tank_item_index": 0, "item_percentage_index": 0, "multiworld_magic_item_index": 0, "events": [], "tricks": [], "damage": [], "versions": [], "misc": [], "requirement_template": {}, }, "game_specific": { "energy_per_tank": 100.0, "safe_zone_heal_per_second": 1.0, "beam_configurations": [], "dangerous_energy_tank": True, }, "starting_location": { "world_asset_id": 1006255871, "area_asset_id": 1655756413 }, "initial_states": { "Default": [ ] }, "victory_condition": { "type": "and", "data": [] }, "dock_weakness_database": { "door": [], "portal": [], "morph_ball": [], }, "worlds": [], } b = io.BytesIO() binary_data.encode(sample_data, b) b.seek(0) decoded = binary_data.decode(b) assert decoded == sample_data
def test_full_file_round_trip(game): # Setup json_database_path = get_data_path().joinpath("json_data", f"{game.value}.json") if not json_database_path.exists(): pytest.skip("Missing database") with json_database_path.open("r") as json_file: original_data = json.load(json_file) # Run 1 output_io = io.BytesIO() binary_data.encode(original_data, output_io) # Run 2 output_io.seek(0) final_data = binary_data.decode(output_io) # Assert assert final_data == original_data
def test_simple_round_trip(): sample_data = { "game": 2, "game_name": "Metroid Prime 2: Echoes", "resource_database": { "items": [], "events": [], "tricks": [], "damage": [], "versions": [], "misc": [], "difficulty": [], "requirement_template": {}, }, "game_specific": { "energy_per_tank": 100.0, "beam_configurations": [] }, "starting_location": { "world_asset_id": 1006255871, "area_asset_id": 1655756413 }, "initial_states": { "Default": [] }, "victory_condition": { "type": "and", "data": [] }, "dock_weakness_database": { "door": [], "portal": [] }, "worlds": [], } b = io.BytesIO() binary_data.encode(sample_data, b) b.seek(0) decoded = binary_data.decode(b) assert sample_data == decoded
def test_full_data_encode_is_equal(): # The prime2.json may be missing if we're running using a Pyinstaller binary # Setup json_database_file = get_data_path().joinpath("json_data", "prime2.json") with json_database_file.open("r") as open_file: json_database = json.load(open_file) b = io.BytesIO() binary_data.encode(json_database, b) b.seek(0) decoded_database = binary_data.decode(b) # Run assert json_database == decoded_database comparable_json = _comparable_dict(json_database) comparable_binary = _comparable_dict(decoded_database) assert comparable_json == comparable_binary
def test_full_file_round_trip(): # Setup json_database_path = get_data_path().joinpath("json_data", "prime2.json") if not json_database_path.exists(): pytest.skip("Missing database") with json_database_path.open("r") as json_file: original_data = json.load(json_file) # Run 1 output_io = io.BytesIO() remaining_data = binary_data.encode(original_data, output_io) # Run 2 output_io.seek(0) text_io = io.StringIO(json.dumps(remaining_data)) final_data = binary_data.decode(output_io, text_io) # Assert assert final_data == original_data