mirror of
https://github.com/dtomlinson91/panaetius.git
synced 2025-12-22 04:55:44 +00:00
adding initial tests
This commit is contained in:
@@ -1 +0,0 @@
|
||||
__header__ = 'panaetius_test'
|
||||
6
tests/conftest.py
Normal file
6
tests/conftest.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def header():
|
||||
return "panaetius_testing"
|
||||
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
|
||||
from panaetius import Config, set_config
|
||||
from panaetius import Config, set_config, set_logger, SimpleLogger
|
||||
# from panaetius.logging import AdvancedLogger
|
||||
|
||||
if __name__ == "__main__":
|
||||
os.environ["PANAETIUS_TEST_PATH"] = "/usr/local"
|
||||
@@ -17,17 +18,17 @@ if __name__ == "__main__":
|
||||
os.environ["PANAETIUS_TEST_NOC_EMBEDDED_FLOAT"] = "2.0"
|
||||
os.environ["PANAETIUS_TEST_NOC_EMBEDDED_BOOL"] = "true"
|
||||
|
||||
c = Config("panaetius_test")
|
||||
# c = Config("panaetius_test_noc")
|
||||
# c = Config("panaetius_test")
|
||||
c = Config("panaetius_test_noc")
|
||||
|
||||
set_config(c, key="toml.points", coerce=True)
|
||||
set_config(c, key="path", default="some path")
|
||||
set_config(c, key="top", default="some top")
|
||||
set_config(c, key="logging.path", default="some logging path")
|
||||
set_config(c, key="logging.path")
|
||||
set_config(c, key="nonexistent.item", default="some nonexistent item")
|
||||
set_config(c, key="nonexistent.item")
|
||||
set_config(c, key="toml.points_config")
|
||||
set_config(c, key="float", default=2.0)
|
||||
set_config(c, key="float", coerce=True)
|
||||
set_config(c, key="float_str", default="2.0")
|
||||
set_config(c, key="bool", coerce=True)
|
||||
set_config(c, key="noexistbool", default=False)
|
||||
@@ -47,5 +48,7 @@ if __name__ == "__main__":
|
||||
set_config(c, key="embedded.noexistfloat", default=2.0)
|
||||
set_config(c, key="embedded.noexistbool", default=False)
|
||||
|
||||
print(c)
|
||||
pass
|
||||
logger = set_logger(c, SimpleLogger())
|
||||
# logger = set_logger(c, AdvancedLogger(logging_level="INFO"))
|
||||
logger.info("test logging message")
|
||||
logger.debug("debugging message")
|
||||
@@ -1,33 +0,0 @@
|
||||
import panaetius
|
||||
|
||||
# from panaetius import CONFIG as CONFIG
|
||||
# from panaetius import logger as logger
|
||||
|
||||
print(panaetius.__header__)
|
||||
|
||||
panaetius.set_config(panaetius.CONFIG, 'logging.level')
|
||||
|
||||
# print(panaetius.CONFIG.logging_format)
|
||||
print(panaetius.CONFIG.logging_path)
|
||||
print(panaetius.config_inst.CONFIG_PATH)
|
||||
|
||||
# panaetius.logger.info('test event')
|
||||
|
||||
|
||||
panaetius.logger.info('setting foo.bar value')
|
||||
panaetius.set_config(panaetius.CONFIG, 'foo.bar', mask=True)
|
||||
|
||||
panaetius.logger.info(f'foo.bar set to {panaetius.CONFIG.foo_bar}')
|
||||
|
||||
# print((panaetius.CONFIG.path))
|
||||
# print(panaetius.CONFIG.logging_level)
|
||||
|
||||
panaetius.set_config(panaetius.CONFIG, 'test', mask=True)
|
||||
panaetius.logger.info(f'test_root={panaetius.CONFIG.test}')
|
||||
|
||||
print(panaetius.CONFIG.config_file)
|
||||
|
||||
# for i in panaetius.CONFIG.deferred_messages:
|
||||
# panaetius.logger.debug(i)
|
||||
|
||||
panaetius.logger.info('some logging message')
|
||||
36
tests/test_config.py
Normal file
36
tests/test_config.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import pathlib
|
||||
|
||||
import toml
|
||||
|
||||
import panaetius
|
||||
|
||||
|
||||
def test_default_config_path_set(header):
|
||||
# act
|
||||
config = panaetius.Config(header)
|
||||
|
||||
# assert
|
||||
assert str(config.config_path) == str(pathlib.Path.home() / ".config")
|
||||
|
||||
|
||||
def test_user_config_path_set(header, datadir):
|
||||
# arrange
|
||||
config_path = str(datadir / "without_logging")
|
||||
|
||||
# act
|
||||
config = panaetius.Config(header, config_path)
|
||||
|
||||
# assert
|
||||
assert str(config.config_path) == config_path
|
||||
|
||||
|
||||
def test_config_file_exists(header, datadir):
|
||||
# arrange
|
||||
config_path = str(datadir / "without_logging")
|
||||
|
||||
# act
|
||||
config = panaetius.Config(header, config_path)
|
||||
config_contents = config.config
|
||||
|
||||
# assert
|
||||
assert config._missing_config == False
|
||||
@@ -0,0 +1,12 @@
|
||||
[panaetius_testing]
|
||||
some_top_string = "some_top_value"
|
||||
|
||||
[panaetius_testing.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"] }
|
||||
|
||||
# [panaetius_testing.logging]
|
||||
# path = ""
|
||||
Reference in New Issue
Block a user