Skip to content

Commit 717631c

Browse files
Re-writing the whole core. Supporting multiple files extensions
1 parent 6badb9f commit 717631c

10 files changed

Lines changed: 61 additions & 51 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea/
2+
python_json_config_parser.egg-info/

config/config.bad_extension

Whitespace-only changes.
File renamed without changes.

config/schema_config_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
SIMPLE_SCHEMA_CONFIG = {
2+
'core': {
3+
'logging': {
4+
'format': str,
5+
'datefmt': str
6+
},
7+
'obj_list': [{'name': str, 'age': int}]
8+
}
9+
}

configparser.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ def __get_file_path(cls, config_dir, file_name):
7878
@classmethod
7979
def __check_schema(cls, schema):
8080
if schema is None:
81-
raise ConfigError('The schema config can not be None')
81+
raise ConfigInvalidSchemaError('The schema config can not be None')
8282
if type(schema) is not dict:
83-
raise ConfigError('The first config\'s schema element should be a Map')
83+
raise ConfigInvalidSchemaError('The first config\'s schema element should be a Map')
8484

8585
@classmethod
8686
def __get_file_buff(cls, path_file: str):
@@ -124,6 +124,10 @@ class ConfigSchemaModelError(ConfigError):
124124
pass
125125

126126

127+
class ConfigInvalidSchemaError(ConfigError):
128+
pass
129+
130+
127131
class ConfigFileOpenReadError(ConfigError):
128132
pass
129133

schema_config_test.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

setup.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import setuptools
22

3-
with open("README.md", "r") as fh:
3+
with open('README.md', 'r') as fh:
44
long_description = fh.read()
55

66
setuptools.setup(
7-
name="python-json-config-parser",
8-
version="1.0.9",
9-
author="Bruno Silva de Andrade",
10-
author_email="brunojf.andrade@gmail.com",
11-
description="Project created to given the possibility of create dynamics Json config files",
12-
license="MIT",
7+
name='python-config-parser',
8+
version='2.0.0',
9+
author='Bruno Silva de Andrade',
10+
author_email='brunojf.andrade@gmail.com',
11+
description='Project created to given the possibility of create dynamics config files',
12+
license='MIT',
1313
long_description=long_description,
14-
long_description_content_type="text/markdown",
15-
url="https://github.com/BrunoSilvaAndrade/python-json-config-parser",
16-
py_modules=["jsonconfigparser"],
17-
install_requires=open("requirements.txt", "r").read().split("\n"),
14+
long_description_content_type='text/markdown',
15+
url='https://github.com/BrunoSilvaAndrade/python-config-parser',
16+
py_modules=['configparser'],
17+
install_requires=open('requirements.txt', 'r').read().split('\n'),
1818
classifiers=[
19-
"Programming Language :: Python :: 3",
20-
"License :: OSI Approved :: MIT License",
21-
"Operating System :: OS Independent",
19+
'Programming Language :: Python :: 3',
20+
'License :: OSI Approved :: MIT License',
21+
'Operating System :: OS Independent',
2222
]
2323
)

test_configparser.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import unittest
2+
from configparser import *
3+
from config.schema_config_test import SIMPLE_SCHEMA_CONFIG
4+
5+
6+
class ConfigTestCase(unittest.TestCase):
7+
8+
def test_config_without_file(self):
9+
self.assertRaises(ConfigFileNotFoundError, Config, SIMPLE_SCHEMA_CONFIG, 'config', 'some_non_exists_file.json')
10+
11+
def test_config_with_wrong_json_model(self):
12+
self.assertRaises(ConfigFileModelError, Config, SIMPLE_SCHEMA_CONFIG, 'config', 'wrong_model.json')
13+
14+
def test_config_file_with_unsupported_extension(self):
15+
self.assertRaises(ConfigFileExtensionNotSupportedError, Config, SIMPLE_SCHEMA_CONFIG, 'config', 'config.bad_extension')
16+
17+
def test_to_access_attr_from_config(self):
18+
config = Config(SIMPLE_SCHEMA_CONFIG)
19+
self.assertEqual(config.core.logging.format, 'format')
20+
self.assertEqual(config.core.logging.datefmt, 'datefmt')
21+
self.assertEqual(config.core.obj_list[0].name, 'bruno')
22+
self.assertEqual(config.core.obj_list[0].age, 24)
23+
24+
def test_access_fake_attr(self):
25+
config = Config(SIMPLE_SCHEMA_CONFIG)
26+
self.assertRaises(AttributeError, lambda: config.fake_attr)
27+
28+
29+
if __name__ == '__main__':
30+
unittest.main()

test_jsonconfigparser.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)