Added testing for service provider with unittests. Also fixed small bugs, found while testing.

This commit is contained in:
2020-11-23 22:22:17 +01:00
parent dd65bbb182
commit c7dff4a212
10 changed files with 178 additions and 100 deletions

View File

@@ -1,6 +1,10 @@
from abc import abstractmethod
from typing import Optional
from sh_edraft.service.base import ServiceBase
from sh_edraft.configuration.application_host import ApplicationHost
from sh_edraft.logging.model.log_settings import LoggingSettings
from sh_edraft.service.base.service_base import ServiceBase
from sh_edraft.time.model.time_format_settings import TimeFormatSettings
class LoggerBase(ServiceBase):
@@ -9,6 +13,10 @@ class LoggerBase(ServiceBase):
def __init__(self):
ServiceBase.__init__(self)
self._log_settings: Optional[LoggingSettings] = None
self._time_format_settings: Optional[TimeFormatSettings] = None
self._app_host: Optional[ApplicationHost] = None
@abstractmethod
def header(self, string: str): pass

View File

@@ -4,11 +4,8 @@ import traceback
from string import Template
from typing import Optional
from sh_edraft.configuration.application_host import ApplicationHost
from sh_edraft.logging.base.logger_base import LoggerBase
from sh_edraft.logging.model.log_level import LoggingLevel
from sh_edraft.logging.model.log_settings import LoggingSettings
from sh_edraft.time.model.time_format_settings import TimeFormatSettings
from sh_edraft.utils.console import Console
@@ -17,10 +14,6 @@ class Logger(LoggerBase):
def __init__(self):
LoggerBase.__init__(self)
self._log_settings: Optional[LoggingSettings] = None
self._time_format_settings: Optional[TimeFormatSettings] = None
self._app_host: Optional[ApplicationHost] = None
self._log: Optional[str] = None
self._path: Optional[str] = None
self._level: Optional[LoggingLevel] = None

View File

@@ -1,6 +1,9 @@
from abc import abstractmethod
from typing import Optional
from sh_edraft.service.base import ServiceBase
from sh_edraft.logging.base.logger_base import LoggerBase
from sh_edraft.publish.model.template import Template
from sh_edraft.service.base.service_base import ServiceBase
class PublisherBase(ServiceBase):
@@ -9,6 +12,14 @@ class PublisherBase(ServiceBase):
def __init__(self):
ServiceBase.__init__(self)
self._logger: Optional[LoggerBase] = None
self._source_path: Optional[str] = None
self._dist_path: Optional[str] = None
self._settings: Optional[list[Template]] = None
self._included_files: list[str] = []
self._excluded_files: list[str] = []
@property
@abstractmethod
def source_path(self) -> str: pass

View File

@@ -1,7 +1,6 @@
import os
import shutil
from string import Template as stringTemplate
from typing import Optional
from sh_edraft.logging.base.logger_base import LoggerBase
from sh_edraft.publish.base.publisher_base import PublisherBase
@@ -13,11 +12,6 @@ class Publisher(PublisherBase):
def __init__(self):
super().__init__()
self._logger: Optional[LoggerBase] = None
self._source_path: Optional[str] = None
self._dist_path: Optional[str] = None
self._settings: Optional[list[Template]] = None
self._included_files: list[str] = []
self._excluded_files: list[str] = []

View File

@@ -30,7 +30,7 @@ class ServiceProvider(ServiceProviderBase):
self._transient_services.append(ProvideState(service, args))
def add_scoped(self, service: Type[ServiceBase], *args):
self._transient_services.append(ProvideState(service, args))
self._scoped_services.append(ProvideState(service, args))
def add_singleton(self, service: Type[ServiceBase], *args):
for known_service in self._singleton_services: