diff options
| author | Eugene Triguba <eugenetriguba@gmail.com> | 2020-01-17 16:10:39 -0600 |
|---|---|---|
| committer | Eugene Triguba <eugenetriguba@gmail.com> | 2020-01-17 16:10:39 -0600 |
| commit | 993f92f03626adf583d8cedb01f52b18afe28c29 (patch) | |
| tree | 2ddef347ea4f13e5642da5f64ccb648cc7b64913 | |
| parent | Bump version: 0.2.0 → 0.3.0 (diff) | |
| download | config-file-993f92f03626adf583d8cedb01f52b18afe28c29.zip | |
Run pre-commit on all files
| -rw-r--r-- | config_file/config_file.py | 6 | ||||
| -rw-r--r-- | config_file/parsers/ini_parser.py | 4 | ||||
| -rw-r--r-- | pyproject.toml | 1 | ||||
| -rw-r--r-- | tests/test_ini_parser.py | 42 |
4 files changed, 17 insertions, 36 deletions
diff --git a/config_file/config_file.py b/config_file/config_file.py index a95aa2d..a57e77f 100644 --- a/config_file/config_file.py +++ b/config_file/config_file.py @@ -1,11 +1,10 @@ from pathlib import Path -from config_file.parsers.ini_parser import IniParser from config_file.parsers.base_parser import BaseParser +from config_file.parsers.ini_parser import IniParser class ConfigFile: - def __init__(self, file_path: str, parser=None): self.path = self.__create_config_path(file_path) @@ -66,6 +65,3 @@ class ConfigFile: it would only be checking if the section """ return self.parser.has(section_key) - - - diff --git a/config_file/parsers/ini_parser.py b/config_file/parsers/ini_parser.py index 9a69164..502ad54 100644 --- a/config_file/parsers/ini_parser.py +++ b/config_file/parsers/ini_parser.py @@ -6,7 +6,6 @@ from config_file.parsers.parse_value import parse_value class IniParser(BaseParser): - def __init__(self, file_contents: str): """Reads in the file contents into the parser.""" try: @@ -27,7 +26,8 @@ class IniParser(BaseParser): :param parse_type: Coerces the return value to its native type. :return: The value of the key, parsed to its native type if parse_type is True. - :raises ValueError: if the section_key given is not in a dot format. e.g. 'section1.key' + :raises ValueError: if the section_key given is not in a dot format. + e.g. 'section1.key' :raises ParsingError: if the specified `section.key` is not found, in an invalid format, or if we are unable to coerce the return value to value_type. """ diff --git a/pyproject.toml b/pyproject.toml index 0ac41bf..c59e3b5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,6 +42,7 @@ include = '\.pyi?$' [tool.isort] line_length = 88 multi_line_output = 3 +include_trailing_comma = true known_third_party = ["pytest"] known_first_party = ["config_file"] diff --git a/tests/test_ini_parser.py b/tests/test_ini_parser.py index 6e5b0a8..5c26b23 100644 --- a/tests/test_ini_parser.py +++ b/tests/test_ini_parser.py @@ -3,13 +3,7 @@ import pytest from config_file.parsers.ini_parser import IniParser, ParsingError -@pytest.mark.parametrize( - "ini_file", - [ - "blahblahblah", - "{ 'key1': 5 }", - ] -) +@pytest.mark.parametrize("ini_file", ["blahblahblah", "{ 'key1': 5 }"]) def test_incorrect_ini_formats(ini_file): with pytest.raises(ParsingError): IniParser(ini_file) @@ -22,7 +16,6 @@ def test_incorrect_ini_formats(ini_file): ("test_section.strkey", "blah", True), ("test_section.boolkey", False, True), ("test_section.floatkey", 5.3, True), - ("test_section.intkey", "5", False), ("test_section.strkey", "blah", False), ("test_section.boolkey", "false", False), @@ -30,7 +23,13 @@ def test_incorrect_ini_formats(ini_file): ], ) def test_that_ini_parser_can_get_values(section_key, expected_value, parse_type): - ini_file = """[test_section]\nintkey = 5\nstrkey = blah\nboolkey = false\nfloatkey = 5.3\n\n""" + ini_file = """[test_section] +intkey = 5 +strkey = blah +boolkey = false +floatkey = 5.3 + +""" parser = IniParser(ini_file) assert parser.get(section_key, parse_type=parse_type) == expected_value @@ -41,7 +40,7 @@ def test_that_ini_parser_can_get_values(section_key, expected_value, parse_type) ("test.key1", "different value", "[test]\nkey1 = different value\n\n"), ("test.key2", 5, "[test]\nkey1 = different value\nkey2 = 5\n\n"), ("test2.key", False, "[test]\nkey1 = value1\n[test2]\nkey = False\n\n"), - ] + ], ) def test_that_ini_parser_can_set_values(section_key, value, expected_value): ini_file = """[test]\nkey1 = value1\n\n""" @@ -51,11 +50,7 @@ def test_that_ini_parser_can_set_values(section_key, value, expected_value): @pytest.mark.parametrize( "ini_file", - [ - "[test]\nkey1 = value1\n\n", - "[test]\nblah = 5\n\n[section2]\nkey = 2\n\n", - "", - ] + ["[test]\nkey1 = value1\n\n", "[test]\nblah = 5\n\n[section2]\nkey = 2\n\n", ""], ) def test_that_ini_parser_can_be_stringified(ini_file): parser = IniParser(ini_file) @@ -64,10 +59,7 @@ def test_that_ini_parser_can_be_stringified(ini_file): @pytest.mark.parametrize( "section_key,expected_result", - [ - ("test_section", ""), - ("test_section.key1", "[test_section]\n\n"), - ], + [("test_section", ""), ("test_section.key1", "[test_section]\n\n")], ) def test_that_ini_parser_can_delete(section_key, expected_result): ini_file = """[test_section]\nkey1 = value\n\n""" @@ -77,11 +69,7 @@ def test_that_ini_parser_can_delete(section_key, expected_result): @pytest.mark.parametrize( - "section_key", - [ - "section_is_not_present", - "test_section.but_key_is_not_present", - ], + "section_key", ["section_is_not_present", "test_section.but_key_is_not_present"], ) def test_that_ini_parser_delete_raises_value_errors(section_key): ini_file = """[test_section]\nkey1 = value\n\n""" @@ -91,11 +79,7 @@ def test_that_ini_parser_delete_raises_value_errors(section_key): @pytest.mark.parametrize( - "section_key", - [ - "test_section", - "test_section.key1", - ], + "section_key", ["test_section", "test_section.key1"], ) def test_that_ini_parser_can_check_its_section_and_keys(section_key): ini_file = """[test_section]\nkey1 = value\n\n""" |