def test_read_write_bytes(self, tmpdir): expected = utils.to_bytes(TEXT) for ext in (".txt", ".gz", ".bz2", ".xz"): filepath = str(tmpdir.join("test_read_write_file_bytes" + ext)) io.write_text(expected, filepath, mode="wb", make_dirs=True) observed = next(io.read_text(filepath, mode="rb")) assert observed == expected
def test_read_write_bytes_lines(self, tmpdir, spacy_doc): expected = [utils.to_bytes(sent.text) for sent in spacy_doc.sents] for ext in (".txt", ".gz", ".bz2", ".xz"): filepath = str( tmpdir.join("test_read_write_file_lines_bytes" + ext)) io.write_text(expected, filepath, mode="wb", make_dirs=True, lines=True) observed = [ line.strip() for line in io.read_text(filepath, mode="rb", lines=True) ] assert observed == expected
def test_invalid(self, s): with pytest.raises(TypeError): _ = utils.to_bytes(s)
def test_valid(self, s): assert isinstance(utils.to_bytes(s), bytes)
def test_to_bytes(): for obj in STRINGS: assert isinstance(utils.to_bytes(obj), bytes) for obj in NOT_STRINGS: with pytest.raises(TypeError): utils.to_bytes(obj)