#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
+@summary: General used functions an objects used for unit tests on the pp-admintools.
+
@author: Frank Brehm
@contact: frank.brehm@pixelpark.com
@copyright: © 2021 Frank Brehm, Digitas Pixelpark GmbH Berlin
@license: LGPL3
-@summary: general used functions an objects used for unit tests on
- the pp-admintools
"""
+import argparse
+import logging
import os
import sys
-import logging
-import argparse
-
+import textwrap
from pathlib import Path
try:
except ImportError:
import unittest
-import six
-
-# Own modules
+# Third party modules
from fb_logging.colored import ColoredFormatter
+import six
+
# =============================================================================
LOG = logging.getLogger(__name__)
# =============================================================================
def get_arg_verbose():
-
+ """Get and return command line arguments."""
arg_parser = argparse.ArgumentParser()
- arg_parser = argparse.ArgumentParser()
arg_parser.add_argument(
- "-v", "--verbose", action="count",
+ '-v', '--verbose', action='count',
dest='verbose', help='Increase the verbosity level')
args = arg_parser.parse_args()
# =============================================================================
def init_root_logger(verbose=0):
-
+ """Initialize the root logger."""
root_log = logging.getLogger()
root_log.setLevel(logging.WARNING)
if verbose:
# =============================================================================
class PpAdminToolsTestcase(unittest.TestCase):
+ """Base test case for all testcase classes of this package."""
# -------------------------------------------------------------------------
def __init__(self, methodName='runTest', verbose=0):
-
+ """Initialize the base testcase class."""
self._verbose = int(verbose)
appname = os.path.basename(sys.argv[0]).replace('.py', '')
# -------------------------------------------------------------------------
@property
def verbose(self):
- """The verbosity level."""
+ """Return the verbosity level."""
return getattr(self, '_verbose', 0)
# -------------------------------------------------------------------------
@property
def appname(self):
- """The name of the current running application."""
+ """Return the name of the current running application."""
return self._appname
# -------------------------------------------------------------------------
def setUp(self):
+ """Execute this on seting up before calling each particular test method."""
pass
# -------------------------------------------------------------------------
def tearDown(self):
+ """Tear down routine for calling each particular test method."""
pass
+ # -------------------------------------------------------------------------
+ @classmethod
+ def current_function_name(cls, level=0):
+ """Return the name of the function, from where this method was called."""
+ return sys._getframe(level + 1).f_code.co_name
+
+ # -------------------------------------------------------------------------
+ @classmethod
+ def get_method_doc(cls):
+ """Return the docstring of the method, from where this method was called."""
+ func_name = cls.current_function_name(1)
+ doc_str = getattr(cls, func_name).__doc__
+ cname = cls.__name__
+ mname = '{cls}.{meth}()'.format(cls=cname, meth=func_name)
+ msg = 'This is {}.'.format(mname)
+ if doc_str is None:
+ return msg
+ doc_str = textwrap.dedent(doc_str).strip()
+ if doc_str:
+ msg = '{m} - {d}'.format(m=mname, d=doc_str)
+ return msg
+
# =============================================================================
if __name__ == '__main__':
# -------------------------------------------------------------------------
def test_import(self):
"""Test importing module pp_admintools.config.mail."""
- LOG.info('Testing import of pp_admintools.config.mail ...')
+ LOG.info(self.get_method_doc())
+
import pp_admintools.config.mail
LOG.debug(
'Version of pp_admintools.config.mail: ' + pp_admintools.config.mail.__version__)
# -------------------------------------------------------------------------
def test_object(self):
"""Test init of a MailConfiguration object."""
- LOG.info('Testing init of a MailConfiguration object.')
+ LOG.info(self.get_method_doc())
from pp_admintools.config.mail import MailConfiguration
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-'''
+"""
+@summary: Test script (and module) for unit tests on LDAP config class.
+
@author: Frank Brehm
@contact: frank.brehm@pixelpark.com
@copyright: © 2022 by Frank Brehm, Berlin
@license: GPL3
-@summary: test script (and module) for unit tests on LDAP config class
-'''
+"""
+import logging
import os
import sys
-import logging
-
+import textwrap
from pathlib import Path
try:
# =============================================================================
class TestLdapConfig(PpAdminToolsTestcase):
+ """Testcase for unit tests on LDAP config objects."""
# -------------------------------------------------------------------------
def setUp(self):
-
+ """Execute this on setting up before calling each particular test method."""
self.test_dir = Path(__file__).parent.resolve()
self.base_dir = self.test_dir.parent
self.test_cfg_dir = self.test_dir / 'test-ldapconfig'
# -------------------------------------------------------------------------
def tearDown(self):
-
+ """Execute this after calling each particular test method."""
pass
# -------------------------------------------------------------------------
def test_import(self):
+ """Test importing module pp_admintools.config.ldap."""
+ LOG.info(self.get_method_doc())
- LOG.info("Testing import of pp_admintools.config.ldap ...")
+ LOG.info('Testing import of pp_admintools.config.ldap ...')
import pp_admintools.config.ldap
LOG.debug(
- "Version of pp_admintools.config.ldap: " + pp_admintools.config.ldap.__version__)
+ 'Version of pp_admintools.config.ldap: ' + pp_admintools.config.ldap.__version__)
- LOG.info("Testing import of LdapConfigError from pp_admintools.config.ldap ...")
- from pp_admintools.config.ldap import LdapConfigError # noqa
+ LOG.info('Testing import of LdapConfigError from pp_admintools.config.ldap ...')
+ from pp_admintools.config.ldap import LdapConfigError
+ LOG.debug(
+ 'Description of LdapConfigError: ' + textwrap.dedent(LdapConfigError.__doc__))
- LOG.info("Testing import of LdapConnectionInfo from pp_admintools.config.ldap ...")
- from pp_admintools.config.ldap import LdapConnectionInfo # noqa
+ LOG.info('Testing import of LdapConnectionInfo from pp_admintools.config.ldap ...')
+ from pp_admintools.config.ldap import LdapConnectionInfo
+ LOG.debug(
+ 'Description of LdapConnectionInfo: ' + textwrap.dedent(LdapConnectionInfo.__doc__))
- LOG.info("Testing import of LdapConfiguration from pp_admintools.config.ldap ...")
- from pp_admintools.config.ldap import LdapConfiguration # noqa
+ LOG.info('Testing import of LdapConfiguration from pp_admintools.config.ldap ...')
+ from pp_admintools.config.ldap import LdapConfiguration
+ LOG.debug(
+ 'Description of LdapConfiguration: ' + textwrap.dedent(LdapConfiguration.__doc__))
# -------------------------------------------------------------------------
def test_object(self):
-
- LOG.info("Testing init of a LdapConfiguration object.")
+ """Test initializing a LdapConfiguration object."""
+ LOG.info(self.get_method_doc())
from pp_admintools.config.ldap import LdapConfiguration
config_dir='test', additional_stems='test',
verbose=self.verbose,
)
- LOG.debug("LdapConfiguration %%r: %r", cfg)
- LOG.debug("LdapConfiguration %%s: %s", str(cfg))
+ LOG.debug('LdapConfiguration %%r: %r', cfg)
+ LOG.debug('LdapConfiguration %%s: %s', str(cfg))
# =============================================================================
verbose = 0
init_root_logger(verbose)
- LOG.info("Starting tests ...")
+ LOG.info('Starting tests ...')
suite = unittest.TestSuite()
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-'''
+"""
+@summary: Test script (and module) for unit tests on base application class.
+
@author: Frank Brehm
@contact: frank.brehm@pixelpark.com
@copyright: © 2024 by Frank Brehm, Berlin
@license: GPL3
-@summary: test script (and module) for unit tests on base application class
-'''
+"""
+import logging
import os
import sys
-import logging
-
from pathlib import Path
try:
# =============================================================================
class TestBaseApp(PpAdminToolsTestcase):
+ """Testcase for unit tests on base applicaion class."""
# -------------------------------------------------------------------------
def setUp(self):
+ """Execute this on setting up before calling each particular test method."""
+ if self.verbose >= 1:
+ print()
self.test_dir = Path(__file__).parent.resolve()
self.base_dir = self.test_dir.parent
# -------------------------------------------------------------------------
def tearDown(self):
-
+ """Execute this after calling each particular test method."""
pass
# -------------------------------------------------------------------------
def test_import(self):
+ """Test importing module pp_admintools.app."""
+ LOG.info(self.get_method_doc())
- LOG.info("Testing import of pp_admintools.app ...")
import pp_admintools.app
LOG.debug(
- "Version of pp_admintools.app: " + pp_admintools.app.__version__)
+ 'Version of pp_admintools.app: ' + pp_admintools.app.__version__)
# -------------------------------------------------------------------------
def test_cursor_position(self):
+ """Test getting the cursor position on a terminal."""
+ LOG.info(self.get_method_doc())
- LOG.info("Testing BaseDPXApplication.cursor_position() ...")
from pp_admintools.app import BaseDPXApplication
pos = BaseDPXApplication.cursor_position()
- LOG.debug("Got {}.".format(pos))
+ LOG.debug('Got {}.'.format(pos))
print('0123456789', end='', flush=True)
pos = BaseDPXApplication.cursor_position()
if pos.x == -1 and pos.y == -1:
- LOG.info("Terminal has no cursor.")
+ LOG.info('Terminal has no cursor.')
else:
print()
if pos.x != -1 and pos.y != -1:
- LOG.debug("Got {}.".format(pos))
+ LOG.debug('Got {}.'.format(pos))
self.assertEqual(pos.x, 11)
else:
- LOG.info("Could not detect position of screen cursor.")
+ LOG.info('Could not detect position of screen cursor.')
# =============================================================================
verbose = 0
init_root_logger(verbose)
- LOG.info("Starting tests ...")
+ LOG.info('Starting tests ...')
suite = unittest.TestSuite()
# -------------------------------------------------------------------------
def test_import(self):
"""Test importing module pp_admintools.postfix_chain."""
- LOG.info('Testing import of pp_admintools.postfix_chain ...')
+ LOG.info(self.get_method_doc())
+
import pp_admintools.postfix_chain
LOG.debug(
'Version of pp_admintools.postfix_chain: ' + pp_admintools.postfix_chain.__version__)
# -------------------------------------------------------------------------
def test_empty_object(self):
"""Test init of an empty PostfixLogchainInfo object."""
- LOG.info('Testing init of an empty PostfixLogchainInfo object.')
+ LOG.info(self.get_method_doc())
from pp_admintools.postfix_chain import PostfixLogchainInfo
# -------------------------------------------------------------------------
def test_filled_object(self):
"""Test init of a filled PostfixLogchainInfo object."""
- LOG.info('Testing init of a filled PostfixLogchainInfo object.')
+ LOG.info(self.get_method_doc())
from pp_admintools.postfix_chain import PostfixLogchainInfo