def test_iterreader_sentence(): with open(file, encoding='utf8') as fp: collection = biocjson.load(fp) s = io.StringIO() with biocjson.iterwriter(s) as writer: for sen in collection.documents[1].passages[0].sentences: writer.write(sen) del collection.documents[1].passages[0].sentences[:] with pytest.raises(IndexError): assert_everything(collection) with biocjson.iterreader(io.StringIO(s.getvalue())) as reader: for obj in reader: collection.documents[1].passages[0].add_sentence(obj) assert_everything(collection) # # # def test_level(): # with pytest.raises(ValueError): # BioCJsonIterReader(io.StringIO(), level=-1)
def test_dump(): collection = _get_collection() tmp = tempfile.mktemp() with open(tmp, 'w', encoding='utf8') as fp: biocxml.dump(collection, fp) with open(tmp, encoding='utf8') as fp: collection = biocxml.load(fp) assert_everything(collection)
def test_dump(): with open(file, encoding='utf8') as fp: collection = bioc.load(fp, BioCFileType.BIOC_JSON) tmp = tempfile.mktemp() with open(tmp, 'w', encoding='utf8') as fp: bioc.dump(collection, fp, BioCFileType.BIOC_JSON) with open(tmp, encoding='utf8') as fp: collection = bioc.load(fp, BioCFileType.BIOC_JSON) assert_everything(collection)
def test_dump(): with open(file, encoding='utf8') as fp: collection = biocjson.load(fp) tmp = tempfile.mktemp() with open(tmp, 'w', encoding='utf8') as fp: biocjson.dump(collection, fp) with open(tmp, encoding='utf8') as fp: collection = biocjson.load(fp) assert_everything(collection)
def test_dump(tmp_path): with open(file, encoding='utf8') as fp: collection = biocjson.load(fp) filepath = tmp_path / 'foo.json' with open(filepath, 'w', encoding='utf8') as fp: biocjson.dump(collection, fp) with open(filepath, encoding='utf8') as fp: collection = biocjson.load(fp) assert_everything(collection)
def test_iterwrite_io(): collection = _get_collection() f = io.BytesIO() with biocxml.iterwrite(f) as writer: writer.write_collection_info(collection) for document in collection.documents: writer.write_document(document) collection = biocxml.loads(f.getvalue().decode('utf-8')) assert_everything(collection)
def test_BioCXMLDocumentWriter_io(): collection = _get_collection() f = io.BytesIO() writer = bioc.BioCXMLDocumentWriter(f) writer.write_collection_info(collection) for document in collection.documents: writer.write_document(document) writer.close() collection = bioc.loads(f.getvalue().decode('utf-8')) assert_everything(collection)
def test_iterparse(): with biocxml.iterparse(open(file, 'rb')) as reader: collection = reader.get_collection_info() for document in reader: collection.add_document(document) assert_everything(collection) with biocxml.iterparse(str(file)) as reader: collection = reader.get_collection_info() for document in reader: collection.add_document(document) assert_everything(collection)
def test_BioCXMLDocumentReader(): with open(file, 'rb') as fp: reader = bioc.BioCXMLDocumentReader(fp) collection = reader.get_collection_info() for document in reader: collection.add_document(document) assert_everything(collection) reader = bioc.BioCXMLDocumentReader(str(file)) collection = reader.get_collection_info() for document in reader: collection.add_document(document) assert_everything(collection)
def test_iterwrite_file(): collection = _get_collection() tmp = tempfile.mktemp() with biocxml.iterwrite(tmp) as writer: writer.write_collection_info(collection) for document in collection.documents: writer.write_document(document) with open(tmp, encoding='utf8') as fp: collection = biocxml.load(fp) assert_everything(collection)
def test_jsoniterwriter(tmp_path): with open(file, encoding='utf8') as fp: collection = biocjson.load(fp) filepath = tmp_path / 'foo.json' with biocjson.iterwriter(filepath) as writer: for doc in collection.documents: writer.write(doc) del collection.documents[:] with biocjson.iterreader(filepath) as reader: for doc in reader: collection.add_document(doc) assert_everything(collection)
def test_iterreader_passage(): with open(file, encoding='utf8') as fp: collection = biocjson.load(fp) s = io.StringIO() with biocjson.iterwriter(s) as writer: for p in collection.documents[0].passages: writer.write(p) del collection.documents[0].passages[:] with pytest.raises(IndexError): assert_everything(collection) with biocjson.iterreader(io.StringIO(s.getvalue())) as reader: for obj in reader: collection.documents[0].add_passage(obj) assert_everything(collection)
def test_BioCJsonIterReader_sentence(): with open(file, encoding='utf8') as fp: collection = biocjson.load(fp) s = io.StringIO() writer = BioCJsonIterWriter(s, level=bioc.SENTENCE) for sen in collection.documents[1].passages[0].sentences: writer.write(sen) del collection.documents[1].passages[0].sentences[:] with pytest.raises(IndexError): assert_everything(collection) reader = BioCJsonIterReader(io.StringIO(s.getvalue()), level=bioc.SENTENCE) for obj in reader: collection.documents[1].passages[0].add_sentence(obj) assert_everything(collection)
def test_BioCJsonIterReader_document(): with open(file, encoding='utf8') as fp: collection = biocjson.load(fp) s = io.StringIO() writer = BioCJsonIterWriter(s, level=bioc.DOCUMENT) for doc in collection.documents: writer.write(doc) del collection.documents[:] with pytest.raises(IndexError): assert_everything(collection) reader = BioCJsonIterReader(io.StringIO(s.getvalue()), level=bioc.DOCUMENT) for obj in reader: collection.add_document(obj) assert_everything(collection)
def test_dumps(): with open(file, encoding='utf8') as fp: collection = biocjson.load(fp) s = biocjson.dumps(collection) collection = biocjson.loads(s) assert_everything(collection)
def test_loads(): with open(file, encoding='utf8') as fp: s = fp.read() collection = biocxml.loads(s) assert_everything(collection)
def test_load(): with open(file, encoding='utf8') as fp: collection = biocxml.load(fp) assert_everything(collection)
def test_pretty_print(): tmp = tempfile.mktemp() bioc.pretty_print(file, tmp) with open(tmp, encoding='utf8') as fp: collection = bioc.load(fp) assert_everything(collection)
def test_dumps(): with open(file, encoding='utf8') as fp: collection = bioc.load(fp, BioCFileType.BIOC_JSON) s = bioc.dumps(collection, BioCFileType.BIOC_JSON) collection = bioc.loads(s, BioCFileType.BIOC_JSON) assert_everything(collection)
def test_dumps(): collection = _get_collection() s = biocxml.dumps(collection, version=bioc.BioCVersion.V2) collection = biocxml.loads(s, version=bioc.BioCVersion.V2) assert_everything(collection)
def test_dumps(): collection = _get_collection() s = biocxml.dumps(collection) collection = biocxml.loads(s) assert_everything(collection)