示例#1
0
    def test_output_from_a_separate_process_is_visible_after_it_exits(self) -> None:
        path = self.make_empty_file()
        with follow_log_file(path) as follower:
            env = dict(os.environ)
            env["file"] = str(path)
            subprocess.check_call(["sh", "-c", 'echo hello >>"${file}"'], env=env)

            self.assertEqual(follower.poll(), b"hello\n")
示例#2
0
    def test_file_yields_updates_after_concurrent_appends(self) -> None:
        path = self.make_empty_file()
        with follow_log_file(path) as follower:
            self.assertEqual(follower.poll(), b"")

            with open(path, "ab") as file:
                file.write(b"hello")
                file.flush()
                self.assertEqual(follower.poll(), b"hello")

                file.write(b"world")
                file.flush()
                self.assertEqual(follower.poll(), b"world")
示例#3
0
    def test_large_file_yields_one_update(self) -> None:
        file_size = 1024 * 1024
        path = self.make_empty_file()

        data = bytearray(file_size)
        data[0] = 100
        data[file_size // 2] = 101
        data[-1] = 102

        path.write_bytes(bytes(data))
        with follow_log_file(path) as follower:
            self.assertEqual(follower.poll(), data)
            self.assertEqual(follower.poll(), b"")
示例#4
0
 def test_nonempty_file_yields_one_update(self) -> None:
     path = self.make_empty_file()
     path.write_bytes(b"hello world")
     with follow_log_file(path) as follower:
         self.assertEqual(follower.poll(), b"hello world")
         self.assertEqual(follower.poll(), b"")
示例#5
0
 def test_empty_file_yields_no_updates(self) -> None:
     path = self.make_empty_file()
     with follow_log_file(path) as follower:
         self.assertEqual(follower.poll(), b"")
         self.assertEqual(follower.poll(), b"")