Ejemplo n.º 1
0
def test_dict_config():
    from terracotta import config

    settings = config.parse_config({'DRIVER_PATH': 'test3'})
    assert settings.DRIVER_PATH == 'test3'

    settings = config.parse_config({'DEFAULT_TILE_SIZE': [100, 100]})
    assert settings.DEFAULT_TILE_SIZE == (100, 100)
Ejemplo n.º 2
0
def test_env_config(monkeypatch):
    from terracotta import config

    with monkeypatch.context() as m:
        m.setenv('TC_DRIVER_PATH', 'test')
        assert config.parse_config().DRIVER_PATH == 'test'

    with monkeypatch.context() as m:
        m.setenv('TC_DRIVER_PATH', 'test2')
        assert config.parse_config().DRIVER_PATH == 'test2'

    with monkeypatch.context() as m:
        m.setenv('TC_DEFAULT_TILE_SIZE', json.dumps([1, 2]))
        assert config.parse_config().DEFAULT_TILE_SIZE == (1, 2)
Ejemplo n.º 3
0
def test_terracotta_settings():
    from terracotta import config
    settings = config.parse_config()

    assert settings.DEFAULT_TILE_SIZE

    with pytest.raises(AttributeError):
        settings.DEFAULT_TILE_SIZE = (10, 10)
Ejemplo n.º 4
0
def update_settings(**new_config: Any) -> None:
    """Update the global Terracotta runtime settings.

    Arguments:

        new_config: Options to override. Have to be valid Terracotta settings.

    Example:

        >>> import terracotta as tc
        >>> tc.get_settings().DEFAULT_TILE_SIZE
        (256, 256)
        >>> tc.update_settings(DEFAULT_TILE_SIZE=[512, 512])
        >>> tc.get_settings().DEFAULT_TILE_SIZE
        (512, 512)

    """
    from terracotta.config import parse_config
    global _settings, _overwritten_settings
    current_config = {k: getattr(_settings, k) for k in _overwritten_settings}
    _settings = parse_config({**current_config, **new_config})
    _overwritten_settings |= set(new_config.keys())
Ejemplo n.º 5
0
def test_env_config_invalid(monkeypatch):
    from terracotta import config

    with monkeypatch.context() as m:
        m.setenv('TC_DEFAULT_TILE_SIZE', '[1')  # unbalanced bracket
        with pytest.raises(ValueError):
            config.parse_config()

    with monkeypatch.context() as m:
        m.setenv('TC_DEBUG', 'foo')  # not a boolean
        with pytest.raises(ValueError):
            config.parse_config()

    with monkeypatch.context() as m:
        m.setenv('TC_REMOTE_DB_CACHE_DIR', '/foo/test.sqlite')  # non-existing folder
        with pytest.raises(ValueError):
            config.parse_config()

    assert True
Ejemplo n.º 6
0
# get version
try:
    from terracotta._version import version as __version__  # noqa: F401
except ImportError:  # pragma: no cover
    # package is not installed
    raise RuntimeError(
        'Terracotta has not been installed correctly. Please run `pip install -e .` or '
        '`python setup.py develop` in the Terracotta package folder.'
    ) from None

# initialize settings, define settings API
from typing import Mapping, Any, Set
from terracotta.config import parse_config, TerracottaSettings

_settings: TerracottaSettings = parse_config()
_overwritten_settings: Set = set()


def update_settings(**new_config: Any) -> None:
    """Update the global Terracotta runtime settings.

    Arguments:

        new_config: Options to override. Have to be valid Terracotta settings.

    Example:

        >>> import terracotta as tc
        >>> tc.get_settings().DEFAULT_TILE_SIZE
        (256, 256)