コード例 #1
0
ファイル: logfile_test.py プロジェクト: zerkella/eden
 def test_forward_does_not_automatically_copy_existing_file_content(
         self) -> None:
     path = self.make_empty_file()
     path.write_bytes(b"hello world")
     output = io.BytesIO()
     with forward_log_file(path, output_file=output):
         self.assertEqual(output.getvalue(), b"")
コード例 #2
0
ファイル: logfile_test.py プロジェクト: zerkella/eden
 def test_forward_copies_existing_file_content_after_poll(self) -> None:
     path = self.make_empty_file()
     path.write_bytes(b"hello world")
     output = io.BytesIO()
     with forward_log_file(path, output_file=output) as forwarder:
         forwarder.poll()
         self.assertEqual(output.getvalue(), b"hello world")
コード例 #3
0
ファイル: logfile_test.py プロジェクト: simpkins/eden
 def test_forward_does_not_automatically_copy_concurrent_appends(self) -> None:
     path = self.make_empty_file()
     output = io.BytesIO()
     with forward_log_file(path, output_file=output):
         self.assertEqual(output.getvalue(), b"")
         with open(path, "ab") as file:
             file.write(b"hello")
             file.flush()
             self.assertEqual(output.getvalue(), b"")
コード例 #4
0
ファイル: logfile_test.py プロジェクト: zerkella/eden
 def test_polling_forward_flushes_output_buffer(self) -> None:
     path = self.make_empty_file()
     unbuffered_output = io.BytesIO()
     # HACK(strager): BufferedWriter requires RawIOBase, but BytesIO inherits
     # from IOBase, not RawIOBase. BufferedWriter seems to work fine with
     # BytesIO though, and CPython's test suite even covers this use case:
     # https://github.com/python/cpython/blob/v3.6.5/Lib/test/test_io.py#L1648-L1650
     raw_output = typing.cast(io.RawIOBase, unbuffered_output)
     buffered_output = io.BufferedWriter(raw_output, buffer_size=1024)
     with forward_log_file(path, output_file=buffered_output) as forwarder:
         with open(path, "ab") as file:
             file.write(b"hello")
             file.flush()
             forwarder.poll()
             self.assertEqual(unbuffered_output.getvalue(), b"hello")
コード例 #5
0
ファイル: logfile_test.py プロジェクト: zerkella/eden
    def test_polling_forward_copies_concurrent_appends(self) -> None:
        path = self.make_empty_file()
        output = io.BytesIO()
        with forward_log_file(path, output_file=output) as forwarder:
            self.assertEqual(output.getvalue(), b"")
            with open(path, "ab") as file:
                file.write(b"hello")
                file.flush()
                forwarder.poll()
                self.assertEqual(output.getvalue(), b"hello")

                file.write(b"world")
                file.flush()
                forwarder.poll()
                self.assertEqual(output.getvalue(), b"helloworld")