updating tests

This commit is contained in:
2021-10-23 21:08:16 +01:00
parent 485ab9ef09
commit 1af790f01a
4 changed files with 39 additions and 4 deletions

View File

@@ -40,7 +40,6 @@ class Config:
Examples:
`config_path` defaults to None on initialisation but will be set to `~/.config`.
Example:
A header of `data_analysis` with a config_path of `~/myapps` will define
a config file in `~/myapps/data_analysis/config.yml`.
"""

View File

@@ -0,0 +1,9 @@
panaetius_testing:
some_top_string: some_top_value
second:
some_second_string: some_second_value
some_second_int: 1
some_second_float: 1.0
some_second_list: ["some", "second", "value"]
some_second_table: { "first": ["some", "first", "value"] }
some_second_table_bools: { "bool": [true, false] }

View File

@@ -29,6 +29,17 @@ def test_user_config_path_set(header, shared_datadir):
assert str(config.config_path) == config_path
def test_user_config_path_without_header_dir_set(header, shared_datadir):
# arrange
config_path = str(shared_datadir / "without_header")
# act
config = panaetius.Config(header, config_path, skip_header_init=True)
# assert
assert str(config.config_path) == config_path
# test config files
@@ -44,6 +55,18 @@ def test_config_file_exists(header, shared_datadir):
assert config._missing_config is False
def test_config_file_without_header_dir_exists(header, shared_datadir):
# arrange
config_path = str(shared_datadir / "without_header")
# act
config = panaetius.Config(header, config_path, skip_header_init=True)
_ = config.config
# assert
assert config._missing_config is False
def test_config_file_contents_read_success(
header, shared_datadir, testing_config_contents
):
@@ -106,7 +129,7 @@ def test_get_value_from_key(
def test_get_value_environment_var_override(header, shared_datadir):
# arrange
os.environ[f"{header.upper()}_SOME_TOP_STRING"] = '"some_overridden_value"'
os.environ[f"{header.upper()}_SOME_TOP_STRING"] = "some_overridden_value"
config_path = str(shared_datadir / "without_logging")
config = panaetius.Config(header, config_path)
panaetius.set_config(config, "some_top_string")
@@ -158,7 +181,7 @@ def test_get_value_missing_key_from_default(header, shared_datadir):
def test_get_value_missing_key_from_env(header, shared_datadir):
# arrange
os.environ[f"{header.upper()}_MISSING_KEY"] = '"some missing key"'
os.environ[f"{header.upper()}_MISSING_KEY"] = "some missing key"
config_path = str(shared_datadir / "without_logging")
config = panaetius.Config(header, config_path)
@@ -205,7 +228,7 @@ def test_missing_config_read_from_default(header, shared_datadir):
@pytest.mark.parametrize(
"env_value,expected_value",
[
('"a missing string"', "a missing string"),
("a missing string", "a missing string"),
("1", 1),
("1.0", 1.0),
("True", True),
@@ -237,6 +260,7 @@ def test_missing_config_read_from_env_var(
del os.environ[f"{header.upper()}_MISSING_KEY_READ_FROM_ENV_VAR"]
@pytest.mark.skip(reason="No longer needed as strings are loaded without quotes")
def test_missing_config_read_from_env_var_invalid_python(header):
# arrange
os.environ[f"{header.upper()}_INVALID_PYTHON"] = "a string without quotes"

View File

@@ -21,6 +21,7 @@ def test_logging_directory_does_not_exist(header, shared_datadir):
assert str(logging_exception.value) == ""
# TODO: change this test so it asserts the dir exists
def test_logging_directory_does_exist(header, shared_datadir):
# arrange
config = Config(header)
@@ -32,3 +33,5 @@ def test_logging_directory_does_exist(header, shared_datadir):
# assert
assert isinstance(logger, logging.Logger)
# TODO: add tests to check that SimpleLogger, AdvancedLogger, CustomLogger work as intended