[517] Set Logging Handler and Remove Old Tests

This commit is contained in:
David Sangrey committed 2025-11-16 21:46:36 -05:00
1 parent fa0ec91b8f
commit 16212e154b
2 files changed
+1 -99

No files matched your search

+1 -1
View File
@@ -537,7 +537,7 @@ def get_config(*args, **kwargs) -> Config:
config_logger = logging.getLogger("pre_config")
config_logger.setLevel(logging.DEBUG) # Or INFO
ch = logging.StreamHandler()
ch = logging.StreamHandler(sys.stdout)
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(asctime)s [%(levelname)s] %(message)s")
formatter.converter = gmtime # Optional: match your main logger's UTC timestamps
-98
View File
@@ -7,7 +7,6 @@ key deletions. Said modifications are to keys that are generated internally.
Most of these tests are parity tests with the "old" config, and likely one day can be
entirely removed.
"""
import contextlib
import itertools
import pathlib
import random
@@ -23,8 +22,6 @@ from pytest import mark
sys.path += [str(pathlib.Path(__file__).parent.parent.resolve()), "."]
print(sys.path)
from _old_config import old_config # noqa: E402
from config import config # noqa: E402
@@ -148,98 +145,3 @@ class TestNewConfig:
assert res == '1337'
config.delete(name)
config.save()
class TestOldNewConfig:
"""Tests going through the old config and out the new config."""
KEY_PREFIX = 'oldnew_'
def teardown_method(self) -> None:
"""
Teardown for all config tests to save out configs.
It is expected that tests have cleaned up whatever keys they have aded.
This is here to ensure that a save out happens for configs that need it.
"""
old_config.save()
config.save()
def cleanup_entry(self, entry: str) -> None:
"""Remove the given key, on both sides if on linux."""
config.delete(entry)
if sys.platform == 'linux':
old_config.delete(entry)
def __update_linuxconfig(self) -> None:
"""On linux config uses ConfigParser, which doesn't update from disk changes. Force the update here."""
if sys.platform != 'linux':
return
from config.linux import LinuxConfig # type: ignore
if isinstance(config, LinuxConfig) and config.config is not None:
config.config.read(config.filename)
@mark.parametrize("i", _build_test_list(int_tests, _get_fuzz(int, 50, (-big_int, big_int))))
def test_int(self, i: int) -> None:
"""Save an int though the old config, recall it using the new config."""
if sys.platform == 'win32':
i = abs(i)
name = self.KEY_PREFIX + f'int_{i}'
old_config.set(name, i)
old_config.save()
self.__update_linuxconfig()
res = config.get_int(name)
with contextlib.ExitStack() as stack:
stack.callback(self.cleanup_entry, name)
assert res == i
@mark.parametrize("string", _build_test_list(string_tests, _get_fuzz(str, value_length=(0, 512))))
def test_string(self, string: str) -> None:
"""Save a string though the old config, recall it using the new config."""
string = string.replace("\r", "") # The old config does _not_ support \r in its entries. We do.
name = self.KEY_PREFIX + f'string_{hash(string)}'
old_config.set(name, string)
old_config.save()
self.__update_linuxconfig()
res = config.get_str(name)
with contextlib.ExitStack() as stack:
stack.callback(self.cleanup_entry, name)
assert res == string
@mark.parametrize("lst", _build_test_list(list_tests, _get_fuzz(list)))
def test_list(self, lst: list[str]) -> None:
"""Save a list though the old config, recall it using the new config."""
lst = [x.replace("\r", "") for x in lst] # OldConfig on linux fails to store these correctly
if sys.platform == 'win32':
# old conf on windows replaces empty entries with spaces as a workaround for a bug. New conf does not
# So insert those spaces here, to ensure that it works otherwise.
lst = [e if len(e) > 0 else ' ' for e in lst]
name = self.KEY_PREFIX + f'list_test_{hash("".join(lst))}'
old_config.set(name, lst)
old_config.save()
self.__update_linuxconfig()
res = config.get_list(name)
with contextlib.ExitStack() as stack:
stack.callback(self.cleanup_entry, name)
assert res == lst
@mark.skipif(sys.platform == 'win32', reason="Old Windows config does not support bool types")
@mark.parametrize("b", bool_tests)
def test_bool(self, b: bool) -> None:
"""Save a bool though the old config, recall it using the new config."""
name = str(b)
old_config.set(name, b)
old_config.save()
self.__update_linuxconfig()
with contextlib.ExitStack() as stack:
stack.callback(self.cleanup_entry, name)
assert config.get_bool(name) == b