Example #1
0
def test_record_skip_empty(data, record_id, author_address):
    rec = Record()
    rec.parse(data)
    assert "AB" not in rec

    rec.skip_empty = False
    rec.parse(data)
    assert "AB" in rec
Example #2
0
def test_records_from():
    data = b"""FN Thomson Reuters Web of Science\nVR 1.0
PT J\nAU John\nER
PT J\nAU Mary\nER\nEF"""

    _, fname = tempfile.mkstemp()
    with open(fname, "wb") as f:
        f.write(data)

    results = list(records_from(fname))
    expected = [{"PT": "J", "AU": "John"}, {"PT": "J", "AU": "Mary"}]
    for res, exp in zip(results, expected):
        assert_is_instance(res, Record)
        assert_equal(res, Record(exp))
Example #3
0
def test_records_from_multiple_files():
    data = [
        b"FN Thomson Reuters Web of Science\nVR 1.0\n"
        b"PT J\nAU John\nER\nEF",
        b"FN Thomson Reuters Web of Science\nVR 1.0\n"
        b"PT J\nAU Mary\nER\nEF",
    ]

    files = []
    for d in data:
        fd, fname = tempfile.mkstemp()
        with open(fname, "wb") as f:
            f.write(d)
        files.append((fd, fname))

    results = list(records_from([fname for _, fname in files]))
    expected = [{"PT": "J", "AU": "John"}, {"PT": "J", "AU": "Mary"}]
    for res, exp in zip(results, expected):
        assert_is_instance(res, Record)
        assert_equal(res, Record(exp))
Example #4
0
    def test_parse(self):
        rec = Record()
        rec.parse(self.data)

        assert dict(rec) == {
            "PT": "J",
            "AU": ["Doe, J", "Foo, B"],
            "C1": ["Univ Michigan", "Stanford Univ"],
            "TI": "Title here",
            "DE": ["desc1", "desc2", "desc3"],
            "PY": "2016",
            "J9": "J9",
            "BS": "BS",
            "SO": "SO",
            "VL": "4",
            "BP": "102",
            "DI": "123",
        }

        rec.skip_empty = False
        rec.parse(self.data)
        assert "AB" in rec
Example #5
0
    def test_parse(self):
        rec = Record()
        rec.parse(self.data)

        assert_equal(
            dict(rec),
            {
                "PT": "J",
                "AU": ["Doe, J", "Foo, B"],
                "TI": "Title here",
                "DE": ["desc1", "desc2", "desc3"],
                "PY": "2016",
                "J9": "J9",
                "BS": "BS",
                "SO": "SO",
                "VL": "4",
                "BP": "102",
                "DI": "123",
            },
        )

        rec.skip_empty = False
        rec.parse(self.data)
        assert "AB" in rec
Example #6
0
 def test_record_id(self):
     rec = Record(self.data)
     assert_equal(rec.record_id, "Doe J, 2016, J9, V4, P102, DOI 123")
Example #7
0
 def test_init(self):
     rec = Record(self.data, skip_empty=False)
     assert_equal(rec.skip_empty, False)
Example #8
0
def test_record_author_address(data, record_id, author_address):
    rec = Record(data)
    assert rec.author_address == author_address
Example #9
0
def test_record_id(data, record_id, author_address):
    rec = Record(data)
    assert rec.record_id == record_id
Example #10
0
def test_record_parse(data, record_id, author_address):
    rec = Record()
    rec.parse(data)
    assert rec["PT"] == data["PT"]
    assert type(rec["AU"]) == list
Example #11
0
def test_record_init(data, record_id, author_address):
    rec = Record(data, skip_empty=False)
    assert rec.skip_empty is False
Example #12
0
 def test_record_id(self):
     rec = Record(self.data)
     assert rec.record_id == "Doe J, 2016, J9, V4, P102, DOI 123"
Example #13
0
 def test_init(self):
     rec = Record(self.data, skip_empty=False)
     assert rec.skip_empty is False