Beispiel #1
0
def create_test_storage(
        engine_kwargs: Optional[Dict[str, Any]] = None) -> RDBStorage:

    storage = RDBStorage("sqlite:///:memory:", engine_kwargs=engine_kwargs)
    return storage
Beispiel #2
0
def test_init_url_template() -> None:

    with tempfile.NamedTemporaryFile(suffix="{SCHEMA_VERSION}") as tf:
        storage = RDBStorage("sqlite:///" + tf.name)
        assert storage.engine.url.database.endswith(str(SCHEMA_VERSION))
Beispiel #3
0
def test_set_default_engine_kwargs_for_mysql(
    url: str, engine_kwargs: Dict[str, Any], expected: bool
) -> None:

    RDBStorage._set_default_engine_kwargs_for_mysql(url, engine_kwargs)
    assert engine_kwargs["pool_pre_ping"] is expected
Beispiel #4
0
        trial_id=-1,  # dummy id
    )
]

STORAGE_MODES = [
    'none',  # We give `None` to storage argument, so InMemoryStorage is used.
    'new',  # We always create a new sqlite DB file for each experiment.
    'common',  # We use a sqlite DB file for the whole experiments.
]

CACHE_MODES = [True, False]

# TODO(Yanase): Replace @parametrize_storage with StorageSupplier.
parametrize_storage = pytest.mark.parametrize(
    'storage_init_func',
    [InMemoryStorage, lambda: RDBStorage('sqlite:///:memory:')])


def setup_module():
    # type: () -> None

    StorageSupplier.setup_common_tempfile()


def teardown_module():
    # type: () -> None

    StorageSupplier.teardown_common_tempfile()


@parametrize_storage
Beispiel #5
0
def test_init_url_template():
    # type: ()-> None

    with tempfile.NamedTemporaryFile(suffix='{SCHEMA_VERSION}') as tf:
        storage = RDBStorage('sqlite:///' + tf.name)
        assert storage.engine.url.database.endswith(str(SCHEMA_VERSION))
Beispiel #6
0
def create_test_storage():
    # type: () -> RDBStorage

    storage = RDBStorage('sqlite:///:memory:')
    return storage
Beispiel #7
0
def get_storage():
    main_ip = os.environ.get("MAIN_IP")
    if main_ip is None or main_ip == '0.0.0.0':
        main_ip = 'optuna_mysql'
    url = f'mysql://{os.environ.get("MYSQL_DB_USER")}:{os.environ.get("MYSQL_DB_PASS")}@{main_ip}:{os.environ.get("MYSQL_DB_PORT")}/{os.environ.get("MYSQL_DB_NAME")}'
    return RDBStorage(url=url)
Beispiel #8
0

def redis_with_flushdb():
    # type: () -> BaseStorage

    # The redis url is not going to be used, but it has to be valid.
    storage = RedisStorage("redis://localhost")
    storage._redis = fakeredis.FakeStrictRedis()
    return storage


# TODO(Yanase): Replace @parametrize_storage with StorageSupplier.
parametrize_storage = pytest.mark.parametrize(
    "storage_init_func",
    [
        InMemoryStorage, lambda: RDBStorage("sqlite:///:memory:"),
        redis_with_flushdb
    ],
)


def setup_module():
    # type: () -> None

    StorageSupplier.setup_common_tempfile()


def teardown_module():
    # type: () -> None

    StorageSupplier.teardown_common_tempfile()
Beispiel #9
0
def test_set_default_engine_kwargs_for_mysql(url, engine_kwargs, expected):
    # type: (str, Dict[str, Any], bool)-> None

    RDBStorage._set_default_engine_kwargs_for_mysql(url, engine_kwargs)
    assert engine_kwargs["pool_pre_ping"] is expected
Beispiel #10
0
        datetime_complete=None,  # dummy
        trial_id=-1,  # dummy id
    )
]

STORAGE_MODES = [
    'none',  # We give `None` to storage argument, so InMemoryStorage is used.
    'new',  # We always create a new sqlite DB file for each experiment.
    'common',  # We use a sqlite DB file for the whole experiments.
]

CACHE_MODES = [True, False]

# TODO(Yanase): Replace @parametrize_storage with StorageSupplier.
parametrize_storage = pytest.mark.parametrize(
    'storage_init_func', [InMemoryStorage, lambda: RDBStorage('sqlite:///:memory:')])


def setup_module():
    # type: () -> None

    StorageSupplier.setup_common_tempfile()


def teardown_module():
    # type: () -> None

    StorageSupplier.teardown_common_tempfile()


@parametrize_storage
Beispiel #11
0
def create_test_storage(engine_kwargs=None):
    # type: (Optional[Dict[str, Any]]) -> RDBStorage

    storage = RDBStorage('sqlite:///:memory:', engine_kwargs=engine_kwargs)
    return storage
Beispiel #12
0
def create_test_storage(enable_cache=True):
    # type: (bool) -> RDBStorage

    storage = RDBStorage('sqlite:///:memory:', enable_cache=enable_cache)
    return storage