def test_rotation(self):
        """
        Rotating log files autorotate after a period of time, and can also be
        manually rotated.
        """
        # this logfile should rotate every 10 bytes
        with contextlib.closing(
                logfile.LogFile(self.name, self.dir, rotateLength=10)) as log:

            # test automatic rotation
            log.write("123")
            log.write("4567890")
            log.write("1" * 11)
            self.assertTrue(os.path.exists("{0}.1".format(self.path)))
            self.assertFalse(os.path.exists("{0}.2".format(self.path)))
            log.write('')
            self.assertTrue(os.path.exists("{0}.1".format(self.path)))
            self.assertTrue(os.path.exists("{0}.2".format(self.path)))
            self.assertFalse(os.path.exists("{0}.3".format(self.path)))
            log.write("3")
            self.assertFalse(os.path.exists("{0}.3".format(self.path)))

            # test manual rotation
            log.rotate()
            self.assertTrue(os.path.exists("{0}.3".format(self.path)))
            self.assertFalse(os.path.exists("{0}.4".format(self.path)))

        self.assertEqual(log.listLogs(), [1, 2, 3])

        Rotating log files autorotate after a period of time, and can also be
        manually rotated.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_logfile.py