示例#1
0
文件: _epub.py 项目: kwinkunks/Objavi
def _test_spine_manifest_match():
    #every item in the spine should be in the manifest (thence in the zip, tested above)
    #every xhtml in the manifest should be in the spine. (XXX unless there are fallbacks)
    bad_spine_files = []
    for book in TEST_FILES:
        #print book
        spine, manifest, e = _get_elements(book, ('spine', 'manifest'))
        toc, order = epub.parse_spine(spine)
        pwd = os.path.dirname(e.opf_file)
        files = epub.parse_manifest(manifest, pwd)

        assert toc not in order
        xhtmls = set(order)
        for x in order:
            name, mimetype = files.pop(x)
            if mimetype != 'application/xhtml+xml':
                bad_spine_files.append((book, name, mimetype))

        name, mimetype = files.pop(toc)
        assert mimetype == 'application/x-dtbncx+xml'
        remaining = (x[1] for x in files.values())
        if any(x in ('application/x-dtbncx+xml', 'application/xhtml+xml') for x in remaining):
            print book, set(remaining)

        assert not any(x in ('application/x-dtbncx+xml', 'application/xhtml+xml') for x in remaining)

    if bad_spine_files:
        bsf = {}
        for book, fn, mt in bad_spine_files:
            mimecount = bsf.setdefault(book, {})
            mimecount[mt] = mimecount.get(mt, 0) + 1

        pprint(bsf)

        raise AssertionError('bad spine files in %s' % bsf.keys())
示例#2
0
文件: _epub.py 项目: kwinkunks/Objavi
def test_parse_spine():
    #every item in the spine should be a string
    # the toc should be a string
    #no duplicates
    for book in TEST_FILES:
        spine, e = _get_elements(book, ('spine',))
        toc, order = epub.parse_spine(spine)
        assert isinstance(order, (list, tuple))
        if not isinstance(toc, basestring):
            print book, toc, basestring

        assert isinstance(toc, basestring)
        assert all(isinstance(x, basestring) for x in order)
        assert len(order) == len(set(order))