Skip to content

Commit

Permalink
First steps into adding parsing helpers
Browse files Browse the repository at this point in the history
This first one is does booleans.
  • Loading branch information
cknv committed Jan 21, 2017
1 parent 26df9cc commit 9fe8003
Show file tree
Hide file tree
Showing 3 changed files with 33 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
13 changes: 13 additions & 0 deletions envargs/inputs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""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
19 changes: 19 additions & 0 deletions tests/test_funcs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""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

0 comments on commit 9fe8003

Please sign in to comment.