Exemple #1
0
 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
Exemple #2
0
 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
Exemple #3
0
 def test_invalid(self, s):
     with pytest.raises(TypeError):
         _ = utils.to_bytes(s)
Exemple #4
0
 def test_valid(self, s):
     assert isinstance(utils.to_bytes(s), bytes)
Exemple #5
0
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)