# Path: magnate/savegame/db.py
# class PricedItem:
#     class SystemData(Base):  # pylint: disable=unused-variable
#     class CelestialData(Base):  # pylint: disable=unused-variable
#     class LocationData(Base):  # pylint: disable=unused-variable
#     class Commodity(Base):  # pylint: disable=unused-variable
#     class CommodityData(PricedItem, Base):  # pylint: disable=unused-variable
#     class CommodityCategory(Base):  # pylint: disable=unused-variable
#     class Ship(Base):  # pylint: disable=unused-variable
#     class ShipData(PricedItem, Base):  # pylint: disable=unused-variable
#     class Cargo(Base):  # pylint: disable=unused-variable
#     class Property(Base):  # pylint: disable=unused-variable
#     class PropertyData(PricedItem, Base):  # pylint: disable=unused-variable
#     class ShipPart(Base):  # pylint: disable=unused-variable
#     class ShipPartData(PricedItem, Base):  # pylint: disable=unused-variable
#     class EventData(Base):  # pylint: disable=unused-variable
#     class EventCondition(Base):  # pylint: disable=unused-variable
#     class ConditionCategory(Base):  # pylint: disable=unused-variable
#     class Player(Base):  # pylint: disable=unused-variable
#     class World(Base):  # pylint: disable=unused-variable
# SCHEMA_NAMES = ('SystemData', 'CelestialData', 'LocationData', 'Commodity', 'CommodityData',
#                 'CommodityCategory', 'Ship', 'ShipData', 'Cargo', 'Property', 'PropertyData',
#                 'ShipPart', 'ShipPartData', 'EventData', 'EventCondition', 'ConditionCategory',
#                 'Player', 'World',)
# def init_schema(datadir):
# def _init_systems(session, systems):
# def _init_ships(session, ships):
# def _init_property(session, properties):
# def _init_parts(session, ship_parts):
# def _init_events(session, events):
# def init_savegame(engine, game_data):
# def create_savegame(savegame, datadir):
# def load_savegame(savegame, datadir):
# 
# Path: magnate/savegame/load.py
# def init_game(savegame, datadir):
# 
# Path: magnate/savegame/data_def.py
# BASE_SCHEMA = None
# SYSTEM_SCHEMA = None
#     SYSTEM_SCHEMA = v.Schema(v.All(system_structure,
#                                    known_celestial))
#     BASE_SCHEMA = v.Schema(v.All(base_structure,
#                                  volume_or_storage))
# def known_celestial(data):
# def volume_or_storage(data):
# def _define_schemas(datadir):
# def load_data_definitions(datadir):
# 
# Path: magnate/savegame/base_types.py
# def type_name(value):
# def _generic_types_validator(type_enum, value):
# def load_base_types(datadir):
# def init_base_types(datadir):
# DATA_TYPES_SCHEMA = v.Schema({'version': '0.1',
#                               'types': {type_name: [str]}, },
#                              required=True)


import builtins
import os.path
import re
import pytest
from unittest.mock import mock_open, patch
from magnate.savegame import db
from magnate.savegame import load
from magnate.savegame import data_def
from magnate.savegame import base_types
                    'volume': 23}],
    'ships': [{'depreciation_rate': 1,
               'mean_price': 10,
               'name': 'ship',
               'standard_deviation': 1,
               'storage': 0,
               'weapon_mounts': 1}],
    'events': [{'adjustment': -5,
                'affects': ['food', ['illegal', 'chemical']],
                'msg': 'price lower'},
               {'adjustment': 5,
                'affects': [['illegal', 'chemical'], 'food'],
                'msg': 'price higher'}],
}


def test_load_data_definitions(fake_datadir):
    base_data = data_def.load_data_definitions(fake_datadir)

    print(base_data)
    assert base_data == LOADED_DATA


def test_init_game(tmpdir, fake_datadir):
    """Test that init_game can create and load games"""

    savegame = os.path.join(tmpdir, 'test_game.sqlite')
    game_state = load.init_game(savegame, fake_datadir)

    assert game_state

# Path: magnate/savegame/db.py
# class PricedItem:
#     class SystemData(Base):  # pylint: disable=unused-variable
#     class CelestialData(Base):  # pylint: disable=unused-variable
#     class LocationData(Base):  # pylint: disable=unused-variable
#     class Commodity(Base):  # pylint: disable=unused-variable
#     class CommodityData(PricedItem, Base):  # pylint: disable=unused-variable
#     class CommodityCategory(Base):  # pylint: disable=unused-variable
#     class Ship(Base):  # pylint: disable=unused-variable
#     class ShipData(PricedItem, Base):  # pylint: disable=unused-variable
#     class Cargo(Base):  # pylint: disable=unused-variable
#     class Property(Base):  # pylint: disable=unused-variable
#     class PropertyData(PricedItem, Base):  # pylint: disable=unused-variable
#     class ShipPart(Base):  # pylint: disable=unused-variable
#     class ShipPartData(PricedItem, Base):  # pylint: disable=unused-variable
#     class EventData(Base):  # pylint: disable=unused-variable
#     class EventCondition(Base):  # pylint: disable=unused-variable
#     class ConditionCategory(Base):  # pylint: disable=unused-variable
#     class Player(Base):  # pylint: disable=unused-variable
#     class World(Base):  # pylint: disable=unused-variable
# SCHEMA_NAMES = ('SystemData', 'CelestialData', 'LocationData', 'Commodity', 'CommodityData',
#                 'CommodityCategory', 'Ship', 'ShipData', 'Cargo', 'Property', 'PropertyData',
#                 'ShipPart', 'ShipPartData', 'EventData', 'EventCondition', 'ConditionCategory',
#                 'Player', 'World',)
# def init_schema(datadir):
# def _init_systems(session, systems):
# def _init_ships(session, ships):
# def _init_property(session, properties):
# def _init_parts(session, ship_parts):
# def _init_events(session, events):
# def init_savegame(engine, game_data):
# def create_savegame(savegame, datadir):
# def load_savegame(savegame, datadir):
# 
# Path: magnate/savegame/load.py
# def init_game(savegame, datadir):
# 
# Path: magnate/savegame/data_def.py
# BASE_SCHEMA = None
# SYSTEM_SCHEMA = None
#     SYSTEM_SCHEMA = v.Schema(v.All(system_structure,
#                                    known_celestial))
#     BASE_SCHEMA = v.Schema(v.All(base_structure,
#                                  volume_or_storage))
# def known_celestial(data):
# def volume_or_storage(data):
# def _define_schemas(datadir):
# def load_data_definitions(datadir):
# 
# Path: magnate/savegame/base_types.py
# def type_name(value):
# def _generic_types_validator(type_enum, value):
# def load_base_types(datadir):
# def init_base_types(datadir):
# DATA_TYPES_SCHEMA = v.Schema({'version': '0.1',
#                               'types': {type_name: [str]}, },
#                              required=True)


# Path: tests/functional/savegame/test_loading_game.py
import builtins
import os.path
import re
import pytest
from unittest.mock import mock_open, patch
from magnate.savegame import db
from magnate.savegame import load
from magnate.savegame import data_def
from magnate.savegame import base_types

                    'volume': 23}],
    'ships': [{'depreciation_rate': 1,
               'mean_price': 10,
               'name': 'ship',
               'standard_deviation': 1,
               'storage': 0,
               'weapon_mounts': 1}],
    'events': [{'adjustment': -5,
                'affects': ['food', ['illegal', 'chemical']],
                'msg': 'price lower'},
               {'adjustment': 5,
                'affects': [['illegal', 'chemical'], 'food'],
                'msg': 'price higher'}],
}


def test_load_data_definitions(fake_datadir):
    base_data = data_def.load_data_definitions(fake_datadir)

    print(base_data)
    assert base_data == LOADED_DATA


def test_init_game(tmpdir, fake_datadir):
    """Test that init_game can create and load games"""

    savegame = os.path.join(tmpdir, 'test_game.sqlite')
    game_state = load.init_game(savegame, fake_datadir)

    assert game_state

    assert db.engine is game_state