From 3b3f21bae30d71b09d50174c5a1703f3f037a53e Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Thu, 21 Mar 2024 16:28:57 +0100 Subject: [PATCH] Make the linter happy --- test/general.py | 54 +++++++++++++++++++++++++---------- test/test_05_mailcfg.py | 5 ++-- test/test_06_ldapcfg.py | 50 +++++++++++++++++++------------- test/test_10_base_app.py | 34 +++++++++++++--------- test/test_20_postfix_chain.py | 7 +++-- 5 files changed, 96 insertions(+), 54 deletions(-) diff --git a/test/general.py b/test/general.py index d454808..ce2c716 100644 --- a/test/general.py +++ b/test/general.py @@ -1,19 +1,19 @@ #!/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: @@ -21,11 +21,11 @@ try: except ImportError: import unittest -import six - -# Own modules +# Third party modules from fb_logging.colored import ColoredFormatter +import six + # ============================================================================= LOG = logging.getLogger(__name__) @@ -33,12 +33,11 @@ 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() @@ -47,7 +46,7 @@ def get_arg_verbose(): # ============================================================================= def init_root_logger(verbose=0): - + """Initialize the root logger.""" root_log = logging.getLogger() root_log.setLevel(logging.WARNING) if verbose: @@ -79,10 +78,11 @@ def init_root_logger(verbose=0): # ============================================================================= 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', '') @@ -102,23 +102,47 @@ class PpAdminToolsTestcase(unittest.TestCase): # ------------------------------------------------------------------------- @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__': diff --git a/test/test_05_mailcfg.py b/test/test_05_mailcfg.py index 7e19d3e..2d17a06 100755 --- a/test/test_05_mailcfg.py +++ b/test/test_05_mailcfg.py @@ -55,7 +55,8 @@ class TestMailConfig(PpAdminToolsTestcase): # ------------------------------------------------------------------------- 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__) @@ -72,7 +73,7 @@ class TestMailConfig(PpAdminToolsTestcase): # ------------------------------------------------------------------------- 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 diff --git a/test/test_06_ldapcfg.py b/test/test_06_ldapcfg.py index b8ae32a..581c76b 100755 --- a/test/test_06_ldapcfg.py +++ b/test/test_06_ldapcfg.py @@ -1,17 +1,18 @@ #!/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: @@ -33,10 +34,11 @@ LOG = logging.getLogger('test-ldapcfg') # ============================================================================= 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' @@ -44,30 +46,38 @@ class TestLdapConfig(PpAdminToolsTestcase): # ------------------------------------------------------------------------- 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 @@ -76,8 +86,8 @@ class TestLdapConfig(PpAdminToolsTestcase): 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)) # ============================================================================= @@ -88,7 +98,7 @@ if __name__ == '__main__': verbose = 0 init_root_logger(verbose) - LOG.info("Starting tests ...") + LOG.info('Starting tests ...') suite = unittest.TestSuite() diff --git a/test/test_10_base_app.py b/test/test_10_base_app.py index b84c926..c608ed5 100755 --- a/test/test_10_base_app.py +++ b/test/test_10_base_app.py @@ -1,17 +1,17 @@ #!/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: @@ -32,9 +32,13 @@ LOG = logging.getLogger('test-base-app') # ============================================================================= 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 @@ -42,37 +46,39 @@ class TestBaseApp(PpAdminToolsTestcase): # ------------------------------------------------------------------------- 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.') # ============================================================================= @@ -83,7 +89,7 @@ if __name__ == '__main__': verbose = 0 init_root_logger(verbose) - LOG.info("Starting tests ...") + LOG.info('Starting tests ...') suite = unittest.TestSuite() diff --git a/test/test_20_postfix_chain.py b/test/test_20_postfix_chain.py index f4f0710..e4c5d23 100755 --- a/test/test_20_postfix_chain.py +++ b/test/test_20_postfix_chain.py @@ -53,7 +53,8 @@ class TestPostfixChain(PpAdminToolsTestcase): # ------------------------------------------------------------------------- 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__) @@ -66,7 +67,7 @@ class TestPostfixChain(PpAdminToolsTestcase): # ------------------------------------------------------------------------- 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 @@ -78,7 +79,7 @@ class TestPostfixChain(PpAdminToolsTestcase): # ------------------------------------------------------------------------- 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 -- 2.39.5