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
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))
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))
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
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
def test_record_id(self): rec = Record(self.data) assert_equal(rec.record_id, "Doe J, 2016, J9, V4, P102, DOI 123")
def test_init(self): rec = Record(self.data, skip_empty=False) assert_equal(rec.skip_empty, False)
def test_record_author_address(data, record_id, author_address): rec = Record(data) assert rec.author_address == author_address
def test_record_id(data, record_id, author_address): rec = Record(data) assert rec.record_id == record_id
def test_record_parse(data, record_id, author_address): rec = Record() rec.parse(data) assert rec["PT"] == data["PT"] assert type(rec["AU"]) == list
def test_record_init(data, record_id, author_address): rec = Record(data, skip_empty=False) assert rec.skip_empty is False
def test_record_id(self): rec = Record(self.data) assert rec.record_id == "Doe J, 2016, J9, V4, P102, DOI 123"
def test_init(self): rec = Record(self.data, skip_empty=False) assert rec.skip_empty is False