Added logic to create new unittest project
This commit is contained in:
25
src/cpl_cli/_templates/new/unittest/__init__.py
Normal file
25
src/cpl_cli/_templates/new/unittest/__init__.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
cpl-cli sh-edraft Common Python library CLI
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Common Python library Command Line Interface
|
||||
|
||||
:copyright: (c) 2020 - 2022 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'cpl_cli._templates.new.console'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.16.dev2'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='16.dev2')
|
23
src/cpl_cli/_templates/new/unittest/license.py
Normal file
23
src/cpl_cli/_templates/new/unittest/license.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from cpl_cli._templates.template_file_abc import TemplateFileABC
|
||||
|
||||
|
||||
class LicenseTemplate(TemplateFileABC):
|
||||
|
||||
def __init__(self):
|
||||
TemplateFileABC.__init__(self)
|
||||
|
||||
self._name = 'LICENSE'
|
||||
self._path = ''
|
||||
self._value = """"""
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def path(self) -> str:
|
||||
return self._path
|
||||
|
||||
@property
|
||||
def value(self) -> str:
|
||||
return self._value
|
23
src/cpl_cli/_templates/new/unittest/readme_py.py
Normal file
23
src/cpl_cli/_templates/new/unittest/readme_py.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from cpl_cli._templates.template_file_abc import TemplateFileABC
|
||||
|
||||
|
||||
class ReadmeTemplate(TemplateFileABC):
|
||||
|
||||
def __init__(self):
|
||||
TemplateFileABC.__init__(self)
|
||||
|
||||
self._name = 'README.md'
|
||||
self._path = ''
|
||||
self._value = """"""
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def path(self) -> str:
|
||||
return self._path
|
||||
|
||||
@property
|
||||
def value(self) -> str:
|
||||
return self._value
|
25
src/cpl_cli/_templates/new/unittest/source/__init__.py
Normal file
25
src/cpl_cli/_templates/new/unittest/source/__init__.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
cpl-cli sh-edraft Common Python library CLI
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Common Python library Command Line Interface
|
||||
|
||||
:copyright: (c) 2020 - 2022 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'cpl_cli._templates.new.console.source'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.16.dev2'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='16.dev2')
|
25
src/cpl_cli/_templates/new/unittest/source/name/__init__.py
Normal file
25
src/cpl_cli/_templates/new/unittest/source/name/__init__.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
cpl-cli sh-edraft Common Python library CLI
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Common Python library Command Line Interface
|
||||
|
||||
:copyright: (c) 2020 - 2022 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'cpl_cli._templates.new.console.source.name'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.16.dev2'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='16.dev2')
|
@@ -0,0 +1,74 @@
|
||||
import textwrap
|
||||
|
||||
from cpl_cli._templates.template_file_abc import TemplateFileABC
|
||||
|
||||
|
||||
class ApplicationTemplate(TemplateFileABC):
|
||||
|
||||
def __init__(self, name: str, path: str, use_async: bool):
|
||||
TemplateFileABC.__init__(self)
|
||||
|
||||
self._name = 'application.py'
|
||||
self._path = path
|
||||
self._use_async = use_async
|
||||
|
||||
if self._use_async:
|
||||
self._value = textwrap.dedent("""\
|
||||
import unittest
|
||||
from unittest import TestSuite
|
||||
|
||||
from cpl_core.application import ApplicationABC
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from unittests.test_case import TestCase
|
||||
|
||||
|
||||
class Application(ApplicationABC):
|
||||
|
||||
def __init__(self, config: ConfigurationABC, services: ServiceProviderABC):
|
||||
ApplicationABC.__init__(self, config, services)
|
||||
self._suite: TestSuite = unittest.TestSuite()
|
||||
|
||||
async def configure(self):
|
||||
self._suite.addTest(TestCase('test_equal'))
|
||||
|
||||
async def main(self):
|
||||
runner = unittest.TextTestRunner()
|
||||
runner.run(self._suite)
|
||||
""")
|
||||
else:
|
||||
self._value = textwrap.dedent("""\
|
||||
import unittest
|
||||
from unittest import TestSuite
|
||||
|
||||
from cpl_core.application import ApplicationABC
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from unittests.test_case import TestCase
|
||||
|
||||
|
||||
class Application(ApplicationABC):
|
||||
|
||||
def __init__(self, config: ConfigurationABC, services: ServiceProviderABC):
|
||||
ApplicationABC.__init__(self, config, services)
|
||||
self._suite: TestSuite = unittest.TestSuite()
|
||||
|
||||
def configure(self):
|
||||
self._suite.addTest(TestCase('test_equal'))
|
||||
|
||||
def main(self):
|
||||
runner = unittest.TextTestRunner()
|
||||
runner.run(self._suite)
|
||||
""")
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def path(self) -> str:
|
||||
return self._path
|
||||
|
||||
@property
|
||||
def value(self) -> str:
|
||||
return self._value
|
27
src/cpl_cli/_templates/new/unittest/source/name/init.py
Normal file
27
src/cpl_cli/_templates/new/unittest/source/name/init.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import textwrap
|
||||
|
||||
from cpl_cli._templates.template_file_abc import TemplateFileABC
|
||||
|
||||
|
||||
class MainInitTemplate(TemplateFileABC):
|
||||
|
||||
def __init__(self, name: str, path: str):
|
||||
TemplateFileABC.__init__(self)
|
||||
|
||||
self._name = '__init__.py'
|
||||
self._path = path
|
||||
self._value = textwrap.dedent("""\
|
||||
# imports:
|
||||
""")
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def path(self) -> str:
|
||||
return self._path
|
||||
|
||||
@property
|
||||
def value(self) -> str:
|
||||
return self._value
|
63
src/cpl_cli/_templates/new/unittest/source/name/main.py
Normal file
63
src/cpl_cli/_templates/new/unittest/source/name/main.py
Normal file
@@ -0,0 +1,63 @@
|
||||
import textwrap
|
||||
|
||||
from cpl_core.utils.string import String
|
||||
from cpl_cli._templates.template_file_abc import TemplateFileABC
|
||||
|
||||
|
||||
class MainWithApplicationBaseTemplate(TemplateFileABC):
|
||||
|
||||
def __init__(self, name: str, path: str, use_async: bool):
|
||||
TemplateFileABC.__init__(self)
|
||||
|
||||
name = String.convert_to_snake_case(name)
|
||||
self._name = 'main.py'
|
||||
self._path = path
|
||||
|
||||
import_pkg = f'{name}.'
|
||||
|
||||
if use_async:
|
||||
self._value = textwrap.dedent(f"""\
|
||||
import asyncio
|
||||
|
||||
from cpl_core.application import ApplicationBuilder
|
||||
|
||||
from {import_pkg}application import Application
|
||||
|
||||
|
||||
async def main():
|
||||
app_builder = ApplicationBuilder(Application)
|
||||
app: Application = await app_builder.build_async()
|
||||
await app.run_async()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
ml = asyncio.get_event_loop()
|
||||
ml.run_until_complete(main())
|
||||
""")
|
||||
else:
|
||||
self._value = textwrap.dedent(f"""\
|
||||
from cpl_core.application import ApplicationBuilder
|
||||
|
||||
from {import_pkg}application import Application
|
||||
|
||||
|
||||
def main():
|
||||
app_builder = ApplicationBuilder(Application)
|
||||
app_builder.build().run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
""")
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def path(self) -> str:
|
||||
return self._path
|
||||
|
||||
@property
|
||||
def value(self) -> str:
|
||||
return self._value
|
52
src/cpl_cli/_templates/new/unittest/source/name/test_case.py
Normal file
52
src/cpl_cli/_templates/new/unittest/source/name/test_case.py
Normal file
@@ -0,0 +1,52 @@
|
||||
import textwrap
|
||||
|
||||
from cpl_cli._templates.template_file_abc import TemplateFileABC
|
||||
|
||||
|
||||
class TestCaseTemplate(TemplateFileABC):
|
||||
|
||||
def __init__(self, name: str, path: str, use_async: bool):
|
||||
TemplateFileABC.__init__(self)
|
||||
|
||||
self._name = 'test_case.py'
|
||||
self._path = path
|
||||
self._use_async = use_async
|
||||
|
||||
if self._use_async:
|
||||
self._value = textwrap.dedent("""\
|
||||
import unittest
|
||||
|
||||
|
||||
class TestCase(unittest.TestCase):
|
||||
|
||||
async def setUp(self) -> None:
|
||||
pass
|
||||
|
||||
async def test_equal(self):
|
||||
self.assertEqual(True, True)
|
||||
""")
|
||||
else:
|
||||
self._value = textwrap.dedent("""\
|
||||
import unittest
|
||||
|
||||
|
||||
class TestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self) -> None:
|
||||
pass
|
||||
|
||||
def test_equal(self):
|
||||
self.assertEqual(True, True)
|
||||
""")
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def path(self) -> str:
|
||||
return self._path
|
||||
|
||||
@property
|
||||
def value(self) -> str:
|
||||
return self._value
|
Reference in New Issue
Block a user