Example #1
0
def test_read():
    data = preamble_b + b"PT J\nAU John Doe\nER\nEF"
    expected = {"PT": "J", "AU": "John Doe"}

    import tempfile
    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)
Example #2
0
def test_read():
    data = preamble_b + b"PT J\nAU John Doe\nER\nEF"
    expected = {"PT": "J", "AU": "John Doe"}

    import tempfile
    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)
Example #3
0
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"
    }]

    import tempfile
    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)
Example #4
0
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"}]

    import tempfile
    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)
Example #5
0
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)