def test_title(self): # {{{ def rt(root): return read_title(root, read_prefixes(root), read_refines(root)) def st(root, title, title_sort=None): set_title(root, read_prefixes(root), read_refines(root), title, title_sort) return rt(root) root = self.get_opf('''<dc:title/><dc:title id='t'>xxx</dc:title>''') self.ae(rt(root), 'xxx') self.ae(st(root, 'abc', 'cba'), 'abc') self.ae(read_title_sort(root, read_prefixes(root), read_refines(root)), 'cba') root = self.get_opf('''<dc:title>yyy</dc:title><dc:title id='t'>x xx </dc:title><meta refines='#t' property='title-type'>main</meta><meta name="calibre:title_sort" content="sorted"/>''') self.ae(rt(root), 'x xx') self.ae(read_title_sort(root, read_prefixes(root), read_refines(root)), 'sorted') self.ae(st(root, 'abc'), 'abc')
def test_dates(self): # {{{ from calibre.utils.date import utcnow def rl(root): p, r = read_prefixes(root), read_refines(root) return read_pubdate(root, p, r), read_timestamp(root, p, r) def st(root, pd, ts): p, r = read_prefixes(root), read_refines(root) set_pubdate(root, p, r, pd) set_timestamp(root, p, r, ts) return rl(root) def ae(root, y1=None, y2=None): x1, x2 = rl(root) for x, y in ((x1, y1), (x2, y2)): if y is None: self.assertIsNone(x) else: self.ae(y, getattr(x, 'year', None)) root = self.get_opf('''<dc:date>1999-3-2</dc:date><meta property="calibre:timestamp" scheme="dcterms:W3CDTF">2001</meta>''') ae(root, 1999, 2001) n = utcnow() q = n.replace(microsecond=0) self.ae(st(root, n, n), (n, q)) root = self.get_opf('''<dc:date>1999-3-2</dc:date><meta name="calibre:timestamp" content="2001-1-1"/>''') ae(root, 1999, 2001) root = self.get_opf('''<meta property="dcterms:modified">2003</meta>''') self.ae(read_last_modified(root, read_prefixes(root), read_refines(root)).year, 2003)
def test_raster_cover(self): # {{{ def rt(root): return read_raster_cover(root, read_prefixes(root), read_refines(root)) root = self.get_opf('<meta name="cover" content="cover"/>', '<item id="cover" media-type="image/jpeg" href="x.jpg"/>') self.ae('x.jpg', rt(root)) root = self.get_opf('<meta name="cover" content="cover"/>', '<item id="cover" media-type="image/jpeg" href="x.jpg"/><item media-type="image/jpeg" href="y.jpg" properties="cover-image"/>') self.ae('y.jpg', rt(root)) ensure_is_only_raster_cover(root, read_prefixes(root), read_refines(root), 'x.jpg') self.ae('x.jpg', rt(root)) self.ae(['x.jpg'], root.xpath('//*[@properties="cover-image"]/@href')) self.assertFalse(root.xpath('//*[@name]'))
def upgrade_metadata(root): data = Data() data.prefixes = read_prefixes(root) data.refines = read_refines(root) upgrade_identifiers(root, data) upgrade_title(root, data) upgrade_languages(root, data) upgrade_authors(root, data) upgrade_timestamp(root, data) upgrade_date(root, data) upgrade_rating(root, data) upgrade_series(root, data) upgrade_custom(root, data) upgrade_meta(root, data) remove_invalid_attrs_in_dc_metadata(root, data) pretty_print_opf(root)
def upgrade_metadata(root): data = Data() data.prefixes = read_prefixes(root) data.refines = read_refines(root) upgrade_identifiers(root, data) upgrade_title(root, data) upgrade_languages(root, data) upgrade_authors(root, data) upgrade_timestamp(root, data) upgrade_date(root, data) upgrade_rating(root, data) upgrade_series(root, data) upgrade_custom(root, data) upgrade_meta(root, data) upgrade_cover(root, data) remove_invalid_attrs_in_dc_metadata(root, data) set_last_modified(root, data.prefixes, data.refines) pretty_print_opf(root)
def rt(root): return read_comments(root, read_prefixes(root), read_refines(root))
def rl(root): return read_pubdate(root, read_prefixes(root), read_refines(root)), read_timestamp(root, read_prefixes(root), read_refines(root))
def rl(root): return read_book_producers(root, read_prefixes(root), read_refines(root))
def su(root, val): set_user_metadata(root, read_prefixes(root), read_refines(root), val) return ru(root)
def st(root, val): set_tags(root, read_prefixes(root), read_refines(root), val) return rt(root)
def st(root, val, i): set_series(root, read_prefixes(root), read_refines(root), val, i) return rt(root)
def st(root, producers): set_book_producers(root, read_prefixes(root), read_refines(root), producers) return rl(root)
def rl(root): return read_authors(root, read_prefixes(root), read_refines(root))
def st(root, authors): set_authors(root, read_prefixes(root), read_refines(root), authors) return rl(root)
def st(root, languages): set_languages(root, read_prefixes(root), read_refines(root), languages) return rl(root)
def rl(root): return read_languages(root, read_prefixes(root), read_refines(root))
def st(root, title, title_sort=None): set_title(root, read_prefixes(root), read_refines(root), title, title_sort) return rt(root)
def rt(root): return read_publisher(root, read_prefixes(root), read_refines(root))
def rl(root): return read_pubdate(root, read_prefixes(root), read_refines(root)), read_timestamp( root, read_prefixes(root), read_refines(root))
def rl(root): p, r = read_prefixes(root), read_refines(root) return read_pubdate(root, p, r), read_timestamp(root, p, r)
def ru(root): return read_user_metadata(root, read_prefixes(root), read_refines(root))
def st(root, val): set_rating(root, read_prefixes(root), read_refines(root), val) return rt(root)
def st(root, name, val): f = globals()['set_' + name] f(root, read_prefixes(root), read_refines(root), val) return rt(root, name)
def st(root, pd, ts): set_pubdate(root, read_prefixes(root), read_refines(root), pd) set_timestamp(root, read_prefixes(root), read_refines(root), ts) return rl(root)
def st(root, val): set_comments(root, read_prefixes(root), read_refines(root), val) return rt(root)
def st(root, val): set_publisher(root, read_prefixes(root), read_refines(root), val) return rt(root)
def rt(root): return read_raster_cover(root, read_prefixes(root), read_refines(root))
def rt(root): return read_tags(root, read_prefixes(root), read_refines(root))
def rt(root): return read_rating(root, read_prefixes(root), read_refines(root))
def rt(root): return read_series(root, read_prefixes(root), read_refines(root))
def rt(root, name): f = globals()['read_' + name] return f(root, read_prefixes(root), read_refines(root))
def rt(root): return read_title(root, read_prefixes(root), read_refines(root))
def rt(root): return read_title(root, reserved_prefixes, read_refines(root))