This repository has been archived by the owner on Jan 4, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from __future__ import absolute_import | ||
|
||
from .._hook import import_hook | ||
|
||
|
||
@import_hook(__name__) | ||
def value_processor(name, raw_name, raw_value): | ||
import json | ||
try: | ||
return json.loads(raw_value) | ||
except ValueError: | ||
return raw_value | ||
|
||
|
||
del import_hook | ||
del value_processor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from pytest import raises | ||
|
||
|
||
def test_success(environ): | ||
environ['SUCHDOGE_BOOLEAN'] = 'true' | ||
environ['SUCHDOGE_INTEGER'] = '42' | ||
environ['SUCHDOGE_REAL'] = '42.42' | ||
environ['SUCHDOGE_STRING'] = '"42"' | ||
environ['SUCHDOGE_DICT'] = '{"value": 42}' | ||
environ['SUCHDOGE_RAW_STR'] = 'foo' | ||
|
||
from envcfg.smart.suchdoge import ( | ||
BOOLEAN, | ||
INTEGER, | ||
REAL, | ||
STRING, | ||
DICT, | ||
RAW_STR, | ||
) | ||
assert BOOLEAN is True | ||
assert INTEGER == 42 | ||
assert REAL == 42.42 | ||
assert STRING == '42' | ||
assert DICT == {'value': 42} | ||
assert RAW_STR == 'foo' | ||
|
||
|
||
def test_failed(environ): | ||
with raises(ImportError) as einfo: | ||
import envcfg.smart._private_module # noqa | ||
assert einfo.value.args[0].startswith( | ||
'No module named envcfg.smart._private_module') | ||
|
||
with raises(ImportError) as einfo: | ||
import envcfg.smart.INVALID_NAME # noqa | ||
assert einfo.value.args[0].startswith( | ||
'No module named envcfg.smart.INVALID_NAME') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[tox] | ||
envlist = py27,py33,py34,pypy | ||
envlist = py27,py33,py34,py35,pypy | ||
[testenv] | ||
deps = | ||
pytest | ||
|