# Path: magnate/errors.py
# class MagnateNoSaveGame(MagnateSaveError):
#     """Raised when a save game file is missing"""
#     pass
# 
# 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: 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/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):


import os.path
import shutil
import pytest
import sqlalchemy
from magnate.errors import MagnateNoSaveGame
from magnate.savegame import base_types
from magnate.savegame import data_def
from magnate.savegame import db
    session = Session()

    systems = session.query(db.SystemData).all()
    assert len(systems) == 1
    assert systems[0].name == 'Test'
    assert len(systems[0].celestials) == 2
    assert frozenset((systems[0].celestials[0].name, systems[0].celestials[1].name)) == frozenset(('Primary', 'Friesland'))
    assert systems[0].celestials[0].locations[0].name == 'Solar Observation Station'
    assert systems[0].celestials[1].locations == []

    commodities = session.query(db.CommodityData).all()
    assert len(commodities) == 1
    assert commodities[0].name == 'Drugs'

    ships = session.query(db.ShipData).all()
    assert len(ships) == 1
    assert ships[0].name == 'ship'

    properties = session.query(db.PropertyData).all()
    assert len(properties) == 1
    assert properties[0].name == 'property'

    ship_parts = session.query(db.ShipPartData).all()
    assert len(ship_parts) == 2
    assert frozenset((ship_parts[0].name, ship_parts[1].name)) == frozenset(('add storage', 'take up space'))

    events = session.query(db.EventData).filter(db.EventData.msg == 'price lower').all()
    assert len(events) == 1
    assert events[0].adjustment == -5
    assert len(events[0].affects) == 2

# Path: magnate/errors.py
# class MagnateNoSaveGame(MagnateSaveError):
#     """Raised when a save game file is missing"""
#     pass
# 
# 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: 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/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: tests/units/savegame/test_db.py
import os.path
import shutil
import pytest
import sqlalchemy
from magnate.errors import MagnateNoSaveGame
from magnate.savegame import base_types
from magnate.savegame import data_def
from magnate.savegame import db

    session = Session()

    systems = session.query(db.SystemData).all()
    assert len(systems) == 1
    assert systems[0].name == 'Test'
    assert len(systems[0].celestials) == 2
    assert frozenset((systems[0].celestials[0].name, systems[0].celestials[1].name)) == frozenset(('Primary', 'Friesland'))
    assert systems[0].celestials[0].locations[0].name == 'Solar Observation Station'
    assert systems[0].celestials[1].locations == []

    commodities = session.query(db.CommodityData).all()
    assert len(commodities) == 1
    assert commodities[0].name == 'Drugs'

    ships = session.query(db.ShipData).all()
    assert len(ships) == 1
    assert ships[0].name == 'ship'

    properties = session.query(db.PropertyData).all()
    assert len(properties) == 1
    assert properties[0].name == 'property'

    ship_parts = session.query(db.ShipPartData).all()
    assert len(ship_parts) == 2
    assert frozenset((ship_parts[0].name, ship_parts[1].name)) == frozenset(('add storage', 'take up space'))

    events = session.query(db.EventData).filter(db.EventData.msg == 'price lower').all()
    assert len(events) == 1
    assert events[0].adjustment == -5
    assert len(events[0].affects) == 2

    assert events[0].affects[0].categories == {base_types.CommodityType.food}