Exemplo n.º 1
0
 def testUpdate(self):
     name = self._CreateTempFile()
     oldi = utils.GetFileID(path=name)
     fd = os.open(name, os.O_RDWR)
     try:
         newi = utils.GetFileID(fd=fd)
         self.failUnless(utils.VerifyFileID(oldi, newi))
         self.failUnless(utils.VerifyFileID(newi, oldi))
     finally:
         os.close(fd)
Exemplo n.º 2
0
    def testReopen(self):
        tmpfile = tempfile.NamedTemporaryFile()
        tmpfile2 = tempfile.NamedTemporaryFile()

        handler = utils.log._ReopenableLogHandler(tmpfile.name)

        self.assertFalse(utils.ReadFile(tmpfile.name))
        self.assertFalse(utils.ReadFile(tmpfile2.name))

        logger = logging.Logger("TestLoggerReopen")
        logger.addHandler(handler)

        for _ in range(3):
            logger.error("Test message ERROR")
        handler.flush()
        self.assertEqual(len(utils.ReadFile(tmpfile.name).splitlines()), 3)
        before_id = utils.GetFileID(tmpfile.name)

        handler.RequestReopen()
        self.assertTrue(handler._reopen)
        self.assertTrue(
            utils.VerifyFileID(utils.GetFileID(tmpfile.name), before_id))

        # Rename only after requesting reopen
        os.rename(tmpfile.name, tmpfile2.name)
        assert not os.path.exists(tmpfile.name)

        # Write another message, should reopen
        for _ in range(4):
            logger.info("Test message INFO")

            # Flag must be reset
            self.assertFalse(handler._reopen)

            self.assertFalse(
                utils.VerifyFileID(utils.GetFileID(tmpfile.name), before_id))

        logger.removeHandler(handler)
        self.assertFalse(logger.handlers)
        handler.close()

        self.assertEqual(len(utils.ReadFile(tmpfile.name).splitlines()), 4)
        self.assertEqual(len(utils.ReadFile(tmpfile2.name).splitlines()), 3)
Exemplo n.º 3
0
 def testEquality(self):
     name = self._CreateTempFile()
     oldi = utils.GetFileID(path=name)
     self.failUnless(utils.VerifyFileID(oldi, oldi))
Exemplo n.º 4
0
 def testEquality(self):
     name = self._CreateTempFile()
     oldi = utils.GetFileID(path=name)
     self.assertTrue(utils.VerifyFileID(oldi, oldi))