def test_read_files():
    "Test that the system can read files."
    db = get_db_with_content()

    # Create the test files.
    test_file_fmt = 'test_reading_input.%s'
    example_files = []
    for fmt in [formats.TEXT, formats.XML]:
        tc = db.select_one(db.TextContent, db.TextContent.format == fmt)
        if tc is None:
            print("Could not find %s content for testing." % fmt)
            continue
        suffix = fmt
        if fmt is formats.XML:
            suffix = 'n' + fmt
        with open(test_file_fmt % suffix, 'wb') as f:
            f.write(zlib.decompress(tc.content, 16 + zlib.MAX_WBITS))
        example_files.append(test_file_fmt % suffix)

    # Now read them.
    readers = get_readers()
    outputs = read_files(example_files, readers)
    N_out = len(outputs)
    N_exp = len(example_files)
    assert N_out == N_exp, "Expected %d outputs, got %d." % (N_exp, N_out)
Exemple #2
0
def test_read_files():
    "Test that the system can read files."
    # Create the test files.
    example_files = []

    # Get txt content
    abstract_txt = ("This is a paper that contains the phrase: MEK "
                    "phosphorylates ERK.")
    with open('test_abstract.txt', 'w') as f:
        f.write(abstract_txt)
    example_files.append('test_abstract.txt')

    # Get nxml content
    pmc_test_fpath = path.join(path.dirname(path.abspath(__file__)),
                               'pmc_cont_example.nxml')
    if path.exists(pmc_test_fpath):
        example_files.append(pmc_test_fpath)

    assert len(example_files), "No content available to test."

    # Now read them.
    reader_classes = get_reader_classes()
    readers = []
    for rc in reader_classes:
        readers.append(rc())
    outputs = read_files(example_files, readers)
    N_out = len(outputs)
    proper_readers = [r for r in readers if not isinstance(r, EmptyReader)]
    N_exp = len(proper_readers) * len(example_files)
    assert N_out == N_exp, "Expected %d outputs, got %d." % (N_exp, N_out)
def test_read_files():
    "Test that the system can read files."
    # Create the test files.
    example_files = []

    # Get txt content
    abstract_txt = ("This is a paper that contains the phrase: MEK "
                    "phosphorylates ERK.")
    with open('test_abstract.txt', 'w') as f:
        f.write(abstract_txt)
    example_files.append('test_abstract.txt')

    # Get nxml content
    pmc_test_fpath = path.join(path.dirname(path.abspath(__file__)),
                               'pmc_cont_example.nxml')
    if path.exists(pmc_test_fpath):
        example_files.append(pmc_test_fpath)

    assert len(example_files), "No content available to test."

    # Now read them.
    reader_classes = get_reader_classes()
    readers = []
    for rc in reader_classes:
        readers.append(rc())
    outputs = read_files(example_files, readers)
    N_out = len(outputs)
    proper_readers = [r for r in readers if not isinstance(r, EmptyReader)]
    N_exp = len(proper_readers)*len(example_files)
    assert N_out == N_exp, "Expected %d outputs, got %d." % (N_exp, N_out)