def test_cat_dev_urandom(self, cat_env_fixture): """ test of cat (pseudo) device. """ stdin = io.StringIO() stdout_buf = CatLimitedBuffer(limit=500) stderr_buf = io.BytesIO() stdout = io.TextIOWrapper(stdout_buf) stderr = io.TextIOWrapper(stderr_buf) opts = cat._cat_parse_args([]) cat._cat_single_file(opts, "/dev/urandom", stdin, stdout, stderr) stdout.flush() stderr.flush() assert len(stdout_buf.getvalue()) >= 500
def test_cat_empty_file(self, cat_env_fixture): with open(self.tempfile, "w") as f: f.write("") stdin = io.StringIO() stdout_buf = io.BytesIO() stderr_buf = io.BytesIO() stdout = io.TextIOWrapper(stdout_buf) stderr = io.TextIOWrapper(stderr_buf) opts = cat._cat_parse_args([]) cat._cat_single_file(opts, self.tempfile, stdin, stdout, stderr) stdout.flush() stderr.flush() assert stdout_buf.getvalue() == b"" assert stderr_buf.getvalue() == b""
def test_cat_single_file_with_end_newline(self, cat_env_fixture): content = "this is a content withe \\n\nfor testing xoreutil's cat\n" with open(self.tempfile, "w") as f: f.write(content) expected_content = content.replace("\n", os.linesep) stdin = io.StringIO() stdout_buf = io.BytesIO() stderr_buf = io.BytesIO() stdout = io.TextIOWrapper(stdout_buf) stderr = io.TextIOWrapper(stderr_buf) opts = cat._cat_parse_args([]) cat._cat_single_file(opts, self.tempfile, stdin, stdout, stderr) stdout.flush() stderr.flush() assert stdout_buf.getvalue() == bytes(expected_content, "utf-8") assert stderr_buf.getvalue() == b""
def test_cat_single_file_work_exist_content(self, cat_env_fixture, content): with open(self.tempfile, "w") as f: f.write(content) expected_content = content.replace("\n", os.linesep) stdin = io.StringIO() stdout_buf = io.BytesIO() stderr_buf = io.BytesIO() stdout = io.TextIOWrapper(stdout_buf) stderr = io.TextIOWrapper(stderr_buf) opts = cat._cat_parse_args([]) cat._cat_single_file(opts, self.tempfile, stdin, stdout, stderr) stdout.flush() stderr.flush() assert stdout_buf.getvalue() == bytes(expected_content, "utf-8") assert stderr_buf.getvalue() == b""