~jaap.karssenberg/zim/pyzim-gtk3

« back to all changes in this revision

Viewing changes to tests/attachmentbrowser.py

  • Committer: Jaap Karssenberg
  • Date: 2014-03-08 11:47:43 UTC
  • mfrom: (668.1.49 pyzim-refactor)
  • Revision ID: jaap.karssenberg@gmail.com-20140308114743-fero6uvy9zirbb4o
Merge branch with refactoring

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
from zim.parsing import url_encode, URL_ENCODE_READABLE
8
8
from zim.plugins.attachmentbrowser import *
9
9
 
 
10
class TestMimeData(tests.TestCase):
 
11
 
 
12
        def runTest(self):
 
13
                dir = Dir('./data/pixmaps')
 
14
                for filename in dir.list():
 
15
                        file = dir.file(filename)
 
16
                        icon = get_mime_icon(file, THUMB_SIZE_NORMAL)
 
17
                        desc = get_mime_description(file.get_mimetype())
 
18
                        # TODO assert something on icon and text ?
 
19
 
10
20
 
11
21
class ThumbnailManagerTest(tests.TestCase):
12
22
 
13
 
        def runTest(self):
 
23
        def testCreateThumbnail(self):
14
24
                manager = ThumbnailManager(preferences={})
15
25
                dir = Dir('./data/pixmaps')
16
26
 
50
60
                        # TODO test detection of invalid thumbs
51
61
                        # TODO test with utf-8 char in image name
52
62
 
53
 
                        # Remove again and assert thumbnail does not exist
54
 
                        #~ manager.remove_thumbnails(file)
55
 
                        #~ for size in (THUMB_SIZE_NORMAL, THUMB_SIZE_LARGE):
56
 
                                #~ thumbfile = manager.get_thumbnail_file(file, size)
57
 
                                #~ self.assertFalse(thumbfile.exists(), msg="File exists: %s" % thumbfile)
58
 
 
59
 
                # Test ASync mode
60
 
                #~ wanted = set()
61
 
                #~ seen = {}
62
 
                #~ def callback(file, size, thumbnail):
63
 
                #~      seen[file] = thumbnail
64
 
 
65
 
                #~ for file in dir.list_objects():
66
 
                #~      manager.get_thumbnail_async(file, THUMB_SIZE_NORMAL, callback)
67
 
 
68
 
                #while queue:
69
 
                #       wait
70
 
 
71
 
                #~ for file in wanted:
72
 
                #~      assert file in seen
 
63
 
 
64
        def testAsyncCreateThumbnail(self):
 
65
                manager = ThumbnailManager(preferences={})
 
66
                dir = Dir('./data/pixmaps')
 
67
 
 
68
                seen = set()
 
69
                def on_thumbnail_ready(o, file, size, pixbuf):
 
70
                        seen.add(file)
 
71
                manager.connect('thumbnail-ready', on_thumbnail_ready)
 
72
 
 
73
                # Test API and functions
 
74
                #~ for file in dir.list_objects(): # TODO
 
75
                for filename in dir.list():
 
76
                        file = dir.file(filename)
 
77
 
 
78
                        # Remove and assert thumbnail does not exist
 
79
                        manager.remove_thumbnails(file)
 
80
                        for size in (THUMB_SIZE_NORMAL, THUMB_SIZE_LARGE):
 
81
                                manager.get_thumbnail_async(file, size)
 
82
 
 
83
                manager.async_queue.join()
 
84
                self.assertTrue(len(seen) > 3)
 
85