aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_ini_parser.py
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2020-08-07 20:25:00 -0500
committerGitHub <noreply@github.com>2020-08-07 20:25:00 -0500
commit05dba35cab34c2524b945da0164327b7b8a1159d (patch)
treee1f263a316839c0d32a413c120a3c92426f36817 /tests/test_ini_parser.py
parentCreate python-package-ci.yml (diff)
parentFix ConfigFile default (diff)
downloadconfig-file-05dba35cab34c2524b945da0164327b7b8a1159d.zip
Merge pull request #24 from eugenetriguba/dev
v0.11.0
Diffstat (limited to 'tests/test_ini_parser.py')
-rw-r--r--tests/test_ini_parser.py106
1 files changed, 0 insertions, 106 deletions
diff --git a/tests/test_ini_parser.py b/tests/test_ini_parser.py
deleted file mode 100644
index 7cdeea8..0000000
--- a/tests/test_ini_parser.py
+++ /dev/null
@@ -1,106 +0,0 @@
-import pytest
-
-from config_file.parsers.ini_parser import IniParser, ParsingError
-
-
-@pytest.mark.parametrize("ini_file", ["blahblahblah", "{ 'key1': 5 }"])
-def test_incorrect_ini_formats(ini_file):
- with pytest.raises(ParsingError):
- IniParser(ini_file)
-
-
-@pytest.mark.parametrize(
- "section_key,expected_value,parse_type",
- [
- ("test_section.intkey", 5, True),
- ("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),
- ("test_section.floatkey", "5.3", False),
- (
- "test_section",
- {"intkey": "5", "strkey": "blah", "boolkey": "false", "floatkey": "5.3"},
- False,
- ),
- (
- "test_section",
- {"intkey": 5, "strkey": "blah", "boolkey": False, "floatkey": 5.3},
- True,
- ),
- ],
-)
-def test_that_ini_parser_can_get_values(section_key, expected_value, parse_type):
- ini_file = """[test_section]
-intkey = 5
-strkey = blah
-boolkey = false
-floatkey = 5.3
-
-"""
- parser = IniParser(ini_file)
- assert parser.get(section_key, parse_types=parse_type) == expected_value
-
-
-@pytest.mark.parametrize(
- "test_input", ["invalid.invalid_key"],
-)
-def test_that_getting_unknown_sections_or_keys_throws_errors(test_input):
- with pytest.raises(ParsingError):
- IniParser("").get(test_input)
-
-
-@pytest.mark.parametrize(
- "section_key,value,expected_value",
- [
- ("test.key1", "different value", "[test]\nkey1 = different value\n\n"),
- ("test.key2", 5, "[test]\nkey1 = value1\nkey2 = 5\n\n"),
- ("test2.key", False, "[test]\nkey1 = value1\n\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"""
- parser = IniParser(ini_file)
- parser.set(section_key, value)
- assert parser.stringify() == expected_value
-
-
-@pytest.mark.parametrize(
- "ini_file",
- ["[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)
- assert parser.stringify() == ini_file
-
-
-@pytest.mark.parametrize(
- "section_key,expected_result",
- [("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"""
- parser = IniParser(ini_file)
- parser.delete(section_key)
- assert parser.stringify() == expected_result
-
-
-@pytest.mark.parametrize(
- "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"""
- parser = IniParser(ini_file)
- with pytest.raises(ValueError):
- parser.delete(section_key)
-
-
-@pytest.mark.parametrize(
- "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"""
- parser = IniParser(ini_file)
- assert parser.has(section_key)