--- /dev/null
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+@author: Frank Brehm
+@contact: frank.brehm@pixelpark.com
+@license: GPL3
+@summary: test script (and module) for unit tests
+ for function compare_fqdn()
+"""
+
+import os
+import sys
+import logging
+import locale
+import re
+
+try:
+ import unittest2 as unittest
+except ImportError:
+ import unittest
+
+import six
+
+libdir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
+sys.path.insert(0, libdir)
+
+from general import AdminToolsTestcase, get_arg_verbose, init_root_logger
+
+locale.setlocale(locale.LC_ALL, '')
+
+APPNAME = 'test_compare_fqdn'
+
+LOG = logging.getLogger(APPNAME)
+
+
+# =============================================================================
+class CompareFqdnTest(AdminToolsTestcase):
+
+ # -------------------------------------------------------------------------
+ def setUp(self):
+ self.appname = APPNAME
+
+ # -------------------------------------------------------------------------
+ def tearDown(self):
+ pass
+
+ # -------------------------------------------------------------------------
+ def test_import(self):
+
+ LOG.info("Testing import of pp_lib.common ...")
+ import pp_lib.common # noqa
+
+ LOG.info("Testing import of compare_fqdn from pp_lib.common ...")
+ from pp_lib.common import compare_fqdn # noqa
+
+ # -------------------------------------------------------------------------
+ def test_compare_fqdn(self):
+
+ LOG.info("Testing Comparision of FQDNS ...")
+
+ from pp_lib.common import compare_fqdn, pp
+
+ testcases = (
+ (None, None, 0),
+ ('a', None, 1),
+ (None, 'b', -1),
+ ('', '', 0),
+ ('a', '', 1),
+ ('', 'b', -1),
+ ('a', 'a', 0),
+ ('a', 'b', -1),
+ ('b', 'a', 1),
+ ('de', 'de.', 0),
+ ('de.', 'com.', 1),
+ ('com.', 'de.', -1),
+ ('a.de.', '.de', 1),
+ ('aa.de.', 'a.de.', 1),
+ ('a.a.de.', 'a.de.', 1),
+ ('a.de.', 'b.de', -1),
+ )
+
+ for case in testcases:
+
+ x = case[0]
+ y = case[1]
+ expected = case[2]
+
+ LOG.debug("Testing FQDN %r <=> %r -> expected %r", x, y, expected)
+ result = compare_fqdn(x, y)
+ LOG.debug("Got %r.", result)
+
+ self.assertEqual(result, expected)
+
+
+# =============================================================================
+
+
+if __name__ == '__main__':
+
+ verbose = get_arg_verbose()
+ if verbose is None:
+ verbose = 0
+ init_root_logger(verbose)
+
+ LOG.info("Starting tests ...")
+
+ loader = unittest.TestLoader()
+ suite = unittest.TestSuite()
+
+ suite.addTest(CompareFqdnTest('test_import', verbose))
+ suite.addTest(CompareFqdnTest('test_compare_fqdn', verbose))
+
+ runner = unittest.TextTestRunner(verbosity=verbose)
+
+ result = runner.run(suite)
+
+
+# =============================================================================
+
+# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4