def test_read(tmp_path): data = preamble_b + b"PT J\nAU John Doe\nER\nEF" expected = {"PT": "J", "AU": "John Doe"} filename = tmp_path / "test_read" with open(filename, "wb") as f: f.write(data) for res in (list(read(filename)), list(read(filename, using=PlainTextReader))): assert len(res) == 1 assert res[0] == expected assert f.closed
def test_read(): data = preamble_b + b"PT J\nAU John Doe\nER\nEF" expected = {"PT": "J", "AU": "John Doe"} fd, fname = tempfile.mkstemp() with open(fname, "wb") as f: f.write(data) for res in (list(read(fname)), list(read(fname, using=PlainTextReader))): assert_equal(len(res), 1) assert_equal(res[0], expected) assert f.closed os.close(fd) os.unlink(fname)
def test_read_multiple_files(): data = [ preamble_b + b"PT J\nAU John Doe\nER\nEF", preamble_b + b"PT T\nAU Mary Stuart\nER\nEF", ] expected = [{ "PT": "J", "AU": "John Doe" }, { "PT": "T", "AU": "Mary Stuart" }] files = [] for d in data: fd, fname = tempfile.mkstemp() with open(fname, "wb") as f: f.write(d) files.append((fd, fname)) for rec, exp in zip(read([fname for _, fname in files]), expected): assert_equal(rec, exp) for fd, fname in files: os.close(fd) os.unlink(fname)
def test_read_actual_data(): for fname in ( "wos_plaintext.txt", "wos_tab_delimited_win_utf8.txt", "wos_tab_delimited_win_utf16.txt", ): for rec in read("data/" + fname): assert_no_bom(rec)
def test_read_multiple_files(tmp_path): data = [ preamble_b + b"PT J\nAU John Doe\nER\nEF", preamble_b + b"PT T\nAU Mary Stuart\nER\nEF", ] expected = [{"PT": "J", "AU": "John Doe"}, {"PT": "T", "AU": "Mary Stuart"}] files = [] for i, d in enumerate(data): fname = tmp_path / f"test_read_multiple_files{i}" with open(fname, "wb") as f: f.write(d) files.append(fname) for rec, exp in zip(read(files), expected): assert rec == exp