def test_writing(self):
        """
        Log files can be written to, flushed and closed. Closing a log file
        also flushes it.
        """
        with contextlib.closing(logfile.LogFile(self.name, self.dir)) as log:
            log.write("123")
            log.write("456")
            log.flush()
            log.write("7890")

        with open(self.path) as f:
            self.assertEqual(f.read(), "1234567890")

        Log files can be written to, flushed and closed. Closing a log file
        also flushes it.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_logfile.py