def test_write_logs(tmpdir): with open(str(tmpdir / "output.yaml"), "wb") as f_logs: with open(str(tmpdir / "output.idx"), "wb") as f_idx: write_logs(f_logs, f_idx, "hello world\n".encode("utf-8")) write_logs(f_logs, f_idx, "how are you?\n".encode("utf-8")) assert read_logs(str(tmpdir)) == "hello world\nhow are you?\n" # nosec assert size_logs(str(tmpdir)) == 25 # nosec with open(str(tmpdir / "output.idx"), "rb") as f_idx: assert f_idx.read(8) == b"\x00\x00\x00\x00\x00\x00\x00\x00" # nosec assert f_idx.read(8) == b"\x0c\x00\x00\x00\x00\x00\x00\x00" # nosec
def write(self, message): write_logs(self.output, self.index, (message + '\n').encode("utf-8"))