slight rework cfg module, moving file validation and logic into setters. slight improvement on logging and tests

This commit is contained in:
Mathew Guest
2020-07-18 23:02:44 -06:00
parent 64ee90066d
commit 4e083d6a3d
14 changed files with 352 additions and 173 deletions
+18
View File
@@ -0,0 +1,18 @@
Software tests for app_skellington
==================================
Contained is the early stages of unit testing for app_skellington framework.
Usage
-----
Run all tests (cwd is testing directory):
pytest .
Run test by keyword:
pytest -k "<test keyword>" .
Run test by directory:
pytest <dirname>
View File
+5
View File
@@ -0,0 +1,5 @@
root_option = root_option_val
[app]
sub_option = sub_option_val
+5
View File
@@ -0,0 +1,5 @@
root_option = string(max=255, default='def_string')
[app]
sub_option = string(max=255, default='def_sub')
+5
View File
@@ -0,0 +1,5 @@
root_option = root_option_val
[app]
sub_option = sub_option_val
+6
View File
@@ -0,0 +1,6 @@
root_option = string(max=255, default='def_string')
int_option = integer(min=0, max=100)
[app]
sub_option = string(max=255, default='def_sub')
+2
View File
@@ -0,0 +1,2 @@
root_option = invalid(max=255, default='def_string')
+97
View File
@@ -0,0 +1,97 @@
from app_skellington.cfg import Config
from app_skellington import _util
import pytest
@pytest.fixture
def sample_configspec_filepath():
return _util.get_asset(__name__, 'sample_config.spec')
@pytest.fixture
def sample_configini_filepath():
return _util.get_asset(__name__, 'sample_config.ini')
@pytest.fixture
def sample_full_configspec_filepath():
return _util.get_asset(__name__, 'sample_config_full.spec')
@pytest.fixture
def sample_full_configini_filepath():
return _util.get_asset(__name__, 'sample_config_full.ini')
@pytest.fixture
def sample_invalid_configspec_filepath():
return _util.get_asset(__name__, 'sample_config_invalid.spec')
class TestConfig_e2e:
def test_allows_reading_ini_and_no_spec(
self, sample_configini_filepath
):
cfg = Config(
configini_filepath=sample_configini_filepath
)
assert cfg['root_option'] == 'root_option_val', 'expecting default from config.spec (didnt get)'
assert cfg['app']['sub_option'] == 'sub_option_val', 'expecting default for sub option'
def test_allows_reading_spec_and_no_ini(
self, sample_configspec_filepath
):
cfg = Config(
configspec_filepath=sample_configspec_filepath
)
assert cfg['root_option'] == 'def_string', 'expecting default from config.spec (didnt get)'
# NOTE(MG) Changed the functionality to not do it this way.
# def test_constructor_fails_with_invalid_spec(
# self, sample_invalid_configspec_filepath
# ):
# with pytest.raises(Exception):
# cfg = Config(
# configspec_filepath=sample_invalid_configspec_filepath
# )
def test_allows_options_beyond_spec(
self, sample_configspec_filepath
):
cfg = Config(
configspec_filepath=sample_configspec_filepath
)
cfg['foo'] = 'test my value'
assert cfg['foo'] == 'test my value'
cfg['app']['bar'] = 'another value'
assert cfg['app']['bar'] == 'another value'
# def test_can_read_config_file_mutiple_times(self):
# pass
def test_can_override_config_file_manually(
self, sample_configini_filepath
):
cfg = Config(
configini_filepath=sample_configini_filepath
)
cfg['root_option'] = 'newval'
assert cfg['root_option'] == 'newval'
cfg['app']['sub_option'] = 'another_new_val'
assert cfg['app']['sub_option'] == 'another_new_val', 'expecting default for sub option'
def test_can_set_option_without_config(self):
cfg = Config()
cfg['foo'] = 'test my value'
assert cfg['foo'] == 'test my value'
cfg['app'] = {}
cfg['app']['bar'] = 'another value'
assert cfg['app']['bar'] == 'another value'
def test_uses_spec_as_defaults(
self, sample_configspec_filepath
):
cfg = Config(
configspec_filepath=sample_configspec_filepath
)
assert cfg['root_option'] == 'def_string', 'expecting default from config.spec (didnt get)'
assert cfg['app']['sub_option'] == 'def_sub', 'expecting default for sub option'
-31
View File
@@ -1,31 +0,0 @@
from app_skellington.cfg import Config
class TestConfig_e2e:
def test_allows_reading_with_no_spec(self):
x = Config()
assert True == False
def test_allows_reading_with_sample_spec(self):
x = Config()
assert True == False
def test_constructor_fails_with_invalid_spec(self):
x = Config()
assert True == False
def test_allows_options_beyond_spec(self):
x = Config()
assert True == False
def test_can_read_config_correctly_from_file(self):
pass
def test_can_read_config_file_mutiple_times(self):
pass
def test_can_override_config_file_manually(self):
pass
def test_can_set_option_without_config(self):
pass