| 16 | # noinspection PyUnresolvedReferences,PyUnusedLocal |
| 17 | @pytest.fixture |
| 18 | def DBInMemory_test(): |
| 19 | def rollback(): |
| 20 | with sd_lock: |
| 21 | saveddata_session.rollback() |
| 22 | |
| 23 | |
| 24 | print("Creating database in memory") |
| 25 | from os.path import realpath, join, dirname, abspath |
| 26 | |
| 27 | debug = False |
| 28 | gamedataCache = True |
| 29 | saveddataCache = True |
| 30 | gamedata_version = "" |
| 31 | gamedata_connectionstring = 'sqlite:///' + realpath(join(dirname(abspath(str(__file__))), "..", "eve.db")) |
| 32 | saveddata_connectionstring = 'sqlite:///:memory:' |
| 33 | |
| 34 | class ReadOnlyException(Exception): |
| 35 | pass |
| 36 | |
| 37 | if callable(gamedata_connectionstring): |
| 38 | gamedata_engine = create_engine("sqlite://", creator=gamedata_connectionstring, echo=debug) |
| 39 | else: |
| 40 | gamedata_engine = create_engine(gamedata_connectionstring, echo=debug) |
| 41 | |
| 42 | gamedata_meta = MetaData() |
| 43 | gamedata_meta.bind = gamedata_engine |
| 44 | gamedata_session = sessionmaker(bind=gamedata_engine, autoflush=False, expire_on_commit=False)() |
| 45 | |
| 46 | # This should be moved elsewhere, maybe as an actual query. Current, without try-except, it breaks when making a new |
| 47 | # game db because we haven't reached gamedata_meta.create_all() |
| 48 | try: |
| 49 | gamedata_version = gamedata_session.execute( |
| 50 | "SELECT `field_value` FROM `metadata` WHERE `field_name` LIKE 'client_build'" |
| 51 | ).fetchone()[0] |
| 52 | except (KeyboardInterrupt, SystemExit): |
| 53 | raise |
| 54 | except Exception as e: |
| 55 | print("Missing gamedata version.") |
| 56 | gamedata_version = None |
| 57 | |
| 58 | if saveddata_connectionstring is not None: |
| 59 | if callable(saveddata_connectionstring): |
| 60 | saveddata_engine = create_engine(creator=saveddata_connectionstring, echo=debug) |
| 61 | else: |
| 62 | saveddata_engine = create_engine(saveddata_connectionstring, echo=debug) |
| 63 | |
| 64 | saveddata_meta = MetaData() |
| 65 | saveddata_meta.bind = saveddata_engine |
| 66 | saveddata_session = sessionmaker(bind=saveddata_engine, autoflush=False, expire_on_commit=False)() |
| 67 | else: |
| 68 | saveddata_meta = None |
| 69 | |
| 70 | # Lock controlling any changes introduced to session |
| 71 | sd_lock = threading.Lock() |
| 72 | |
| 73 | # Import all the definitions for all our database stuff |
| 74 | # noinspection PyPep8 |
| 75 | #from eos.db.gamedata import alphaClones, attribute, category, effect, group, icon, item, marketGroup, metaData, metaGroup, queries, traits, unit |