-
Notifications
You must be signed in to change notification settings - Fork 1
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
3 changed files
with
47 additions
and
0 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
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 |
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,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(',') |
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,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 |