def test_parser__parse_file_per_type_ini(self): parser = ParseIt(config_folder_location=test_files_location) reply = parser._parse_file_per_type("ini", test_files_location + "/test.ini") expected_reply = { 'DEFAULT': { 'file_type': 'ini', 'test_string': 'testing', 'test_bool_true': 'true', 'test_bool_false': 'false', 'test_int': '123.0', 'test_float': '123.123', 'test_list': '["test1", "test2", "test3"]' }, 'test_ini': { 'test_ini_key': 'test_ini_value' } } self.assertEqual(reply, expected_reply) reply = parser._parse_file_per_type("conf", test_files_location + "/test.ini") self.assertEqual(reply, expected_reply) reply = parser._parse_file_per_type("cfg", test_files_location + "/test.ini") self.assertEqual(reply, expected_reply)
def test_parser__parse_file_per_type_toml(self): parser = ParseIt(config_folder_location=test_files_location) reply = parser._parse_file_per_type("toml", test_files_location + "/test.toml") expected_reply = { 'file_type': 'toml', 'test_string': 'testing', 'test_bool_true': True, 'test_bool_false': False, 'test_int': 123, 'test_float': 123.123, 'test_list': ['test1', 'test2', 'test3'], 'test_toml': { 'test_toml_key': 'test_toml_value' } } self.assertEqual(reply, expected_reply) reply = parser._parse_file_per_type("tml", test_files_location + "/test.toml") self.assertEqual(reply, expected_reply)
def test_parser__parse_file_per_type_custom_yaml(self): parser = ParseIt(config_folder_location=test_files_location, custom_suffix_mapping={"yaml": ["custom"]}, config_type_priority=["custom"] + VALID_FILE_TYPE_EXTENSIONS) reply = parser._parse_file_per_type( "custom", test_files_location + "/test.custom") expected_reply = { 'file_type': 'custom_yaml_suffix', 'test_string': 'testing_custom', 'test_bool_true': True, 'test_bool_false': False, 'test_int': 123, 'test_float': 123.123, 'test_list': ['test1', 'test2', 'test3'], 'test_yaml': { 'test_yaml_key': 'custom_test_yaml_value' } } self.assertEqual(reply, expected_reply)
def test_parser__parse_file_per_type_xml(self): parser = ParseIt(config_folder_location=test_files_location) reply = parser._parse_file_per_type("xml", test_files_location + "/test.xml") expected_reply = { 'xml_root': { 'file_type': 'xml', 'test_bool_false': 'false', 'test_bool_true': 'true', 'test_float': '123.123', 'test_int': '123', 'test_xml': { 'test_xml_key': 'test_xml_value' }, 'test_list': { 'element': ['test1', 'test2', 'test3'] }, 'test_string': 'testing' } } self.assertEqual(reply, expected_reply)
def test_parser__parse_file_per_type_wrong_type(self): parser = ParseIt(config_folder_location=test_files_location) with self.assertRaises(ValueError): parser._parse_file_per_type("non_existing_type", test_files_location + "/test.json")