diff options
| author | Eugene Triguba <eugenetriguba@gmail.com> | 2020-08-06 19:03:53 -0500 |
|---|---|---|
| committer | Eugene Triguba <eugenetriguba@gmail.com> | 2020-08-06 19:03:53 -0500 |
| commit | 286cec0d1c05b6b85f49714ec4635d2e8dcacfc7 (patch) | |
| tree | 24c98af77823cbab22d3463ce01285a809527c1c /tests | |
| parent | Add test for Default util (diff) | |
| download | config-file-286cec0d1c05b6b85f49714ec4635d2e8dcacfc7.zip | |
Remove ini and json parser tests
They heavily overlap with the config_file
test case now and are unnecessary.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_ini_parser.py | 97 | ||||
| -rw-r--r-- | tests/test_json_parser.py | 109 |
2 files changed, 0 insertions, 206 deletions
diff --git a/tests/test_ini_parser.py b/tests/test_ini_parser.py deleted file mode 100644 index 2accc8f..0000000 --- a/tests/test_ini_parser.py +++ /dev/null @@ -1,97 +0,0 @@ -import pytest - -from config_file.exceptions import ParsingError -from config_file.ini_parser import IniParser - - -@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", - [ - ("test_section.intkey", "5"), - ("test_section.strkey", "blah"), - ("test_section.boolkey", "false"), - ("test_section.floatkey", "5.3"), - ( - "test_section", - {"intkey": "5", "strkey": "blah", "boolkey": "false", "floatkey": "5.3"}, - ), - ], -) -def test_that_ini_parser_can_get_values(section_key, expected_value): - ini_file = """[test_section] -intkey = 5 -strkey = blah -boolkey = false -floatkey = 5.3 - -""" - parser = IniParser(ini_file) - assert parser.get(section_key) == 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(KeyError): - 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_key_error(section_key): - ini_file = """[test_section]\nkey1 = value\n\n""" - parser = IniParser(ini_file) - with pytest.raises(KeyError): - 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) diff --git a/tests/test_json_parser.py b/tests/test_json_parser.py deleted file mode 100644 index 54ea646..0000000 --- a/tests/test_json_parser.py +++ /dev/null @@ -1,109 +0,0 @@ -import pytest - -from config_file.exceptions import ParsingError - - -def test_invalid_json(templated_parser): - with pytest.raises(ParsingError): - templated_parser("json", "invalid") - - -def test_that_json_parser_can_stringify(template_and_parser): - template, parser = template_and_parser("json") - - assert parser.stringify() == template.read_text() - - -@pytest.mark.parametrize( - "key", - [ - "glossary", - "title", - "GlossDiv", - "title", - "GlossList", - "GlossEntry", - "ID", - "GlossTerm", - "Acronym", - "GlossDef", - "para", - "GlossSeeAlso", - "GlossSee", - ], -) -def test_that_json_parser_can_find_wild_keys(key, templated_parser): - parser = templated_parser("json", "glossary") - assert parser.has(key, wild=True) - - -@pytest.mark.parametrize( - "key", - [ - "glossary", - "glossary.title", - "glossary.GlossDiv.GlossList.GlossEntry.GlossDef.para", - ], -) -def test_that_json_parser_can_find_dot_keys(key, templated_parser): - parser = templated_parser("json", "glossary") - assert parser.has(key) - - -@pytest.mark.parametrize( - "value", - [ - "str_value", - "5", - "false", - "Standard Generalized Markup Language", - "ISO 8879:1986", - "A meta-markup language, used to create markup languages such as DocBook.", - "GML", - "XML", - "5.5", - ], -) -def test_that_json_parser_does_not_find_values(value, templated_parser): - parser = templated_parser("json", "glossary") - assert not parser.has(value) - - -@pytest.mark.parametrize( - "key, value", - [ - ("glossary.title", "str_value"), - ("glossary.dict", {"key": "str_value", "str_number": "5"}), - ], -) -def test_that_json_parser_can_get_keys_without_parsing_types( - templated_parser, key, value -): - parser = templated_parser("json", "glossary") - assert parser.get(key) == value - - -@pytest.mark.parametrize( - "key, value", [("zip", "zipzip"), ("foo.bar.foobar", "5"), ("foo.baz", "bar")] -) -def test_that_json_parser_can_set_keys(templated_parser, key, value): - parser = templated_parser("json") - - parser.set(key, value) - assert parser.get(key) == value - - -@pytest.mark.parametrize( - "key", - [ - "glossary", - "glossary.dict_within_dict", - "glossary.GlossDiv.GlossList.GlossEntry.Abbrev", - ], -) -def test_that_json_parser_can_delete_keys(template_and_parser, key): - template, parser = template_and_parser("json", "glossary") - - parser.delete(key) - - assert parser.has(key) is False |