diff --git a/tests/test_env.py b/tests/test_env.py index 35b714cb..f2885467 100644 --- a/tests/test_env.py +++ b/tests/test_env.py @@ -25,6 +25,7 @@ @pytest.mark.parametrize( 'variable,value,raw_value,parse_comments', [ + # parse_comments=True ('BOOL_TRUE_STRING_LIKE_BOOL_WITH_COMMENT', 'True', "'True' # comment\n", True), ('BOOL_TRUE_BOOL_WITH_COMMENT', 'True ', "True # comment\n", True), ('STR_QUOTED_IGNORE_COMMENT', 'foo', " 'foo' # comment\n", True), @@ -32,6 +33,24 @@ ('SECRET_KEY_1', '"abc', '"abc#def"\n', True), ('SECRET_KEY_2', 'abc', 'abc#def\n', True), ('SECRET_KEY_3', 'abc#def', "'abc#def'\n", True), + + # parse_comments=False + ('BOOL_TRUE_STRING_LIKE_BOOL_WITH_COMMENT', "'True' # comment", "'True' # comment\n", False), + ('BOOL_TRUE_BOOL_WITH_COMMENT', 'True # comment', "True # comment\n", False), + ('STR_QUOTED_IGNORE_COMMENT', " 'foo' # comment", " 'foo' # comment\n", False), + ('STR_QUOTED_INCLUDE_HASH', "'foo # with hash' # not comment", "'foo # with hash' # not comment\n", False), + ('SECRET_KEY_1', 'abc#def', '"abc#def"\n', False), + ('SECRET_KEY_2', 'abc#def', 'abc#def\n', False), + ('SECRET_KEY_3', 'abc#def', "'abc#def'\n", False), + + # parse_comments is not defined (default behavior) + ('BOOL_TRUE_STRING_LIKE_BOOL_WITH_COMMENT', "'True' # comment", "'True' # comment\n", None), + ('BOOL_TRUE_BOOL_WITH_COMMENT', 'True # comment', "True # comment\n", None), + ('STR_QUOTED_IGNORE_COMMENT', " 'foo' # comment", " 'foo' # comment\n", None), + ('STR_QUOTED_INCLUDE_HASH', "'foo # with hash' # not comment", "'foo # with hash' # not comment\n", None), + ('SECRET_KEY_1', 'abc#def', '"abc#def"\n', None), + ('SECRET_KEY_2', 'abc#def', 'abc#def\n', None), + ('SECRET_KEY_3', 'abc#def', "'abc#def'\n", None), ], ) def test_parse_comments(variable, value, raw_value, parse_comments): @@ -46,7 +65,10 @@ def test_parse_comments(variable, value, raw_value, parse_comments): env = Env() Env.ENVIRON = {} - env.read_env(env_path, parse_comments=parse_comments) + if parse_comments is None: + env.read_env(env_path) + else: + env.read_env(env_path, parse_comments=parse_comments) assert env(variable) == value