From e2a20e1ab15b41ea9a2e88cc811b5ee2c27993c6 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Wed, 8 Feb 2023 11:58:27 +0100 Subject: [PATCH] Adding test/test_22_pfile_modinfo.py --- test/test_22_pfile_modinfo.py | 102 ++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100755 test/test_22_pfile_modinfo.py diff --git a/test/test_22_pfile_modinfo.py b/test/test_22_pfile_modinfo.py new file mode 100755 index 0000000..aa68eac --- /dev/null +++ b/test/test_22_pfile_modinfo.py @@ -0,0 +1,102 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +''' +@author: Frank Brehm +@contact: frank@brehm-online.com +@copyright: © 2023 Frank Brehm, Digitas Pixelpark GmbH Berlin +@license: GNU AGPL3 +@summary: test script (and module) for unit tests on Puppetfile module info +''' + +import os +import sys +import logging + +from pathlib import Path + +try: + import unittest2 as unittest +except ImportError: + import unittest + +libdir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'lib')) +sys.path.insert(0, libdir) + +from general import DpxPuppetToolsTestcase, get_arg_verbose, init_root_logger + +LOG = logging.getLogger('test_pfile_modinfo') + +# ============================================================================= +class TestPuppetfileModinfo(DpxPuppetToolsTestcase): + + # ------------------------------------------------------------------------- + def setUp(self): + self.test_dir = Path(__file__).parent.resolve() + self.base_dir = self.test_dir.parent + self.test_cfg_dir = self.test_dir / 'test-config' + self._appname = 'test_pfile_modinfo' + + # ------------------------------------------------------------------------- + def test_import(self): + + LOG.info("Testing import of dpx_puppettools.pfile_moduleinfo ...") + import dpx_puppettools.pfile_moduleinfo + ver = dpx_puppettools.pfile_moduleinfo.__version__ + LOG.debug( + "Version of dpx_puppettools.pfile_moduleinfo: " + ver) + + # ------------------------------------------------------------------------- + def test_init(self): + + LOG.info("Testing init of a PuppetfileModuleInfo object ...") + from dpx_puppettools.pfile_moduleinfo import PuppetfileModuleInfo + from dpx_puppettools.errors import ModuleInitError + + module = 'pixelpark-infra' + bad_module = 'uhu' + + modinfo = PuppetfileModuleInfo( + appname=self.appname, verbose=self.verbose, full_name=module) + + LOG.debug("PuppetfileModuleInfo %%r: {!r}".format(modinfo)) + if self.verbose > 2: + LOG.debug("PuppetfileModuleInfo %%s:\n{}".format(modinfo)) + self.assertEqual(modinfo.full_name, module) + self.assertEqual(modinfo.full_name_orig, module) + self.assertEqual(modinfo.name, 'infra') + self.assertEqual(modinfo.vendor, 'pixelpark') + + LOG.debug( + "Testing init of a PuppetfileModuleInfo object with a bad module name {!r}.".format( + bad_module)) + with self.assertRaises(ModuleInitError) as cm: + modinfo = PuppetfileModuleInfo( + appname=self.appname, verbose=self.verbose, full_name=bad_module) + LOG.warn("PuppetfileModuleInfo %%r: {!r}".format(modinfo)) + e = cm.exception + LOG.debug("{cls} raised: {e}".format(cls=e.__class__.__name__, e=e)) + + +# ============================================================================= +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(TestPuppetfileModinfo('test_import', verbose)) + suite.addTest(TestPuppetfileModinfo('test_init', verbose)) + # suite.addTest(TestBaseModinfo('test_compare', verbose)) + + runner = unittest.TextTestRunner(verbosity=verbose) + + result = runner.run(suite) + +# ============================================================================= + +# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 -- 2.39.5