Ejemplo n.º 1
0
    def test_context_manager(self):
        settings = Settings()
        settings.configure(debug=False)

        with settings(debug=True):
            self.assertEqual(True, settings.debug)
        self.assertEqual(False, settings.debug)
Ejemplo n.º 2
0
    def test_context_manager(self):
        settings = Settings()
        settings.configure(debug=False)

        with settings(debug=True):
            self.assertEqual(True, settings.debug)
        self.assertEqual(False, settings.debug)
Ejemplo n.º 3
0
    def test_as_dict(self):
        settings = Settings()
        settings.configure(debug=False)

        with settings(debug=True):
            self.assertEqual(dict(debug=True), settings.as_dict())

        self.assertEqual(dict(debug=False), settings.as_dict())
Ejemplo n.º 4
0
    def test_as_dict(self):
        settings = Settings()
        settings.configure(debug=False)

        with settings(debug=True):
            self.assertEqual(dict(debug=True), settings.as_dict())

        self.assertEqual(dict(debug=False), settings.as_dict())
Ejemplo n.º 5
0
    def test_decorator(self):
        settings = Settings()
        settings.configure(debug=False)

        @settings(debug=True)
        def go():
            self.assertEqual(True, settings.debug)

        go()
        self.assertEqual(False, settings.debug)
Ejemplo n.º 6
0
    def test_decorator(self):
        settings = Settings()
        settings.configure(debug=False)

        @settings(debug=True)
        def go():
            self.assertEqual(True, settings.debug)

        go()
        self.assertEqual(False, settings.debug)
Ejemplo n.º 7
0
    def test_with_object(self):
        class MySettings(object):
            def __init__(self):
                self.debug = False

        settings = Settings()
        settings.configure(MySettings())

        self.assertEqual(False, settings.debug)

        with settings(debug=True):
            self.assertEqual(True, settings.debug)
Ejemplo n.º 8
0
    def test_decorator_in_class(self):
        _self = self
        settings = Settings()
        settings.configure(debug=False)

        class Dummy(object):
            @settings(debug=True)
            def go(self):
                _self.assertEqual(True, settings.debug)

        Dummy().go()
        self.assertEqual(False, settings.debug)
Ejemplo n.º 9
0
    def test_decorator_in_class(self):
        _self = self
        settings = Settings()
        settings.configure(debug=False)

        class Dummy(object):
            @settings(debug=True)
            def go(self):
                _self.assertEqual(True, settings.debug)

        Dummy().go()
        self.assertEqual(False, settings.debug)
Ejemplo n.º 10
0
    def test_with_object(self):
        class MySettings(object):
            def __init__(self):
                self.debug = False

        settings = Settings()
        settings.configure(MySettings())

        self.assertEqual(False, settings.debug)

        with settings(debug=True):
            self.assertEqual(True, settings.debug)
Ejemplo n.º 11
0
    def test_with_prefix(self):
        ss = Settings()
        ss.configure(MY_a=1, OTHER_a=2, a=3, c=5, MY_b='2')
        settings = PrefixedSettings(ss, 'MY_')
        self.assertEqual(1, settings.a)
        self.assertEqual('2', settings.b)
        with self.assertRaises(AttributeError):
            a = settings.c
            self.fail(a)

        with self.assertRaises(AttributeError):
            a = settings.MY_a
            self.fail(a)
Ejemplo n.º 12
0
    def test_with_prefix(self):
        ss = Settings()
        ss.configure(
            MY_a=1,
            OTHER_a=2,
            a=3,
            c=5,
            MY_b='2')
        settings = PrefixedSettings(ss, 'MY_')
        self.assertEqual(1, settings.a)
        self.assertEqual('2', settings.b)
        with self.assertRaises(AttributeError):
            a = settings.c
            self.fail(a)

        with self.assertRaises(AttributeError):
            a = settings.MY_a
            self.fail(a)
Ejemplo n.º 13
0
    def test_warning_when_adding_duplicate(self):
        settings = Settings()
        settings.configure()

        settings2 = Settings()
        settings2.configure(settings)

        with pytest.warns(DuplicateConfigureWarning):
            settings.configure(settings2)
Ejemplo n.º 14
0
    def test_warning_when_adding_duplicate(self):
        settings = Settings()
        settings.configure()

        settings2 = Settings()
        settings2.configure(settings)

        with pytest.warns(DuplicateConfigureWarning):
            settings.configure(settings2)
Ejemplo n.º 15
0
 def test_default_settings(self):
     settings = Settings()
     settings.configure(debug=False)
     self.assertEqual(False, settings.debug)
Ejemplo n.º 16
0
 def test_no_prefix(self):
     ss = Settings()
     ss.configure(a=1, b='2')
     settings = PrefixedSettings(ss)
     self.assertEqual(1, settings.a)
     self.assertEqual('2', settings.b)
Ejemplo n.º 17
0
    def test_key_not_found(self):
        settings = Settings()
        settings.configure()

        with self.assertRaises(AttributeError):
            getattr(settings, 'debug')
Ejemplo n.º 18
0
    def test_key_not_found(self):
        settings = Settings()
        settings.configure()

        with self.assertRaises(AttributeError):
            getattr(settings, 'debug')
Ejemplo n.º 19
0
 def test_default_settings(self):
     settings = Settings()
     settings.configure(debug=False)
     self.assertEqual(False, settings.debug)
Ejemplo n.º 20
0
# -*- coding: utf-8 -*-
from pkgsettings import Settings

settings = Settings()
settings.configure(
    DO_USE_SANDBOX=False,
    CONSUMER_KEY='myorcidappkey',
    CONSUMER_SECRET='myorcidappsecret',
    REQUEST_TIMEOUT=30,
)
Ejemplo n.º 21
0
 def test_no_prefix(self):
     ss = Settings()
     ss.configure(a=1, b='2')
     settings = PrefixedSettings(ss)
     self.assertEqual(1, settings.a)
     self.assertEqual('2', settings.b)
Ejemplo n.º 22
0
"""
Time Execution decorator
"""
import socket
import time

import six
from fqn_decorators import Decorator
from pkgsettings import Settings

from .constants import PY_35_GT

SHORT_HOSTNAME = socket.gethostname()

settings = Settings()
settings.configure(backends=[], hooks=[], duration_field='value')


def write_metric(name, **metric):
    for backend in settings.backends:
        backend.write(name, **metric)


def _apply_hooks(**kwargs):
    metadata = dict()
    for hook in settings.hooks:
        hook_result = hook(**kwargs)
        if hook_result:
            metadata.update(hook_result)
    return metadata
Ejemplo n.º 23
0
"""
Time Execution decorator
"""
import socket
import time

import six
from fqn_decorators import Decorator
from pkgsettings import Settings

SHORT_HOSTNAME = socket.gethostname()

settings = Settings()
settings.configure(
    backends=[],
    hooks=[],
    duration_field='value'
)


def write_metric(name, **metric):
    for backend in settings.backends:
        backend.write(name, **metric)


def _apply_hooks(**kwargs):
    metadata = dict()
    for hook in settings.hooks:
        hook_result = hook(**kwargs)
        if hook_result:
            metadata.update(hook_result)
Ejemplo n.º 24
0
# -*- coding: utf-8 -*-
from pkgsettings import Settings

settings = Settings()
settings.configure(
    BASE_URL='localhost/api',
    REQUEST_TIMEOUT=30,
    HTTP_AUTH_USERNAME='******',
    HTTP_AUTH_PASSWORD='******',
)
Ejemplo n.º 25
0
from pkgsettings import Settings

DEFAULT_LOCAL_STORAGE_PATH = os.path.join(os.path.expanduser('~'), 'opendatastorage')


config = configparser.ConfigParser()
config['Storage'] = {}
config['Storage']['local_storage_path'] = DEFAULT_LOCAL_STORAGE_PATH
config.read('opendata.ini')


local_storage = config['Storage']['local_storage_path']
if not os.path.isdir(local_storage):
    if local_storage == DEFAULT_LOCAL_STORAGE_PATH:
        os.makedirs(DEFAULT_LOCAL_STORAGE_PATH)
        print(f'Local storage directory ({DEFAULT_LOCAL_STORAGE_PATH}) created')
    else:
        error_message = f'The specified local storage path {local_storage} does not exist'
        raise OSError(error_message)


settings = Settings()
settings.configure(
    bucket_name='goldencheetah-opendata',
    data_prefix='data',
    metadata_prefix='metadata',
    datasets_prefix='datasets',
    local_storage=config['Storage']['local_storage_path']
)