--- /dev/null
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+@summary: Test script (and module) for unit tests on postfix logparser class.
+
+@author: Frank Brehm
+@contact: frank.brehm@pixelpark.com
+@copyright: © 2024 by Frank Brehm, Berlin
+@license: GPL3
+"""
+
+import logging
+import os
+import sys
+import textwrap
+from pathlib import Path
+
+try:
+ import unittest2 as unittest
+except ImportError:
+ import unittest
+
+# from babel.dates import LOCALTZ
+
+libdir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'lib'))
+sys.path.insert(0, libdir)
+
+# from fb_tools.common import pp, to_str, is_sequence
+# from fb_tools.common import pp
+
+from general import PpAdminToolsTestcase, get_arg_verbose, init_root_logger
+
+APPNAME = 'test-postfix-logparser'
+LOG = logging.getLogger(APPNAME)
+
+
+# =============================================================================
+class TestPostfixLogparser(PpAdminToolsTestcase):
+ """Testcase for unit tests on postfix logparser objects."""
+
+ # -------------------------------------------------------------------------
+ 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.logfile = self.test_dir / 'postfix.mail01.log'
+
+ self._appname = APPNAME
+
+ # -------------------------------------------------------------------------
+ def tearDown(self):
+ """Execute this after calling each particular test method."""
+ pass
+
+ # -------------------------------------------------------------------------
+ def test_import(self):
+ """Test importing module pp_admintools.handler.pflogparse."""
+ LOG.info(self.get_method_doc())
+
+ import pp_admintools.handler.pflogparse
+ version = pp_admintools.handler.pflogparse.__version__
+ LOG.debug('Version of pp_admintools.handler.pflogparse: ' + version)
+
+ LOG.info(
+ 'Testing import of PostfixLogfileParser from pp_admintools.handler.pflogparse ...')
+ from pp_admintools.handler.pflogparse import PostfixLogfileParser
+ the_doc = textwrap.dedent(PostfixLogfileParser.__doc__)
+ LOG.debug('Description of PostfixLogfileParser: ' + the_doc)
+
+ # -------------------------------------------------------------------------
+ def test_init_object(self):
+ """Test initializing a PostfixLogfileParser object."""
+ LOG.info(self.get_method_doc())
+
+ from pp_admintools.handler.pflogparse import PostfixLogfileParser
+
+ parser = PostfixLogfileParser(appname=APPNAME, verbose=self.verbose)
+
+ LOG.debug('PostfixLogfileParser %r: {!r}'.format(parser))
+ LOG.debug('PostfixLogfileParser %s:\n{}'.format(parser))
+
+ # -------------------------------------------------------------------------
+ def test_parsing(self):
+ """Test parsing a postfix logfile."""
+ LOG.info(self.get_method_doc())
+
+ from pp_admintools.handler.pflogparse import PostfixLogfileParser
+
+ parser = PostfixLogfileParser(appname=APPNAME, verbose=self.verbose)
+
+ LOG.debug('PostfixLogfileParser %r: {!r}'.format(parser))
+
+ with self.logfile.open('rt') as fh:
+ parser.parse(fh)
+
+ LOG.debug('PostfixLogfileParser %s:\n{}'.format(parser))
+
+
+# =============================================================================
+if __name__ == '__main__':
+
+ verbose = get_arg_verbose()
+ if verbose is None:
+ verbose = 0
+ init_root_logger(verbose)
+
+ LOG.info('Starting tests ...')
+
+ suite = unittest.TestSuite()
+
+ suite.addTest(TestPostfixLogparser('test_import', verbose))
+ suite.addTest(TestPostfixLogparser('test_init_object', verbose))
+ suite.addTest(TestPostfixLogparser('test_parsing', verbose))
+
+ runner = unittest.TextTestRunner(verbosity=verbose)
+
+ result = runner.run(suite)
+
+
+# =============================================================================
+
+# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 list