Skip to content

Commit

Permalink
Merge 95a0265 into 26df9cc
Browse files Browse the repository at this point in the history
  • Loading branch information
cknv committed Jan 22, 2017
2 parents 26df9cc + 95a0265 commit b3a4578
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions envargs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Exposed internals of envparse."""
from . import inputs
from .models import Var
from .parser import parse_dict
from .parser import parse_env
18 changes: 18 additions & 0 deletions envargs/inputs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""Default value parsers. Does common things simply."""


def boolean(value):
"""Return true if the value indicates a truthiness."""
options = {
'true',
't',
'1',
'yes',
}

return value.lower() in options


def split_by_comma(value):
"""Return the value split by commas."""
return value.split(',')
28 changes: 28 additions & 0 deletions tests/test_funcs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Testing the default parser functions."""
import pytest

from envargs import inputs


@pytest.mark.parametrize('case, expected', [
('true', True),
('t', True),
('True', True),
('1', True),
('yes', True),
('0', False),
('false', False),
('no', False),
])
def test_boolean_parser(case, expected):
"""Test the default boolean parser."""
assert inputs.boolean(case) == expected


@pytest.mark.parametrize('case, expected', [
('1', ['1']),
('1,2,3', ['1', '2', '3']),
])
def test_split_by_comma(case, expected):
"""Test the splitter."""
assert inputs.split_by_comma(case) == expected

0 comments on commit b3a4578

Please sign in to comment.