Bugfixes in unittests
This commit is contained in:
parent
7d4efe7bda
commit
e76b293f60
@ -10,10 +10,6 @@ class ConfigurationBase(ABC):
|
|||||||
@abstractmethod
|
@abstractmethod
|
||||||
def __init__(self): pass
|
def __init__(self): pass
|
||||||
|
|
||||||
@property
|
|
||||||
@abstractmethod
|
|
||||||
def config(self) -> dict[type, object]: pass
|
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def add_config_by_type(self, key_type: type, value: object): pass
|
def add_config_by_type(self, key_type: type, value: object): pass
|
||||||
|
|
||||||
|
@ -11,10 +11,6 @@ class Configuration(ConfigurationBase):
|
|||||||
|
|
||||||
self._config: dict[type, object] = {}
|
self._config: dict[type, object] = {}
|
||||||
|
|
||||||
@property
|
|
||||||
def config(self):
|
|
||||||
return self._config
|
|
||||||
|
|
||||||
def create(self): pass
|
def create(self): pass
|
||||||
|
|
||||||
def add_config_by_type(self, key_type: type, value: object):
|
def add_config_by_type(self, key_type: type, value: object):
|
||||||
|
@ -3,6 +3,7 @@ from datetime import datetime
|
|||||||
|
|
||||||
from sh_edraft.configuration.configuration import Configuration
|
from sh_edraft.configuration.configuration import Configuration
|
||||||
from sh_edraft.configuration.base.configuration_base import ConfigurationBase
|
from sh_edraft.configuration.base.configuration_base import ConfigurationBase
|
||||||
|
from sh_edraft.hosting.base.application_runtime_base import ApplicationRuntimeBase
|
||||||
from sh_edraft.hosting.base.environment_base import EnvironmentBase
|
from sh_edraft.hosting.base.environment_base import EnvironmentBase
|
||||||
from sh_edraft.hosting.hosting_environment import HostingEnvironment
|
from sh_edraft.hosting.hosting_environment import HostingEnvironment
|
||||||
from sh_edraft.hosting.application_runtime import ApplicationRuntime
|
from sh_edraft.hosting.application_runtime import ApplicationRuntime
|
||||||
@ -30,13 +31,17 @@ class ApplicationHost(ApplicationHostBase):
|
|||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def configuration(self) -> ConfigurationBase:
|
||||||
|
return self._config
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def environment(self) -> EnvironmentBase:
|
def environment(self) -> EnvironmentBase:
|
||||||
return self._environment
|
return self._environment
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def configuration(self) -> ConfigurationBase:
|
def application_runtime(self) -> ApplicationRuntimeBase:
|
||||||
return self._config
|
return self._app_runtime
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def services(self) -> ServiceProviderBase:
|
def services(self) -> ServiceProviderBase:
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
|
|
||||||
from sh_edraft.configuration.base.configuration_base import ConfigurationBase
|
from sh_edraft.configuration.base.configuration_base import ConfigurationBase
|
||||||
|
from sh_edraft.hosting.base.application_runtime_base import ApplicationRuntimeBase
|
||||||
from sh_edraft.hosting.base.environment_base import EnvironmentBase
|
from sh_edraft.hosting.base.environment_base import EnvironmentBase
|
||||||
from sh_edraft.service.base.service_provider_base import ServiceProviderBase
|
from sh_edraft.service.base.service_provider_base import ServiceProviderBase
|
||||||
|
|
||||||
@ -14,13 +15,17 @@ class ApplicationHostBase(ABC):
|
|||||||
@abstractmethod
|
@abstractmethod
|
||||||
def name(self) -> str: pass
|
def name(self) -> str: pass
|
||||||
|
|
||||||
|
@property
|
||||||
|
@abstractmethod
|
||||||
|
def configuration(self) -> ConfigurationBase: pass
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def environment(self) -> EnvironmentBase: pass
|
def environment(self) -> EnvironmentBase: pass
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def configuration(self) -> ConfigurationBase: pass
|
def application_runtime(self) -> ApplicationRuntimeBase: pass
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
|
@ -2,18 +2,24 @@ import os
|
|||||||
import shutil
|
import shutil
|
||||||
import unittest
|
import unittest
|
||||||
from string import Template
|
from string import Template
|
||||||
|
from typing import cast
|
||||||
|
|
||||||
from sh_edraft.hosting import ApplicationHost, HostingEnvironment
|
from sh_edraft.hosting import ApplicationHost
|
||||||
from sh_edraft.hosting.model import EnvironmentName
|
|
||||||
from sh_edraft.logging import Logger
|
from sh_edraft.logging import Logger
|
||||||
from sh_edraft.logging.model import LoggingSettings
|
from sh_edraft.logging.model import LoggingSettings
|
||||||
|
from sh_edraft.service import ServiceProvider
|
||||||
from sh_edraft.time.model import TimeFormatSettings
|
from sh_edraft.time.model import TimeFormatSettings
|
||||||
|
|
||||||
|
|
||||||
class LoggerTest(unittest.TestCase):
|
class LoggerTest(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self._app_host = ApplicationHost('CPL_Test', HostingEnvironment(EnvironmentName.testing, './'))
|
app_host = ApplicationHost('CPL_Test')
|
||||||
|
self._app_runtime = app_host.application_runtime
|
||||||
|
self._config = app_host.configuration
|
||||||
|
self._config.create()
|
||||||
|
self._services: ServiceProvider = cast(ServiceProvider, app_host.services)
|
||||||
|
self._services.create()
|
||||||
|
|
||||||
self._log_settings = LoggingSettings()
|
self._log_settings = LoggingSettings()
|
||||||
self._log_settings.from_dict({
|
self._log_settings.from_dict({
|
||||||
@ -41,25 +47,25 @@ class LoggerTest(unittest.TestCase):
|
|||||||
|
|
||||||
def test_create(self):
|
def test_create(self):
|
||||||
print(f'{__name__}.test_create:')
|
print(f'{__name__}.test_create:')
|
||||||
logger = Logger(self._log_settings, self._time_format_settings, self._app_host)
|
logger = Logger(self._log_settings, self._time_format_settings, self._app_runtime)
|
||||||
logger.create()
|
logger.create()
|
||||||
self.assertTrue(os.path.isdir(self._log_settings.path))
|
self.assertTrue(os.path.isdir(self._log_settings.path))
|
||||||
|
|
||||||
log_file = Template(self._log_settings.filename).substitute(
|
log_file = Template(self._log_settings.filename).substitute(
|
||||||
date_time_now=self._app_host.date_time_now.strftime(self._time_format_settings.date_time_format),
|
date_time_now=self._app_runtime.date_time_now.strftime(self._time_format_settings.date_time_format),
|
||||||
start_time=self._app_host.start_time.strftime(self._time_format_settings.date_time_log_format)
|
start_time=self._app_runtime.start_time.strftime(self._time_format_settings.date_time_log_format)
|
||||||
)
|
)
|
||||||
self.assertTrue(os.path.isfile(self._log_settings.path + log_file))
|
self.assertTrue(os.path.isfile(self._log_settings.path + log_file))
|
||||||
|
|
||||||
def test_header(self):
|
def test_header(self):
|
||||||
print(f'{__name__}.test_header:')
|
print(f'{__name__}.test_header:')
|
||||||
logger = Logger(self._log_settings, self._time_format_settings, self._app_host)
|
logger = Logger(self._log_settings, self._time_format_settings, self._app_runtime)
|
||||||
logger.create()
|
logger.create()
|
||||||
logger.header('HeaderTest:')
|
logger.header('HeaderTest:')
|
||||||
|
|
||||||
log_file = Template(self._log_settings.filename).substitute(
|
log_file = Template(self._log_settings.filename).substitute(
|
||||||
date_time_now=self._app_host.date_time_now.strftime(self._time_format_settings.date_time_format),
|
date_time_now=self._app_runtime.date_time_now.strftime(self._time_format_settings.date_time_format),
|
||||||
start_time=self._app_host.start_time.strftime(self._time_format_settings.date_time_log_format)
|
start_time=self._app_runtime.start_time.strftime(self._time_format_settings.date_time_log_format)
|
||||||
)
|
)
|
||||||
log_content = []
|
log_content = []
|
||||||
|
|
||||||
@ -75,13 +81,13 @@ class LoggerTest(unittest.TestCase):
|
|||||||
|
|
||||||
def test_trace(self):
|
def test_trace(self):
|
||||||
print(f'{__name__}.test_trace:')
|
print(f'{__name__}.test_trace:')
|
||||||
logger = Logger(self._log_settings, self._time_format_settings, self._app_host)
|
logger = Logger(self._log_settings, self._time_format_settings, self._app_runtime)
|
||||||
logger.create()
|
logger.create()
|
||||||
logger.trace(__name__, f'{__name__}.test_trace:')
|
logger.trace(__name__, f'{__name__}.test_trace:')
|
||||||
|
|
||||||
log_file = Template(self._log_settings.filename).substitute(
|
log_file = Template(self._log_settings.filename).substitute(
|
||||||
date_time_now=self._app_host.date_time_now.strftime(self._time_format_settings.date_time_format),
|
date_time_now=self._app_runtime.date_time_now.strftime(self._time_format_settings.date_time_format),
|
||||||
start_time=self._app_host.start_time.strftime(self._time_format_settings.date_time_log_format)
|
start_time=self._app_runtime.start_time.strftime(self._time_format_settings.date_time_log_format)
|
||||||
)
|
)
|
||||||
log_content = []
|
log_content = []
|
||||||
|
|
||||||
@ -97,13 +103,13 @@ class LoggerTest(unittest.TestCase):
|
|||||||
|
|
||||||
def test_debug(self):
|
def test_debug(self):
|
||||||
print(f'{__name__}.test_debug:')
|
print(f'{__name__}.test_debug:')
|
||||||
logger = Logger(self._log_settings, self._time_format_settings, self._app_host)
|
logger = Logger(self._log_settings, self._time_format_settings, self._app_runtime)
|
||||||
logger.create()
|
logger.create()
|
||||||
logger.debug(__name__, f'{__name__}.test_debug:')
|
logger.debug(__name__, f'{__name__}.test_debug:')
|
||||||
|
|
||||||
log_file = Template(self._log_settings.filename).substitute(
|
log_file = Template(self._log_settings.filename).substitute(
|
||||||
date_time_now=self._app_host.date_time_now.strftime(self._time_format_settings.date_time_format),
|
date_time_now=self._app_runtime.date_time_now.strftime(self._time_format_settings.date_time_format),
|
||||||
start_time=self._app_host.start_time.strftime(self._time_format_settings.date_time_log_format)
|
start_time=self._app_runtime.start_time.strftime(self._time_format_settings.date_time_log_format)
|
||||||
)
|
)
|
||||||
log_content = []
|
log_content = []
|
||||||
|
|
||||||
@ -119,13 +125,13 @@ class LoggerTest(unittest.TestCase):
|
|||||||
|
|
||||||
def test_info(self):
|
def test_info(self):
|
||||||
print(f'{__name__}.test_info:')
|
print(f'{__name__}.test_info:')
|
||||||
logger = Logger(self._log_settings, self._time_format_settings, self._app_host)
|
logger = Logger(self._log_settings, self._time_format_settings, self._app_runtime)
|
||||||
logger.create()
|
logger.create()
|
||||||
logger.info(__name__, f'{__name__}.test_info:')
|
logger.info(__name__, f'{__name__}.test_info:')
|
||||||
|
|
||||||
log_file = Template(self._log_settings.filename).substitute(
|
log_file = Template(self._log_settings.filename).substitute(
|
||||||
date_time_now=self._app_host.date_time_now.strftime(self._time_format_settings.date_time_format),
|
date_time_now=self._app_runtime.date_time_now.strftime(self._time_format_settings.date_time_format),
|
||||||
start_time=self._app_host.start_time.strftime(self._time_format_settings.date_time_log_format)
|
start_time=self._app_runtime.start_time.strftime(self._time_format_settings.date_time_log_format)
|
||||||
)
|
)
|
||||||
log_content = []
|
log_content = []
|
||||||
|
|
||||||
@ -141,13 +147,13 @@ class LoggerTest(unittest.TestCase):
|
|||||||
|
|
||||||
def test_warn(self):
|
def test_warn(self):
|
||||||
print(f'{__name__}.test_warn:')
|
print(f'{__name__}.test_warn:')
|
||||||
logger = Logger(self._log_settings, self._time_format_settings, self._app_host)
|
logger = Logger(self._log_settings, self._time_format_settings, self._app_runtime)
|
||||||
logger.create()
|
logger.create()
|
||||||
logger.warn(__name__, f'{__name__}.test_warn:')
|
logger.warn(__name__, f'{__name__}.test_warn:')
|
||||||
|
|
||||||
log_file = Template(self._log_settings.filename).substitute(
|
log_file = Template(self._log_settings.filename).substitute(
|
||||||
date_time_now=self._app_host.date_time_now.strftime(self._time_format_settings.date_time_format),
|
date_time_now=self._app_runtime.date_time_now.strftime(self._time_format_settings.date_time_format),
|
||||||
start_time=self._app_host.start_time.strftime(self._time_format_settings.date_time_log_format)
|
start_time=self._app_runtime.start_time.strftime(self._time_format_settings.date_time_log_format)
|
||||||
)
|
)
|
||||||
log_content = []
|
log_content = []
|
||||||
|
|
||||||
@ -163,13 +169,13 @@ class LoggerTest(unittest.TestCase):
|
|||||||
|
|
||||||
def test_error(self):
|
def test_error(self):
|
||||||
print(f'{__name__}.test_error:')
|
print(f'{__name__}.test_error:')
|
||||||
logger = Logger(self._log_settings, self._time_format_settings, self._app_host)
|
logger = Logger(self._log_settings, self._time_format_settings, self._app_runtime)
|
||||||
logger.create()
|
logger.create()
|
||||||
logger.error(__name__, f'{__name__}.test_error:')
|
logger.error(__name__, f'{__name__}.test_error:')
|
||||||
|
|
||||||
log_file = Template(self._log_settings.filename).substitute(
|
log_file = Template(self._log_settings.filename).substitute(
|
||||||
date_time_now=self._app_host.date_time_now.strftime(self._time_format_settings.date_time_format),
|
date_time_now=self._app_runtime.date_time_now.strftime(self._time_format_settings.date_time_format),
|
||||||
start_time=self._app_host.start_time.strftime(self._time_format_settings.date_time_log_format)
|
start_time=self._app_runtime.start_time.strftime(self._time_format_settings.date_time_log_format)
|
||||||
)
|
)
|
||||||
log_content = []
|
log_content = []
|
||||||
|
|
||||||
@ -185,14 +191,14 @@ class LoggerTest(unittest.TestCase):
|
|||||||
|
|
||||||
def test_fatal(self):
|
def test_fatal(self):
|
||||||
print(f'{__name__}.test_fatal:')
|
print(f'{__name__}.test_fatal:')
|
||||||
logger = Logger(self._log_settings, self._time_format_settings, self._app_host)
|
logger = Logger(self._log_settings, self._time_format_settings, self._app_runtime)
|
||||||
logger.create()
|
logger.create()
|
||||||
with self.assertRaises(SystemExit):
|
with self.assertRaises(SystemExit):
|
||||||
logger.fatal(__name__, f'{__name__}.test_fatal:')
|
logger.fatal(__name__, f'{__name__}.test_fatal:')
|
||||||
|
|
||||||
log_file = Template(self._log_settings.filename).substitute(
|
log_file = Template(self._log_settings.filename).substitute(
|
||||||
date_time_now=self._app_host.date_time_now.strftime(self._time_format_settings.date_time_format),
|
date_time_now=self._app_runtime.date_time_now.strftime(self._time_format_settings.date_time_format),
|
||||||
start_time=self._app_host.start_time.strftime(self._time_format_settings.date_time_log_format)
|
start_time=self._app_runtime.start_time.strftime(self._time_format_settings.date_time_log_format)
|
||||||
)
|
)
|
||||||
log_content = []
|
log_content = []
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ from sh_edraft.time.model import TimeFormatSettings
|
|||||||
|
|
||||||
class PublisherTest(unittest.TestCase):
|
class PublisherTest(unittest.TestCase):
|
||||||
|
|
||||||
def _config(self):
|
def _configure(self):
|
||||||
self._log_settings = LoggingSettings()
|
self._log_settings = LoggingSettings()
|
||||||
self._log_settings.from_dict({
|
self._log_settings.from_dict({
|
||||||
"Path": "logs/",
|
"Path": "logs/",
|
||||||
@ -76,10 +76,12 @@ class PublisherTest(unittest.TestCase):
|
|||||||
})
|
})
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self._config()
|
self._configure()
|
||||||
|
|
||||||
self._app_host = ApplicationHost('CPL_Test', HostingEnvironment(EnvironmentName.testing, './'))
|
app_host = ApplicationHost('CPL_Test')
|
||||||
self._logger = Logger(self._log_settings, self._time_format_settings, self._app_host)
|
self._app_runtime = app_host.application_runtime
|
||||||
|
|
||||||
|
self._logger = Logger(self._log_settings, self._time_format_settings, app_host.application_runtime)
|
||||||
self._logger.create()
|
self._logger.create()
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
@ -92,3 +94,4 @@ class PublisherTest(unittest.TestCase):
|
|||||||
|
|
||||||
publisher.create()
|
publisher.create()
|
||||||
self.assertTrue(os.path.isdir(self._dist_path))
|
self.assertTrue(os.path.isdir(self._dist_path))
|
||||||
|
self.assertEqual(publisher._publish_settings, self._publish_settings_model)
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import unittest
|
import unittest
|
||||||
|
from collections import Callable
|
||||||
|
from typing import Type, cast
|
||||||
|
|
||||||
from sh_edraft.hosting import ApplicationHost
|
from sh_edraft.hosting import ApplicationHost
|
||||||
from sh_edraft.hosting import HostingEnvironment
|
|
||||||
from sh_edraft.hosting.model import EnvironmentName
|
|
||||||
from sh_edraft.logging import Logger
|
from sh_edraft.logging import Logger
|
||||||
from sh_edraft.logging.base import LoggerBase
|
from sh_edraft.logging.base import LoggerBase
|
||||||
from sh_edraft.logging.model import LoggingSettings
|
from sh_edraft.logging.model import LoggingSettings
|
||||||
@ -17,8 +17,10 @@ from sh_edraft.time.model import TimeFormatSettings
|
|||||||
class ServiceProviderTest(unittest.TestCase):
|
class ServiceProviderTest(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self._app_host = ApplicationHost('CPL_Test', HostingEnvironment(EnvironmentName.testing, './'))
|
self._app_host = ApplicationHost('CPL_Test')
|
||||||
self._services = self._app_host.services
|
self._config = self._app_host.configuration
|
||||||
|
self._config.create()
|
||||||
|
self._services: ServiceProvider = cast(ServiceProvider, self._app_host.services)
|
||||||
self._services.create()
|
self._services.create()
|
||||||
|
|
||||||
self._log_settings = LoggingSettings()
|
self._log_settings = LoggingSettings()
|
||||||
@ -28,7 +30,7 @@ class ServiceProviderTest(unittest.TestCase):
|
|||||||
"ConsoleLogLevel": "TRACE",
|
"ConsoleLogLevel": "TRACE",
|
||||||
"FileLogLevel": "TRACE"
|
"FileLogLevel": "TRACE"
|
||||||
})
|
})
|
||||||
self._services.config.add_config_by_type(LoggingSettings, self._log_settings)
|
self._config.add_config_by_type(LoggingSettings, self._log_settings)
|
||||||
|
|
||||||
self._time_format_settings = TimeFormatSettings()
|
self._time_format_settings = TimeFormatSettings()
|
||||||
self._time_format_settings.from_dict({
|
self._time_format_settings.from_dict({
|
||||||
@ -37,8 +39,8 @@ class ServiceProviderTest(unittest.TestCase):
|
|||||||
"DateTimeFormat": "%Y-%m-%d %H:%M:%S.%f",
|
"DateTimeFormat": "%Y-%m-%d %H:%M:%S.%f",
|
||||||
"DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S"
|
"DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S"
|
||||||
})
|
})
|
||||||
self._services.config.add_config_by_type(TimeFormatSettings, self._time_format_settings)
|
self._config.add_config_by_type(TimeFormatSettings, self._time_format_settings)
|
||||||
self._services.config.add_config_by_type(ApplicationHost, self._app_host)
|
self._config.add_config_by_type(ApplicationHost, self._app_host)
|
||||||
|
|
||||||
self._publish_settings_model = PublishSettingsModel()
|
self._publish_settings_model = PublishSettingsModel()
|
||||||
self._publish_settings_model.from_dict({
|
self._publish_settings_model.from_dict({
|
||||||
@ -49,7 +51,7 @@ class ServiceProviderTest(unittest.TestCase):
|
|||||||
"ExcludedFiles": [],
|
"ExcludedFiles": [],
|
||||||
"TemplateEnding": "_template.txt",
|
"TemplateEnding": "_template.txt",
|
||||||
})
|
})
|
||||||
self._services.config.add_config_by_type(PublishSettingsModel, self._publish_settings_model)
|
self._config.add_config_by_type(PublishSettingsModel, self._publish_settings_model)
|
||||||
|
|
||||||
def _check_general_requirements(self):
|
def _check_general_requirements(self):
|
||||||
self.assertIsNotNone(self._services)
|
self.assertIsNotNone(self._services)
|
||||||
@ -61,7 +63,7 @@ class ServiceProviderTest(unittest.TestCase):
|
|||||||
|
|
||||||
def test_create(self):
|
def test_create(self):
|
||||||
print(f'{__name__}.test_create:')
|
print(f'{__name__}.test_create:')
|
||||||
provider = ServiceProvider(self._app_host)
|
provider = ServiceProvider(self._app_host.application_runtime)
|
||||||
self.assertIsNotNone(provider)
|
self.assertIsNotNone(provider)
|
||||||
provider.create()
|
provider.create()
|
||||||
self.assertIsNotNone(provider)
|
self.assertIsNotNone(provider)
|
||||||
@ -108,7 +110,7 @@ class ServiceProviderTest(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(logger._log_settings, self._log_settings)
|
self.assertEqual(logger._log_settings, self._log_settings)
|
||||||
self.assertEqual(logger._time_format_settings, self._time_format_settings)
|
self.assertEqual(logger._time_format_settings, self._time_format_settings)
|
||||||
self.assertEqual(logger._app_host, self._app_host)
|
self.assertEqual(logger._app_runtime, self._app_host.application_runtime)
|
||||||
|
|
||||||
def test_add_scoped(self):
|
def test_add_scoped(self):
|
||||||
print(f'{__name__}.test_add_scoped:')
|
print(f'{__name__}.test_add_scoped:')
|
||||||
|
Loading…
Reference in New Issue
Block a user