Added Tester to create all tests
This commit is contained in:
parent
bcfe6f2de4
commit
c8a7954adb
@ -1,42 +1,56 @@
|
||||
import os
|
||||
|
||||
from sh_edraft.service import ServiceProvider
|
||||
from sh_edraft.source_code.model import Version
|
||||
from sh_edraft.publish import Publisher
|
||||
from sh_edraft.publish.model import Template
|
||||
|
||||
if __name__ == '__main__':
|
||||
templates = [
|
||||
Template(
|
||||
'../../publish_templates/*_template.txt',
|
||||
'*',
|
||||
'',
|
||||
'',
|
||||
'2020',
|
||||
'sh-edraft.de',
|
||||
'MIT',
|
||||
', see LICENSE for more details.',
|
||||
'',
|
||||
'Sven Heidemann',
|
||||
Version(2020, 12, 0.1).to_dict()
|
||||
),
|
||||
Template(
|
||||
'../../publish_templates/*_template.txt',
|
||||
'sh_edraft',
|
||||
'common python library',
|
||||
'Library to share common classes and models used at sh-edraft.de',
|
||||
'2020',
|
||||
'sh-edraft.de',
|
||||
'MIT',
|
||||
', see LICENSE for more details.',
|
||||
'',
|
||||
'Sven Heidemann',
|
||||
Version(2020, 12, 0.1).to_dict()
|
||||
)
|
||||
]
|
||||
|
||||
publisher = Publisher('../', '../../dist', templates)
|
||||
class PublisherTest:
|
||||
|
||||
publisher.exclude('../tests/')
|
||||
publisher.include('../../LICENSE')
|
||||
publisher.include('../../README.md')
|
||||
@staticmethod
|
||||
def start(services: ServiceProvider):
|
||||
templates = [
|
||||
Template(
|
||||
'../../publish_templates/*_template.txt',
|
||||
'*',
|
||||
'',
|
||||
'',
|
||||
'2020',
|
||||
'sh-edraft.de',
|
||||
'MIT',
|
||||
', see LICENSE for more details.',
|
||||
'',
|
||||
'Sven Heidemann',
|
||||
Version(2020, 12, 0.1).to_dict()
|
||||
),
|
||||
Template(
|
||||
'../../publish_templates/*_template.txt',
|
||||
'sh_edraft',
|
||||
'common python library',
|
||||
'Library to share common classes and models used at sh-edraft.de',
|
||||
'2020',
|
||||
'sh-edraft.de',
|
||||
'MIT',
|
||||
', see LICENSE for more details.',
|
||||
'',
|
||||
'Sven Heidemann',
|
||||
Version(2020, 12, 0.1).to_dict()
|
||||
)
|
||||
]
|
||||
|
||||
publisher.create()
|
||||
publisher.publish()
|
||||
source = '../'
|
||||
dist = '../../dist'
|
||||
|
||||
services.add_singleton(Publisher, None, source, dist, templates)
|
||||
publisher: Publisher = services.get_service(Publisher)
|
||||
|
||||
publisher.exclude('../tests/')
|
||||
publisher.include('../../LICENSE')
|
||||
publisher.include('../../README.md')
|
||||
|
||||
publisher.create()
|
||||
publisher.publish()
|
||||
|
||||
if not os.path.isdir(dist):
|
||||
raise Exception(f'{__name__}: Dist path was not created')
|
||||
|
23
src/tests/service_provider.py
Normal file
23
src/tests/service_provider.py
Normal file
@ -0,0 +1,23 @@
|
||||
from sh_edraft.publish import Publisher
|
||||
from sh_edraft.service import ServiceProvider
|
||||
|
||||
|
||||
class ServiceProviderTest:
|
||||
|
||||
@staticmethod
|
||||
def start() -> ServiceProvider:
|
||||
provider = ServiceProvider()
|
||||
provider.create()
|
||||
|
||||
provider.add_transient(Publisher, None, '../', '../../dist', [])
|
||||
|
||||
publisher: Publisher = provider.get_service(Publisher)
|
||||
|
||||
if publisher.source_path != '../' or publisher.dist_path != '../../dist':
|
||||
raise Exception(f'{__name__}: Invalid value in {Publisher.__name__}')
|
||||
|
||||
provider.remove_service(Publisher)
|
||||
if provider.get_service(Publisher) is not None:
|
||||
raise Exception(f'{__name__}: Service {Publisher.__name__} was not removed')
|
||||
|
||||
return provider
|
67
src/tests/test.py
Normal file
67
src/tests/test.py
Normal file
@ -0,0 +1,67 @@
|
||||
import os
|
||||
import sys
|
||||
from typing import Optional
|
||||
|
||||
from termcolor import colored
|
||||
|
||||
from sh_edraft.service import ServiceProvider
|
||||
from tests.publisher import PublisherTest
|
||||
from tests.service_provider import ServiceProviderTest
|
||||
|
||||
|
||||
class Test:
|
||||
|
||||
def __init__(self):
|
||||
self._services: Optional[ServiceProvider] = None
|
||||
|
||||
self._tests = [
|
||||
ServiceProviderTest,
|
||||
PublisherTest
|
||||
]
|
||||
|
||||
self._error: bool = False
|
||||
|
||||
@staticmethod
|
||||
def block_print():
|
||||
sys.stdout = open(os.devnull, 'w')
|
||||
|
||||
@staticmethod
|
||||
def enable_print():
|
||||
sys.stdout = sys.__stdout__
|
||||
|
||||
def success(self, message: str):
|
||||
self.enable_print()
|
||||
print(colored(message, 'green'))
|
||||
self.block_print()
|
||||
|
||||
def failed(self, message: str):
|
||||
self.enable_print()
|
||||
print(colored(message, 'red'))
|
||||
self.block_print()
|
||||
|
||||
def create(self): pass
|
||||
|
||||
def start(self):
|
||||
self.block_print()
|
||||
|
||||
if not self._error:
|
||||
try:
|
||||
self._services = ServiceProviderTest.start()
|
||||
self.success(f'{ServiceProviderTest.__name__} test succeeded.')
|
||||
except Exception as e:
|
||||
self._error = True
|
||||
self.failed(f'{ServiceProviderTest.__name__} test failed!\n{e}')
|
||||
|
||||
if not self._error:
|
||||
try:
|
||||
PublisherTest.start(self._services)
|
||||
self.success(f'{PublisherTest.__name__} test succeeded.')
|
||||
except Exception as e:
|
||||
self._error = True
|
||||
self.failed(f'{PublisherTest.__name__} test failed!\n{e}')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
test = Test()
|
||||
test.create()
|
||||
test.start()
|
Loading…
Reference in New Issue
Block a user