From 2d6b50509cc29516f9ef379619d9a3ac15c5c629 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sat, 11 Jul 2020 14:56:53 -0500 Subject: Fix imports in tests/ --- tests/test_parse_value.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/test_parse_value.py') diff --git a/tests/test_parse_value.py b/tests/test_parse_value.py index 81db472..37c68b5 100644 --- a/tests/test_parse_value.py +++ b/tests/test_parse_value.py @@ -1,6 +1,6 @@ import pytest -from config_file.parsers.parse_value import can_be_parsed_as_bool, parse_value +from config_file.parsers import can_be_parsed_as_bool, parse_value @pytest.mark.parametrize( -- cgit v1.2.3 From 3fa782f5b5e3bd4445a5db63c0fce5aaac2d4ac3 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Mon, 20 Jul 2020 22:55:40 -0500 Subject: Add work in progress tests --- tests/test_parse_value.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/test_parse_value.py') diff --git a/tests/test_parse_value.py b/tests/test_parse_value.py index 37c68b5..81db472 100644 --- a/tests/test_parse_value.py +++ b/tests/test_parse_value.py @@ -1,6 +1,6 @@ import pytest -from config_file.parsers import can_be_parsed_as_bool, parse_value +from config_file.parsers.parse_value import can_be_parsed_as_bool, parse_value @pytest.mark.parametrize( -- cgit v1.2.3 From 3c1ebfaf0db4a29cc8ee9ba742c6d8925dc79cff Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Wed, 29 Jul 2020 23:53:15 -0500 Subject: Allow string lists and dicts to be auto parsed --- tests/test_parse_value.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'tests/test_parse_value.py') diff --git a/tests/test_parse_value.py b/tests/test_parse_value.py index 81db472..63ce6bb 100644 --- a/tests/test_parse_value.py +++ b/tests/test_parse_value.py @@ -19,13 +19,16 @@ from config_file.parsers.parse_value import can_be_parsed_as_bool, parse_value (True, True), ({"blah": "5"}, {"blah": 5}), ( - {"blah": {"blah2": {"blah3": "false"}, "abc": "5.25", "boo": "tRuE"}}, + {"blah": {"blah2": {"blah3": "fAlSe"}, "abc": "5.25", "boo": "tRuE"}}, {"blah": {"blah2": {"blah3": False}, "abc": 5.25, "boo": True}}, ), ( ["5", "4.4", "faLSe", "trUE", "foo", "-5", "-5.2"], [5, 4.4, False, True, "foo", -5, -5.2], ), + ("[1, 2, 3]", [1, 2, 3]), + ("[True, [1, 5], {}, 5.5]", [True, [1, 5], {}, 5.5]), + ("{ 'key': '5', 'key2': 'fAlSE' }", {"key": 5, "key2": False}), ], ) def test_parse_value(test_input, expected): -- cgit v1.2.3 From 5ac52d231e56f60a22ba3f755415c4aa43a14d83 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sat, 1 Aug 2020 11:20:39 -0500 Subject: Add tests to parse_value and fix bugs in it --- tests/test_parse_value.py | 191 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 177 insertions(+), 14 deletions(-) (limited to 'tests/test_parse_value.py') diff --git a/tests/test_parse_value.py b/tests/test_parse_value.py index 63ce6bb..735abc3 100644 --- a/tests/test_parse_value.py +++ b/tests/test_parse_value.py @@ -1,6 +1,15 @@ +from datetime import datetime + import pytest -from config_file.parsers.parse_value import can_be_parsed_as_bool, parse_value +from config_file.parsers.parse_value import ( + can_be_parsed_as_bool, + can_be_parsed_as_dict, + can_be_parsed_as_float, + can_be_parsed_as_int, + can_be_parsed_as_list, + parse_value, +) @pytest.mark.parametrize( @@ -8,37 +17,191 @@ from config_file.parsers.parse_value import can_be_parsed_as_bool, parse_value [ ("5", 5), ("-5", -5), + ("0", 0), ("-234.5", -234.5), ("35.5", 35.5), ("TRUE", True), ("true", True), ("false", False), - ("blah", "blah"), - (343, 343), - (3.2, 3.2), - (True, True), + ], +) +def test_parse_value_parses_ints_floats_and_bools(test_input, expected): + """ + config_file.parsers.parse_value + + Parses string values that contain ints, floats, and booleans into + their native representation. + """ + assert parse_value(test_input) == expected + + +@pytest.mark.parametrize( + "test_input,expected", + [ ({"blah": "5"}, {"blah": 5}), ( {"blah": {"blah2": {"blah3": "fAlSe"}, "abc": "5.25", "boo": "tRuE"}}, {"blah": {"blah2": {"blah3": False}, "abc": 5.25, "boo": True}}, ), + ("{ 'key': '5', 'key2': 'fAlSE' }", {"key": 5, "key2": False}), ( ["5", "4.4", "faLSe", "trUE", "foo", "-5", "-5.2"], [5, 4.4, False, True, "foo", -5, -5.2], ), - ("[1, 2, 3]", [1, 2, 3]), - ("[True, [1, 5], {}, 5.5]", [True, [1, 5], {}, 5.5]), - ("{ 'key': '5', 'key2': 'fAlSE' }", {"key": 5, "key2": False}), + (" [1, 2, 3] ", [1, 2, 3]), + (" [True, [1, 5], {}, 5.5]", [True, [1, 5], {}, 5.5]), ], ) -def test_parse_value(test_input, expected): +def test_parse_value_parses_dicts_and_lists(test_input, expected): + """ + config_file.parsers.parse_value + + Parses string values that contain dictionaries or lists into + their native representation. + """ assert parse_value(test_input) == expected -def test_can_be_parsed_as_bool(): +@pytest.mark.parametrize("test_input", ["blah", datetime(2020, 1, 1)]) +def test_parse_value_returns_values_that_cannot_be_parsed(test_input): + """ + config_file.parsers.parse_value + + If a value is given that cannot be parsed by parse_value, + it should simply return that value back. + """ + assert parse_value(test_input) == test_input + + +@pytest.mark.parametrize( + "test_input", + [(343, 343), (3.2, 3.2), (True, True), (False, False), ({}, {}), ([], [])], +) +def test_parse_value_returns_values_that_are_already_in_their_native_type(test_input): + """ + config_file.parsers.parse_value + + Returns back the inputted value if it is already in its native type. + """ + assert parse_value(test_input) == test_input + + +@pytest.mark.parametrize("value", [-1, 0, 1, "1", "-1", " 0 "]) +def test_values_that_can_be_parsed_as_int(value): + """ + config_file.parsers.can_be_parsed_as_int + + Returns True for values that can be parsed as an int. + """ + assert can_be_parsed_as_int(value) + + +@pytest.mark.parametrize( + "value", [True, False, 5.5, "5.5", [], {}, "ruff", datetime.now()] +) +def test_values_that_cannot_be_parsed_as_int(value): + """ + config_file.parsers.can_be_parsed_as_int + + Returns False for values that cannot be parsed as an int. + """ + assert not can_be_parsed_as_int(value) + + +@pytest.mark.parametrize("value", [5.5, -1.2, ".1", "5.5", " 1.1 ", "-0.0", "0.0"]) +def test_values_that_can_be_parsed_as_float(value): """ - This is the section not being covered in the parse_value.py - file from test_parse_value, but I don't think it's reachable - from using it. + config_file.parsers.can_be_parsed_as_float + + Returns True for values that can be parsed as an float. + """ + assert can_be_parsed_as_float(value) + + +@pytest.mark.parametrize( + "value", + [ + 545, + 0, + -3, + "1", + "-1", + True, + False, + " 0 ", + "0..0", + [], + {}, + "ruff", + datetime.now(), + ], +) +def test_values_that_cannot_be_parsed_as_float(value): + """ + config_file.parsers.can_be_parsed_as_float + + Returns False for values that cannot be parsed as an float. + """ + assert not can_be_parsed_as_float(value) + + +@pytest.mark.parametrize( + "value", [True, False, "false", "true", "TRUE", "FALSE", " FALSE ", " TRUE "] +) +def test_values_that_can_be_parsed_as_bool(value): + """ + config_file.parsers.can_be_parsed_as_bool + + Returns True for values that can be parsed as a bool. + """ + assert can_be_parsed_as_bool(value) + + +@pytest.mark.parametrize("value", [0, 1, -1, 5.3, "ruff", {}, [], datetime.now()]) +def test_values_that_cannot_be_parsed_as_bool(value): + """ + config_file.parsers.can_be_parsed_as_bool + + Returns False for values that cannot be parsed as a bool. + """ + assert not can_be_parsed_as_bool(value) + + +@pytest.mark.parametrize("value", [{}, {"hello": 5}, "{}", " { } ", "{'test': 5}"]) +def test_values_that_can_be_parsed_as_dict(value): + """ + config_file.parsers.can_be_parsed_as_dict + + Returns True for values that can be parsed as a dict. + """ + assert can_be_parsed_as_dict(value) + + +@pytest.mark.parametrize("value", [0, 5, -1, 5.5, [], "ruff", " { invalid } "]) +def test_values_that_cannot_be_parsed_as_dict(value): + """ + config_file.parsers.can_be_parsed_as_dict + + Returns False for values that cannot be parsed as a dict. + """ + assert not can_be_parsed_as_dict(value) + + +@pytest.mark.parametrize("value", [[], [1, 2, True, 5.5], "[]", " [] ", " [1, 2, 3]"]) +def test_values_that_can_be_parsed_as_list(value): + """ + config_file.parsers.can_be_parsed_as_list + + Returns True for values that can be parsed as a list. + """ + assert can_be_parsed_as_list(value) + + +@pytest.mark.parametrize("value", [0, 5, -1, 5.5, {}, "ruff", " [ invalid ] "]) +def test_values_that_cannot_be_parsed_as_list(value): + """ + config_file.parsers.can_be_parsed_as_list + + Returns False for values that cannot be parsed as a list. """ - assert can_be_parsed_as_bool(5) is False + assert not can_be_parsed_as_list(value) -- cgit v1.2.3 From c7922b08bf010375416138b2ca85fe88fd8edcef Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sat, 1 Aug 2020 11:54:22 -0500 Subject: Expand on docstrings for parse_value file --- tests/test_parse_value.py | 1 + 1 file changed, 1 insertion(+) (limited to 'tests/test_parse_value.py') diff --git a/tests/test_parse_value.py b/tests/test_parse_value.py index 735abc3..853537c 100644 --- a/tests/test_parse_value.py +++ b/tests/test_parse_value.py @@ -50,6 +50,7 @@ def test_parse_value_parses_ints_floats_and_bools(test_input, expected): ), (" [1, 2, 3] ", [1, 2, 3]), (" [True, [1, 5], {}, 5.5]", [True, [1, 5], {}, 5.5]), + (" [ [ [ [] ]] ] ", [[[[]]]]), ], ) def test_parse_value_parses_dicts_and_lists(test_input, expected): -- cgit v1.2.3 From 59eeb1321fbad41dce7c971778e37ac1943fda3b Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Wed, 5 Aug 2020 20:39:28 -0500 Subject: Redo package to have a flat package structure By having a flat package structure like this, it'll avoid exposing packages and things we don't want to be exposed. --- tests/test_parse_value.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/test_parse_value.py') diff --git a/tests/test_parse_value.py b/tests/test_parse_value.py index 853537c..976c613 100644 --- a/tests/test_parse_value.py +++ b/tests/test_parse_value.py @@ -2,7 +2,7 @@ from datetime import datetime import pytest -from config_file.parsers.parse_value import ( +from config_file.parse_value import ( can_be_parsed_as_bool, can_be_parsed_as_dict, can_be_parsed_as_float, -- cgit v1.2.3 From 924896167d69d753e0150f6089a0ca3d931f0169 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Wed, 5 Aug 2020 21:37:13 -0500 Subject: Fix parse_value test docstring paths --- tests/test_parse_value.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'tests/test_parse_value.py') diff --git a/tests/test_parse_value.py b/tests/test_parse_value.py index 976c613..7956a06 100644 --- a/tests/test_parse_value.py +++ b/tests/test_parse_value.py @@ -27,7 +27,7 @@ from config_file.parse_value import ( ) def test_parse_value_parses_ints_floats_and_bools(test_input, expected): """ - config_file.parsers.parse_value + config_file.parse_value.parse_value Parses string values that contain ints, floats, and booleans into their native representation. @@ -55,7 +55,7 @@ def test_parse_value_parses_ints_floats_and_bools(test_input, expected): ) def test_parse_value_parses_dicts_and_lists(test_input, expected): """ - config_file.parsers.parse_value + config_file.parse_value.parse_value Parses string values that contain dictionaries or lists into their native representation. @@ -66,7 +66,7 @@ def test_parse_value_parses_dicts_and_lists(test_input, expected): @pytest.mark.parametrize("test_input", ["blah", datetime(2020, 1, 1)]) def test_parse_value_returns_values_that_cannot_be_parsed(test_input): """ - config_file.parsers.parse_value + config_file.parse_value.parse_value If a value is given that cannot be parsed by parse_value, it should simply return that value back. @@ -80,7 +80,7 @@ def test_parse_value_returns_values_that_cannot_be_parsed(test_input): ) def test_parse_value_returns_values_that_are_already_in_their_native_type(test_input): """ - config_file.parsers.parse_value + config_file.parse_value.parse_value Returns back the inputted value if it is already in its native type. """ @@ -90,7 +90,7 @@ def test_parse_value_returns_values_that_are_already_in_their_native_type(test_i @pytest.mark.parametrize("value", [-1, 0, 1, "1", "-1", " 0 "]) def test_values_that_can_be_parsed_as_int(value): """ - config_file.parsers.can_be_parsed_as_int + config_file.parse_value.can_be_parsed_as_int Returns True for values that can be parsed as an int. """ @@ -102,7 +102,7 @@ def test_values_that_can_be_parsed_as_int(value): ) def test_values_that_cannot_be_parsed_as_int(value): """ - config_file.parsers.can_be_parsed_as_int + config_file.parse_value.can_be_parsed_as_int Returns False for values that cannot be parsed as an int. """ @@ -112,7 +112,7 @@ def test_values_that_cannot_be_parsed_as_int(value): @pytest.mark.parametrize("value", [5.5, -1.2, ".1", "5.5", " 1.1 ", "-0.0", "0.0"]) def test_values_that_can_be_parsed_as_float(value): """ - config_file.parsers.can_be_parsed_as_float + config_file.parse_value.can_be_parsed_as_float Returns True for values that can be parsed as an float. """ @@ -139,7 +139,7 @@ def test_values_that_can_be_parsed_as_float(value): ) def test_values_that_cannot_be_parsed_as_float(value): """ - config_file.parsers.can_be_parsed_as_float + config_file.parse_value.can_be_parsed_as_float Returns False for values that cannot be parsed as an float. """ @@ -151,7 +151,7 @@ def test_values_that_cannot_be_parsed_as_float(value): ) def test_values_that_can_be_parsed_as_bool(value): """ - config_file.parsers.can_be_parsed_as_bool + config_file.parse_value.can_be_parsed_as_bool Returns True for values that can be parsed as a bool. """ @@ -161,7 +161,7 @@ def test_values_that_can_be_parsed_as_bool(value): @pytest.mark.parametrize("value", [0, 1, -1, 5.3, "ruff", {}, [], datetime.now()]) def test_values_that_cannot_be_parsed_as_bool(value): """ - config_file.parsers.can_be_parsed_as_bool + config_file.parse_value.can_be_parsed_as_bool Returns False for values that cannot be parsed as a bool. """ @@ -171,7 +171,7 @@ def test_values_that_cannot_be_parsed_as_bool(value): @pytest.mark.parametrize("value", [{}, {"hello": 5}, "{}", " { } ", "{'test': 5}"]) def test_values_that_can_be_parsed_as_dict(value): """ - config_file.parsers.can_be_parsed_as_dict + config_file.parse_value.can_be_parsed_as_dict Returns True for values that can be parsed as a dict. """ @@ -181,7 +181,7 @@ def test_values_that_can_be_parsed_as_dict(value): @pytest.mark.parametrize("value", [0, 5, -1, 5.5, [], "ruff", " { invalid } "]) def test_values_that_cannot_be_parsed_as_dict(value): """ - config_file.parsers.can_be_parsed_as_dict + config_file.parse_value.can_be_parsed_as_dict Returns False for values that cannot be parsed as a dict. """ @@ -191,7 +191,7 @@ def test_values_that_cannot_be_parsed_as_dict(value): @pytest.mark.parametrize("value", [[], [1, 2, True, 5.5], "[]", " [] ", " [1, 2, 3]"]) def test_values_that_can_be_parsed_as_list(value): """ - config_file.parsers.can_be_parsed_as_list + config_file.parse_value.can_be_parsed_as_list Returns True for values that can be parsed as a list. """ @@ -201,7 +201,7 @@ def test_values_that_can_be_parsed_as_list(value): @pytest.mark.parametrize("value", [0, 5, -1, 5.5, {}, "ruff", " [ invalid ] "]) def test_values_that_cannot_be_parsed_as_list(value): """ - config_file.parsers.can_be_parsed_as_list + config_file.parse_value.can_be_parsed_as_list Returns False for values that cannot be parsed as a list. """ -- cgit v1.2.3