Example #1
0
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)
Example #2
0
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)
Example #3
0
def test_file_type():
    with pytest.raises(ValueError):
        biocxml.load(open(file, encoding='utf8'), None)

    with pytest.raises(ValueError):
        biocxml.loads('', None)
Example #4
0
def test_load():
    with open(file, encoding='utf8') as fp:
        collection = biocxml.load(fp)
    assert_everything(collection)
Example #5
0
import copy
from pathlib import Path

import pytest

from bioc import bioc, biocxml

file = Path(__file__).parent / 'everything.xml'
with open(file, encoding='utf8') as fp:
    collection = biocxml.load(fp)


def test_BioCLocation():
    base = bioc.BioCLocation(1, 10)
    assert base != 'foo'
    assert base.end == 11

    loc = bioc.BioCLocation(1, 10)
    assert base == loc

    loc = bioc.BioCLocation(2, 9)
    assert base != loc
    assert loc in base
    assert base not in loc

    locs = {base, loc}
    assert base in locs
    assert loc in locs

    with pytest.raises(TypeError):
        assert 'foo' in base
Example #6
0
def collection():
    file = Path(__file__).parent / 'everything.xml'
    with open(file, encoding='utf8') as fp:
        collection = biocxml.load(fp)
    return collection
Example #7
0
def _get_collection():
    file = Path(__file__).parent / 'everything_v2.xml'
    with open(file, encoding='utf8') as fp:
        return biocxml.load(fp, version=bioc.BioCVersion.V2)