Bugfixes in unittests

This commit is contained in:
Sven Heidemann 2020-11-27 11:24:47 +01:00
parent 7d4efe7bda
commit e76b293f60
7 changed files with 65 additions and 52 deletions

View File

@ -10,10 +10,6 @@ class ConfigurationBase(ABC):
@abstractmethod
def __init__(self): pass
@property
@abstractmethod
def config(self) -> dict[type, object]: pass
@abstractmethod
def add_config_by_type(self, key_type: type, value: object): pass

View File

@ -11,10 +11,6 @@ class Configuration(ConfigurationBase):
self._config: dict[type, object] = {}
@property
def config(self):
return self._config
def create(self): pass
def add_config_by_type(self, key_type: type, value: object):

View File

@ -3,6 +3,7 @@ from datetime import datetime
from sh_edraft.configuration.configuration import Configuration
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.hosting_environment import HostingEnvironment
from sh_edraft.hosting.application_runtime import ApplicationRuntime
@ -30,13 +31,17 @@ class ApplicationHost(ApplicationHostBase):
def name(self) -> str:
return self._name
@property
def configuration(self) -> ConfigurationBase:
return self._config
@property
def environment(self) -> EnvironmentBase:
return self._environment
@property
def configuration(self) -> ConfigurationBase:
return self._config
def application_runtime(self) -> ApplicationRuntimeBase:
return self._app_runtime
@property
def services(self) -> ServiceProviderBase:

View File

@ -1,6 +1,7 @@
from abc import ABC, abstractmethod
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.service.base.service_provider_base import ServiceProviderBase
@ -14,13 +15,17 @@ class ApplicationHostBase(ABC):
@abstractmethod
def name(self) -> str: pass
@property
@abstractmethod
def configuration(self) -> ConfigurationBase: pass
@property
@abstractmethod
def environment(self) -> EnvironmentBase: pass
@property
@abstractmethod
def configuration(self) -> ConfigurationBase: pass
def application_runtime(self) -> ApplicationRuntimeBase: pass
@property
@abstractmethod

View File

@ -2,18 +2,24 @@ import os
import shutil
import unittest
from string import Template
from typing import cast
from sh_edraft.hosting import ApplicationHost, HostingEnvironment
from sh_edraft.hosting.model import EnvironmentName
from sh_edraft.hosting import ApplicationHost
from sh_edraft.logging import Logger
from sh_edraft.logging.model import LoggingSettings
from sh_edraft.service import ServiceProvider
from sh_edraft.time.model import TimeFormatSettings
class LoggerTest(unittest.TestCase):
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.from_dict({
@ -41,25 +47,25 @@ class LoggerTest(unittest.TestCase):
def test_create(self):
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()
self.assertTrue(os.path.isdir(self._log_settings.path))
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),
start_time=self._app_host.start_time.strftime(self._time_format_settings.date_time_log_format)
date_time_now=self._app_runtime.date_time_now.strftime(self._time_format_settings.date_time_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))
def test_header(self):
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.header('HeaderTest:')
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),
start_time=self._app_host.start_time.strftime(self._time_format_settings.date_time_log_format)
date_time_now=self._app_runtime.date_time_now.strftime(self._time_format_settings.date_time_format),
start_time=self._app_runtime.start_time.strftime(self._time_format_settings.date_time_log_format)
)
log_content = []
@ -75,13 +81,13 @@ class LoggerTest(unittest.TestCase):
def test_trace(self):
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.trace(__name__, f'{__name__}.test_trace:')
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),
start_time=self._app_host.start_time.strftime(self._time_format_settings.date_time_log_format)
date_time_now=self._app_runtime.date_time_now.strftime(self._time_format_settings.date_time_format),
start_time=self._app_runtime.start_time.strftime(self._time_format_settings.date_time_log_format)
)
log_content = []
@ -97,13 +103,13 @@ class LoggerTest(unittest.TestCase):
def test_debug(self):
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.debug(__name__, f'{__name__}.test_debug:')
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),
start_time=self._app_host.start_time.strftime(self._time_format_settings.date_time_log_format)
date_time_now=self._app_runtime.date_time_now.strftime(self._time_format_settings.date_time_format),
start_time=self._app_runtime.start_time.strftime(self._time_format_settings.date_time_log_format)
)
log_content = []
@ -119,13 +125,13 @@ class LoggerTest(unittest.TestCase):
def test_info(self):
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.info(__name__, f'{__name__}.test_info:')
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),
start_time=self._app_host.start_time.strftime(self._time_format_settings.date_time_log_format)
date_time_now=self._app_runtime.date_time_now.strftime(self._time_format_settings.date_time_format),
start_time=self._app_runtime.start_time.strftime(self._time_format_settings.date_time_log_format)
)
log_content = []
@ -141,13 +147,13 @@ class LoggerTest(unittest.TestCase):
def test_warn(self):
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.warn(__name__, f'{__name__}.test_warn:')
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),
start_time=self._app_host.start_time.strftime(self._time_format_settings.date_time_log_format)
date_time_now=self._app_runtime.date_time_now.strftime(self._time_format_settings.date_time_format),
start_time=self._app_runtime.start_time.strftime(self._time_format_settings.date_time_log_format)
)
log_content = []
@ -163,13 +169,13 @@ class LoggerTest(unittest.TestCase):
def test_error(self):
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.error(__name__, f'{__name__}.test_error:')
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),
start_time=self._app_host.start_time.strftime(self._time_format_settings.date_time_log_format)
date_time_now=self._app_runtime.date_time_now.strftime(self._time_format_settings.date_time_format),
start_time=self._app_runtime.start_time.strftime(self._time_format_settings.date_time_log_format)
)
log_content = []
@ -185,14 +191,14 @@ class LoggerTest(unittest.TestCase):
def test_fatal(self):
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()
with self.assertRaises(SystemExit):
logger.fatal(__name__, f'{__name__}.test_fatal:')
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),
start_time=self._app_host.start_time.strftime(self._time_format_settings.date_time_log_format)
date_time_now=self._app_runtime.date_time_now.strftime(self._time_format_settings.date_time_format),
start_time=self._app_runtime.start_time.strftime(self._time_format_settings.date_time_log_format)
)
log_content = []

View File

@ -15,7 +15,7 @@ from sh_edraft.time.model import TimeFormatSettings
class PublisherTest(unittest.TestCase):
def _config(self):
def _configure(self):
self._log_settings = LoggingSettings()
self._log_settings.from_dict({
"Path": "logs/",
@ -76,10 +76,12 @@ class PublisherTest(unittest.TestCase):
})
def setUp(self):
self._config()
self._configure()
self._app_host = ApplicationHost('CPL_Test', HostingEnvironment(EnvironmentName.testing, './'))
self._logger = Logger(self._log_settings, self._time_format_settings, self._app_host)
app_host = ApplicationHost('CPL_Test')
self._app_runtime = app_host.application_runtime
self._logger = Logger(self._log_settings, self._time_format_settings, app_host.application_runtime)
self._logger.create()
def tearDown(self):
@ -92,3 +94,4 @@ class PublisherTest(unittest.TestCase):
publisher.create()
self.assertTrue(os.path.isdir(self._dist_path))
self.assertEqual(publisher._publish_settings, self._publish_settings_model)

View File

@ -1,8 +1,8 @@
import unittest
from collections import Callable
from typing import Type, cast
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.base import LoggerBase
from sh_edraft.logging.model import LoggingSettings
@ -17,8 +17,10 @@ from sh_edraft.time.model import TimeFormatSettings
class ServiceProviderTest(unittest.TestCase):
def setUp(self):
self._app_host = ApplicationHost('CPL_Test', HostingEnvironment(EnvironmentName.testing, './'))
self._services = self._app_host.services
self._app_host = ApplicationHost('CPL_Test')
self._config = self._app_host.configuration
self._config.create()
self._services: ServiceProvider = cast(ServiceProvider, self._app_host.services)
self._services.create()
self._log_settings = LoggingSettings()
@ -28,7 +30,7 @@ class ServiceProviderTest(unittest.TestCase):
"ConsoleLogLevel": "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.from_dict({
@ -37,8 +39,8 @@ class ServiceProviderTest(unittest.TestCase):
"DateTimeFormat": "%Y-%m-%d %H:%M:%S.%f",
"DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S"
})
self._services.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(TimeFormatSettings, self._time_format_settings)
self._config.add_config_by_type(ApplicationHost, self._app_host)
self._publish_settings_model = PublishSettingsModel()
self._publish_settings_model.from_dict({
@ -49,7 +51,7 @@ class ServiceProviderTest(unittest.TestCase):
"ExcludedFiles": [],
"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):
self.assertIsNotNone(self._services)
@ -61,7 +63,7 @@ class ServiceProviderTest(unittest.TestCase):
def test_create(self):
print(f'{__name__}.test_create:')
provider = ServiceProvider(self._app_host)
provider = ServiceProvider(self._app_host.application_runtime)
self.assertIsNotNone(provider)
provider.create()
self.assertIsNotNone(provider)
@ -108,7 +110,7 @@ class ServiceProviderTest(unittest.TestCase):
self.assertEqual(logger._log_settings, self._log_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):
print(f'{__name__}.test_add_scoped:')