コード例 #1
0
ファイル: fancylogger.py プロジェクト: lexming/vsc-base
    def test_parentinfo(self):
        """Test the collection of parentinfo"""
        log_fr = fancylogger.getLogger(fname=False)  # rootfancylogger
        pi_fr = log_fr._get_parent_info()
        self.assertEqual(len(pi_fr), 2)

        log_l1 = fancylogger.getLogger('level1', fname=False)
        # fname=False is required to have the naming similar for child relations
        pi_l1 = log_l1._get_parent_info()
        self.assertEqual(len(pi_l1), 3)

        is_py27 = is_py_ver(2, 7)

        if is_py27:
            log_l2a = log_l1.getChild('level2a')
            pi_l2a = log_l2a._get_parent_info()
            self.assertEqual(len(pi_l2a), 4)

        # this should be identical to getChild
        log_l2b = fancylogger.getLogger('level1.level2b', fname=False)
        # fname=False is required to have the name similar
        # cutoff last letter (a vs b)
        if is_py27:
            self.assertEqual(log_l2a.name[:-1], log_l2b.name[:-1])
        pi_l2b = log_l2b._get_parent_info()
        # yes, this broken on several levels (incl in logging itself)
        # adding '.' in the name does not automatically create the parent/child relations
        # if the parent with the name exists, this works
        self.assertEqual(len(pi_l2b), 4)

        log_l2c = fancylogger.getLogger('level1a.level2c', fname=False)
        pi_l2c = log_l2c._get_parent_info()
        self.assertEqual(len(pi_l2c), 3)  # level1a as parent does not exist
コード例 #2
0
    def test_is_py_ver(self):
        """Tests for is_py_ver, is_py2, is_py3 functions."""

        maj_ver = sys.version_info[0]
        min_ver = sys.version_info[1]

        if maj_ver >= 3:
            self.assertFalse(is_py2())
            self.assertFalse(is_py_ver(2))
            self.assertFalse(is_py_ver(2, 4))
            self.assertFalse(is_py_ver(2, min_ver=6))
            self.assertTrue(is_py3())
            self.assertTrue(is_py_ver(3))
            self.assertTrue(is_py_ver(3, min_ver))
            self.assertTrue(is_py_ver(3, min_ver=min_ver))
            if min_ver >= 6:
                self.assertTrue(is_py_ver(3, 6))
                self.assertTrue(is_py_ver(3, min_ver=6))
                self.assertFalse(is_py_ver(3, 99))
                self.assertFalse(is_py_ver(3, min_ver=99))
        else:
            # must be Python 2.6 or more recent Python 2 nowdays
            self.assertTrue(is_py2())
            self.assertTrue(is_py_ver(2))
            self.assertTrue(is_py_ver(2, 4))
            self.assertTrue(is_py_ver(2, min_ver=6))
            self.assertFalse(is_py3())
            self.assertFalse(is_py_ver(3))
            self.assertFalse(is_py_ver(3, 6))
            self.assertFalse(is_py_ver(3, min_ver=6))