mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
Add tests for formats
This commit is contained in:
parent
4943f36748
commit
39e95dc254
@ -855,10 +855,14 @@ class DB(object):
|
|||||||
ans = {}
|
ans = {}
|
||||||
if path is not None:
|
if path is not None:
|
||||||
stat = os.stat(path)
|
stat = os.stat(path)
|
||||||
|
ans['path'] = path
|
||||||
ans['size'] = stat.st_size
|
ans['size'] = stat.st_size
|
||||||
ans['mtime'] = utcfromtimestamp(stat.st_mtime)
|
ans['mtime'] = utcfromtimestamp(stat.st_mtime)
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
def has_format(self, book_id, fmt):
|
||||||
|
return self.format_abspath(book_id, fmt) is not None
|
||||||
|
|
||||||
def cover(self, path, as_file=False, as_image=False,
|
def cover(self, path, as_file=False, as_image=False,
|
||||||
as_path=False):
|
as_path=False):
|
||||||
path = os.path.join(self.library_path, path, 'cover.jpg')
|
path = os.path.join(self.library_path, path, 'cover.jpg')
|
||||||
|
@ -162,7 +162,7 @@ class Cache(object):
|
|||||||
if not formats:
|
if not formats:
|
||||||
good_formats = None
|
good_formats = None
|
||||||
else:
|
else:
|
||||||
mi.format_metadata = FormatMetadata(self, id, formats)
|
mi.format_metadata = FormatMetadata(self, book_id, formats)
|
||||||
good_formats = FormatsList(formats, mi.format_metadata)
|
good_formats = FormatsList(formats, mi.format_metadata)
|
||||||
mi.formats = good_formats
|
mi.formats = good_formats
|
||||||
mi.has_cover = _('Yes') if self._field_for('cover', book_id,
|
mi.has_cover = _('Yes') if self._field_for('cover', book_id,
|
||||||
|
@ -8,6 +8,7 @@ __copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
|
|||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import unittest, os, shutil
|
import unittest, os, shutil
|
||||||
|
from io import BytesIO
|
||||||
from future_builtins import map
|
from future_builtins import map
|
||||||
|
|
||||||
class BaseTest(unittest.TestCase):
|
class BaseTest(unittest.TestCase):
|
||||||
@ -22,6 +23,9 @@ class BaseTest(unittest.TestCase):
|
|||||||
db = LibraryDatabase2(library_path)
|
db = LibraryDatabase2(library_path)
|
||||||
db.set_cover(1, I('lt.png', data=True))
|
db.set_cover(1, I('lt.png', data=True))
|
||||||
db.set_cover(2, I('polish.png', data=True))
|
db.set_cover(2, I('polish.png', data=True))
|
||||||
|
db.add_format(1, 'FMT1', BytesIO(b'book1fmt1'), index_is_id=True)
|
||||||
|
db.add_format(1, 'FMT2', BytesIO(b'book1fmt2'), index_is_id=True)
|
||||||
|
db.add_format(2, 'FMT1', BytesIO(b'book2fmt1'), index_is_id=True)
|
||||||
return dest
|
return dest
|
||||||
|
|
||||||
def init_cache(self, library_path):
|
def init_cache(self, library_path):
|
||||||
@ -42,11 +46,9 @@ class BaseTest(unittest.TestCase):
|
|||||||
'ondevice_col', 'last_modified', 'has_cover',
|
'ondevice_col', 'last_modified', 'has_cover',
|
||||||
'cover_data'}.union(allfk1)
|
'cover_data'}.union(allfk1)
|
||||||
for attr in all_keys:
|
for attr in all_keys:
|
||||||
if attr == 'user_metadata': continue
|
if attr == 'user_metadata': continue # TODO:
|
||||||
if attr == 'format_metadata': continue # TODO: Not implemented yet
|
|
||||||
attr1, attr2 = getattr(mi1, attr), getattr(mi2, attr)
|
attr1, attr2 = getattr(mi1, attr), getattr(mi2, attr)
|
||||||
if attr == 'formats':
|
if attr == 'formats':
|
||||||
continue # TODO: Not implemented yet
|
|
||||||
attr1, attr2 = map(lambda x:tuple(x) if x else (), (attr1, attr2))
|
attr1, attr2 = map(lambda x:tuple(x) if x else (), (attr1, attr2))
|
||||||
self.assertEqual(attr1, attr2,
|
self.assertEqual(attr1, attr2,
|
||||||
'%s not the same: %r != %r'%(attr, attr1, attr2))
|
'%s not the same: %r != %r'%(attr, attr1, attr2))
|
||||||
|
@ -8,7 +8,6 @@ __copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
|
|||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import shutil, unittest, tempfile, datetime
|
import shutil, unittest, tempfile, datetime
|
||||||
from cStringIO import StringIO
|
|
||||||
|
|
||||||
from calibre.utils.date import utc_tz
|
from calibre.utils.date import utc_tz
|
||||||
from calibre.db.tests.base import BaseTest
|
from calibre.db.tests.base import BaseTest
|
||||||
@ -55,7 +54,7 @@ class ReadingTest(BaseTest):
|
|||||||
'#tags':(),
|
'#tags':(),
|
||||||
'#yesno':None,
|
'#yesno':None,
|
||||||
'#comments': None,
|
'#comments': None,
|
||||||
|
'size':None,
|
||||||
},
|
},
|
||||||
|
|
||||||
2 : {
|
2 : {
|
||||||
@ -66,7 +65,7 @@ class ReadingTest(BaseTest):
|
|||||||
'series' : 'A Series One',
|
'series' : 'A Series One',
|
||||||
'series_index': 1.0,
|
'series_index': 1.0,
|
||||||
'tags':('Tag One', 'Tag Two'),
|
'tags':('Tag One', 'Tag Two'),
|
||||||
'formats': (),
|
'formats': ('FMT1',),
|
||||||
'rating': 4.0,
|
'rating': 4.0,
|
||||||
'identifiers': {'test':'one'},
|
'identifiers': {'test':'one'},
|
||||||
'timestamp': datetime.datetime(2011, 9, 5, 21, 6,
|
'timestamp': datetime.datetime(2011, 9, 5, 21, 6,
|
||||||
@ -86,6 +85,7 @@ class ReadingTest(BaseTest):
|
|||||||
'#tags':('My Tag One', 'My Tag Two'),
|
'#tags':('My Tag One', 'My Tag Two'),
|
||||||
'#yesno':True,
|
'#yesno':True,
|
||||||
'#comments': '<div>My Comments One<p></p></div>',
|
'#comments': '<div>My Comments One<p></p></div>',
|
||||||
|
'size':9,
|
||||||
},
|
},
|
||||||
1 : {
|
1 : {
|
||||||
'title': 'Title Two',
|
'title': 'Title Two',
|
||||||
@ -96,7 +96,7 @@ class ReadingTest(BaseTest):
|
|||||||
'series_index': 2.0,
|
'series_index': 2.0,
|
||||||
'rating': 6.0,
|
'rating': 6.0,
|
||||||
'tags': ('Tag One', 'News'),
|
'tags': ('Tag One', 'News'),
|
||||||
'formats':(),
|
'formats':('FMT1', 'FMT2'),
|
||||||
'identifiers': {'test':'two'},
|
'identifiers': {'test':'two'},
|
||||||
'timestamp': datetime.datetime(2011, 9, 6, 6, 0,
|
'timestamp': datetime.datetime(2011, 9, 6, 6, 0,
|
||||||
tzinfo=utc_tz),
|
tzinfo=utc_tz),
|
||||||
@ -115,6 +115,7 @@ class ReadingTest(BaseTest):
|
|||||||
'#tags':('My Tag Two',),
|
'#tags':('My Tag Two',),
|
||||||
'#yesno':False,
|
'#yesno':False,
|
||||||
'#comments': '<div>My Comments Two<p></p></div>',
|
'#comments': '<div>My Comments Two<p></p></div>',
|
||||||
|
'size':9,
|
||||||
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -172,12 +173,6 @@ class ReadingTest(BaseTest):
|
|||||||
'Test get_metadata() returns the same data for both backends'
|
'Test get_metadata() returns the same data for both backends'
|
||||||
from calibre.library.database2 import LibraryDatabase2
|
from calibre.library.database2 import LibraryDatabase2
|
||||||
old = LibraryDatabase2(self.library_path)
|
old = LibraryDatabase2(self.library_path)
|
||||||
for i in xrange(1, 3):
|
|
||||||
old.add_format(i, 'txt%d'%i, StringIO(b'random%d'%i),
|
|
||||||
index_is_id=True)
|
|
||||||
old.add_format(i, 'text%d'%i, StringIO(b'random%d'%i),
|
|
||||||
index_is_id=True)
|
|
||||||
|
|
||||||
old_metadata = {i:old.get_metadata(
|
old_metadata = {i:old.get_metadata(
|
||||||
i, index_is_id=True, get_cover=True, cover_as_data=True) for i in
|
i, index_is_id=True, get_cover=True, cover_as_data=True) for i in
|
||||||
xrange(1, 4)}
|
xrange(1, 4)}
|
||||||
@ -229,8 +224,12 @@ class ReadingTest(BaseTest):
|
|||||||
# User categories
|
# User categories
|
||||||
'@Good Authors:One', '@Good Series.good tags:two',
|
'@Good Authors:One', '@Good Series.good tags:two',
|
||||||
|
|
||||||
# TODO: Tests for searching the size and #formats columns and
|
# Cover/Formats
|
||||||
# cover:true|false
|
'cover:true', 'cover:false', 'formats:true', 'formats:false',
|
||||||
|
'formats:#>1', 'formats:#=1', 'formats:=fmt1', 'formats:=fmt2',
|
||||||
|
'formats:=fmt1 or formats:fmt2', '#formats:true', '#formats:false',
|
||||||
|
'#formats:fmt1', '#formats:fmt2', '#formats:fmt1 and #formats:fmt2',
|
||||||
|
|
||||||
)}
|
)}
|
||||||
old = None
|
old = None
|
||||||
|
|
||||||
@ -264,7 +263,8 @@ class ReadingTest(BaseTest):
|
|||||||
(category == 'series' and attr == 'sort') or # Sorting is wrong in old
|
(category == 'series' and attr == 'sort') or # Sorting is wrong in old
|
||||||
(category == 'identifiers' and attr == 'id_set') or
|
(category == 'identifiers' and attr == 'id_set') or
|
||||||
(category == '@Good Series') or # Sorting is wrong in old
|
(category == '@Good Series') or # Sorting is wrong in old
|
||||||
(category == 'news' and attr in {'count', 'id_set'})
|
(category == 'news' and attr in {'count', 'id_set'}) or
|
||||||
|
(category == 'formats' and attr == 'id_set')
|
||||||
):
|
):
|
||||||
continue
|
continue
|
||||||
self.assertEqual(oval, nval,
|
self.assertEqual(oval, nval,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user