Skip to content

Commit

Permalink
Python 3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
rochacbruno committed Oct 27, 2016
1 parent 2516006 commit e24a426
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 10 deletions.
3 changes: 2 additions & 1 deletion dynaconf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging
import importlib
from contextlib import contextmanager
from six import string_types
from dynaconf import default_settings
from dynaconf.utils.parse_conf import converters
from dynaconf.utils.functional import LazyObject, empty
Expand Down Expand Up @@ -313,7 +314,7 @@ def namespace(self, namespace=None, clean=True):
else:
self.loaded_namespaces = []

if not isinstance(namespace, basestring):
if not isinstance(namespace, string_types):
raise AttributeError('namespace should be a string')
if "_" in namespace:
raise AttributeError('namespace should not contains _')
Expand Down
6 changes: 3 additions & 3 deletions example/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

from .conf import settings

print settings.MYSQL_HOST
print settings.MYSQL_PASSWD
print settings.EXAMPLE
print(settings.MYSQL_HOST) # noqa
print(settings.MYSQL_PASSWD) # noqa
print(settings.EXAMPLE) # noqa
2 changes: 1 addition & 1 deletion example/mysettins.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
EXAMPLE = True
EXAMPLE = True
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name='dynaconf',
version="0.2.13",
version="0.3.0",
url='https://github.com/rochacbruno/dynaconf',
license='MIT',
author="Bruno Rocha",
Expand Down
16 changes: 13 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,30 @@
import pytest
import os
from dynaconf import LazySettings
from dynaconf.loaders.redis_loader import write
# from dynaconf.loaders.redis_loader import write


@pytest.fixture(scope='module')
def settings():
mode = 'TRAVIS' if os.environ.get('TRAVIS') else 'TEST'
return LazySettings(
os.environ['DYNA%s_HOSTNAME' % mode] = 'host.com'
os.environ['DYNA%s_PORT' % mode] = '@int 5000'
os.environ['DYNA%s_VALUE' % mode] = '@float 42.1'
os.environ['DYNA%s_ALIST' % mode] = '@json ["item1", "item2", "item3"]'
os.environ['DYNA%s_ADICT' % mode] = '@json {"key": "value"}'
os.environ['DYNA%s_DEBUG' % mode] = '@bool true'
os.environ['PROJECT1_HOSTNAME'] = 'otherhost.com'
sets = LazySettings(
LOADERS_FOR_DYNACONF=[
'dynaconf.loaders.env_loader',
'dynaconf.loaders.redis_loader'
],
DYNACONF_NAMESPACE="DYNA%s" % mode
)
sets.configure()
return sets


def pytest_runtest_setup(item):
# called for running each test in 'a' directory
print("setting up", item)
print("setting up", item) # noqa
1 change: 0 additions & 1 deletion tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@

def test_has_wrapped():
assert settings.configured is True

42 changes: 42 additions & 0 deletions tests/test_endtoend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import os


def test_end_to_end(settings):
"""
settings is fixture configured in conftest.py
"""
assert settings.HOSTNAME == 'host.com'

assert settings.PORT == 5000
assert isinstance(settings.PORT, int)

assert settings.VALUE == 42.1
assert isinstance(settings.VALUE, float)

assert settings.DEBUG is True
assert isinstance(settings.DEBUG, bool)

assert settings.ALIST == ["item1", "item2", "item3"]
assert isinstance(settings.ALIST, list)
assert len(settings.ALIST) == 3

assert settings.ADICT == {"key": "value"}
assert isinstance(settings.ADICT, dict)
assert 'key' in settings.ADICT

assert settings.get('FOO', default='bar') == 'bar'

with settings.using_namespace('PROJECT1'):
assert settings.HOSTNAME == 'otherhost.com'

assert settings.HOSTNAME == 'host.com'

if os.environ.get('TRAVIS'):
assert settings.ENV_BOOLEAN is True
assert settings.OTHER_TESTING is True
assert settings.ENV_INT == 42
assert settings.ENV_FLOAT == 42.2
assert settings.ENV_LIST == ["dyna", "conf"]
assert settings.ENV_PURE_INT == '42'
assert settings.as_int('ENV_PURE_INT') == 42
assert settings.get('ENV_PURE_INT', cast='@int') == 42

0 comments on commit e24a426

Please sign in to comment.