# Path: gengine/app/tests/db.py
# def setupDB():
# def unsetupDB():
# 
# Path: gengine/metadata.py
# def init_declarative_base(override_base=None):
#     global Base
#     if Base:
#         return
#     if override_base:
#         Base = override_base
#     else:
#         convention = {
#             "ix": 'ix_%(column_0_label)s',
#             "uq": "uq_%(table_name)s_%(column_0_name)s",
#             "ck": "ck_%(table_name)s_%(constraint_name)s",
#             "fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
#             "pk": "pk_%(table_name)s"
#         }
#         metadata = MetaData(naming_convention=convention)
#         Base = declarative_base(metadata = metadata)
# 
# def init_session(override_session=None, replace=False):
#     global DBSession
#     if DBSession.target and not replace:
#         return
#     if override_session:
#         DBSession.target = override_session
#     else:
#         DBSession.target = scoped_session(get_sessionmaker())


from gengine.app.tests import db as db
from gengine.metadata import init_declarative_base, init_session
        from gengine.base.cache import setup_redis_cache
        from gengine.app.cache import init_caches
import unittest
import os
import pkgutil
import logging
import sys
    import testing.redis
init_declarative_base()

__path__ = [x[0] for x in os.walk(os.path.dirname(__file__))]

def create_test_suite():
    suite = unittest.TestSuite()
    for imp, modname, _ in pkgutil.walk_packages(__path__):
        #if modname in ('test_achievement_integration_tests',):
            mod = imp.find_module(modname).load_module(modname)
            for test in unittest.defaultTestLoader.loadTestsFromModule(mod):
                suite.addTests(test)
    return suite

if __name__=="__main__":
    exit = 1
    try:
        redis = testing.redis.RedisServer()

        dsn = redis.dsn()
        setup_redis_cache(dsn["host"], dsn["port"], dsn["db"])

        init_caches()

        db.setupDB()
        testSuite = create_test_suite()
        text_runner = unittest.TextTestRunner(failfast=True).run(testSuite)
        if text_runner.wasSuccessful():
            exit = 0
    finally:
        try:

# Path: gengine/app/tests/db.py
# def setupDB():
# def unsetupDB():
# 
# Path: gengine/metadata.py
# def init_declarative_base(override_base=None):
#     global Base
#     if Base:
#         return
#     if override_base:
#         Base = override_base
#     else:
#         convention = {
#             "ix": 'ix_%(column_0_label)s',
#             "uq": "uq_%(table_name)s_%(column_0_name)s",
#             "ck": "ck_%(table_name)s_%(constraint_name)s",
#             "fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
#             "pk": "pk_%(table_name)s"
#         }
#         metadata = MetaData(naming_convention=convention)
#         Base = declarative_base(metadata = metadata)
# 
# def init_session(override_session=None, replace=False):
#     global DBSession
#     if DBSession.target and not replace:
#         return
#     if override_session:
#         DBSession.target = override_session
#     else:
#         DBSession.target = scoped_session(get_sessionmaker())


# Path: gengine/app/tests_old/runner.py
from gengine.app.tests import db as db
from gengine.metadata import init_declarative_base, init_session
        from gengine.base.cache import setup_redis_cache
        from gengine.app.cache import init_caches
import unittest
import os
import pkgutil
import logging
import sys
    import testing.redis

init_declarative_base()

__path__ = [x[0] for x in os.walk(os.path.dirname(__file__))]

def create_test_suite():
    suite = unittest.TestSuite()
    for imp, modname, _ in pkgutil.walk_packages(__path__):
        #if modname in ('test_achievement_integration_tests',):
            mod = imp.find_module(modname).load_module(modname)
            for test in unittest.defaultTestLoader.loadTestsFromModule(mod):
                suite.addTests(test)
    return suite

if __name__=="__main__":
    exit = 1
    try:
        redis = testing.redis.RedisServer()

        dsn = redis.dsn()
        setup_redis_cache(dsn["host"], dsn["port"], dsn["db"])

        init_caches()

        db.setupDB()
        testSuite = create_test_suite()
        text_runner = unittest.TextTestRunner(failfast=True).run(testSuite)
        if text_runner.wasSuccessful():
            exit = 0
    finally:
        try:

            db.unsetupDB()