test_api.py 16.5 KB
Newer Older
Mark Smith's avatar
Mark Smith committed
1
import unittest
2
import random
Mark Smith's avatar
Mark Smith committed
3
import shutil
4
from time import sleep
Josh Roesslein's avatar
Josh Roesslein committed
5
import os
6

Joshua Roesslein's avatar
Joshua Roesslein committed
7
8
from nose import SkipTest

9
10
from tweepy import Friendship, MemoryCache, FileCache, API
from tweepy.parsers import Parser
Mark Smith's avatar
Mark Smith committed
11
from .config import TweepyTestCase, username, use_replay, tape
Josh Roesslein's avatar
Josh Roesslein committed
12

13
test_tweet_id = '266367358078169089'
14
tweet_text = 'testing 1000'
15

16
17
"""Unit tests"""

Mark Smith's avatar
Mark Smith committed
18

19
20
21
22
23
24
25
26
27
28
29
30
class TweepyErrorTests(unittest.TestCase):

    def testpickle(self):
        """Verify exceptions can be pickled and unpickled."""
        import pickle
        from tweepy.error import TweepError

        e = TweepError('no reason', {'status': 200})
        e2 = pickle.loads(pickle.dumps(e))

        self.assertEqual(e.reason, e2.reason)
        self.assertEqual(e.response, e2.response)
Josh Roesslein's avatar
Josh Roesslein committed
31

Mark Smith's avatar
Mark Smith committed
32

33
class TweepyAPITests(TweepyTestCase):
Josh Roesslein's avatar
Josh Roesslein committed
34

Miriam Sexton's avatar
Miriam Sexton committed
35
    # TODO: Actually have some sort of better assertion
Mark Smith's avatar
Mark Smith committed
36
    @tape.use_cassette('testgetoembed.json')
Miriam Sexton's avatar
Miriam Sexton committed
37
    def testgetoembed(self):
Miriam Sexton's avatar
Miriam Sexton committed
38
        data = self.api.get_oembed(test_tweet_id)
Miriam Sexton's avatar
Miriam Sexton committed
39
40
        self.assertEqual(data['author_name'], "Twitter")

Mark Smith's avatar
Mark Smith committed
41
    @tape.use_cassette('testparserargumenthastobeaparserinstance.json')
42
43
44
    def testparserargumenthastobeaparserinstance(self):
        """ Testing the issue https://github.com/tweepy/tweepy/issues/421"""
        self.assertRaises(TypeError, API, self.auth, parser=Parser)
Miriam Sexton's avatar
Miriam Sexton committed
45

Mark Smith's avatar
Mark Smith committed
46
    @tape.use_cassette('testhometimeline.json')
47
48
49
    def testhometimeline(self):
        self.api.home_timeline()

Mark Smith's avatar
Mark Smith committed
50
    @tape.use_cassette('testusertimeline.json')
Josh Roesslein's avatar
Josh Roesslein committed
51
    def testusertimeline(self):
52
53
        self.api.user_timeline()
        self.api.user_timeline('twitter')
Josh Roesslein's avatar
Josh Roesslein committed
54

Mark Smith's avatar
Mark Smith committed
55
    @tape.use_cassette('testmentionstimeline.json')
Joshua Roesslein's avatar
Joshua Roesslein committed
56
57
    def testmentionstimeline(self):
        self.api.mentions_timeline()
58

Mark Smith's avatar
Mark Smith committed
59
    @tape.use_cassette('testretweetsofme.json')
60
61
62
63
    def testretweetsofme(self):
        self.api.retweets_of_me()

    def testretweet(self):
Joshua Roesslein's avatar
Joshua Roesslein committed
64
65
        # TODO(josh): Need a way to get random tweets to retweet.
        raise SkipTest()
66

Mark Smith's avatar
Mark Smith committed
67
    @tape.use_cassette('testretweets.json')
68
    def testretweets(self):
69
        self.api.retweets(test_tweet_id)
70

Mark Smith's avatar
Mark Smith committed
71
    @tape.use_cassette('testretweeters.json')
Joshua Roesslein's avatar
Joshua Roesslein committed
72
73
74
    def testretweeters(self):
        self.api.retweeters(test_tweet_id)

Mark Smith's avatar
Mark Smith committed
75
    @tape.use_cassette('testgetstatus.json')
Josh Roesslein's avatar
Josh Roesslein committed
76
    def testgetstatus(self):
77
        self.api.get_status(id=test_tweet_id)
Josh Roesslein's avatar
Josh Roesslein committed
78

Mark Smith's avatar
Mark Smith committed
79
    @tape.use_cassette('testupdateanddestroystatus.json')
Josh Roesslein's avatar
Josh Roesslein committed
80
81
    def testupdateanddestroystatus(self):
        # test update
82
        text = tweet_text if use_replay else 'testing %i' % random.randint(0, 1000)
Josh Roesslein's avatar
Josh Roesslein committed
83
84
85
86
87
88
89
        update = self.api.update_status(status=text)
        self.assertEqual(update.text, text)

        # test destroy
        deleted = self.api.destroy_status(id=update.id)
        self.assertEqual(deleted.id, update.id)

90
91
92
93
94
95
96
97
98
99
100
    @tape.use_cassette('testupdateanddestroystatus.json')
    def testupdateanddestroystatuswithoutkwarg(self):
        # test update, passing text as a positional argument (#554)
        text = tweet_text if use_replay else 'testing %i' % random.randint(0, 1000)
        update = self.api.update_status(text)
        self.assertEqual(update.text, text)

        # test destroy
        deleted = self.api.destroy_status(id=update.id)
        self.assertEqual(deleted.id, update.id)

Mark Smith's avatar
Mark Smith committed
101
    @tape.use_cassette('testupdatestatuswithmedia.yaml', serializer='yaml')
102
103
    def testupdatestatuswithmedia(self):
        update = self.api.update_with_media('examples/banner.png', status=tweet_text)
Aaron Hill's avatar
Aaron Hill committed
104
        self.assertIn(tweet_text + ' http://t.co', update.text)
105

Mark Smith's avatar
Mark Smith committed
106
    @tape.use_cassette('testgetuser.json')
Josh Roesslein's avatar
Josh Roesslein committed
107
    def testgetuser(self):
108
109
110
111
        u = self.api.get_user('twitter')
        self.assertEqual(u.screen_name, 'twitter')

        u = self.api.get_user(783214)
Josh Roesslein's avatar
Josh Roesslein committed
112
113
        self.assertEqual(u.screen_name, 'twitter')

Mark Smith's avatar
Mark Smith committed
114
    @tape.use_cassette('testlookupusers.json')
115
116
117
118
119
120
    def testlookupusers(self):
        def check(users):
            self.assertEqual(len(users), 2)
        check(self.api.lookup_users(user_ids=[6844292, 6253282]))
        check(self.api.lookup_users(screen_names=['twitterapi', 'twitter']))

Mark Smith's avatar
Mark Smith committed
121
    @tape.use_cassette('testsearchusers.json')
122
123
124
    def testsearchusers(self):
        self.api.search_users('twitter')

Mark Smith's avatar
Mark Smith committed
125
    @tape.use_cassette('testsuggestedcategories.json')
126
127
128
    def testsuggestedcategories(self):
        self.api.suggested_categories()

Mark Smith's avatar
Mark Smith committed
129
    @tape.use_cassette('testsuggestedusers.json')
130
131
132
133
134
    def testsuggestedusers(self):
        categories = self.api.suggested_categories()
        if len(categories) != 0:
            self.api.suggested_users(categories[0].slug)

Mark Smith's avatar
Mark Smith committed
135
    @tape.use_cassette('testsuggesteduserstweets.json')
136
137
138
139
    def testsuggesteduserstweets(self):
        categories = self.api.suggested_categories()
        if len(categories) != 0:
            self.api.suggested_users_tweets(categories[0].slug)
140

Mark Smith's avatar
Mark Smith committed
141
    @tape.use_cassette('testme.json')
Josh Roesslein's avatar
Josh Roesslein committed
142
143
144
145
    def testme(self):
        me = self.api.me()
        self.assertEqual(me.screen_name, username)

Mark Smith's avatar
Mark Smith committed
146
    @tape.use_cassette('testdirectmessages.json')
Josh Roesslein's avatar
Josh Roesslein committed
147
    def testdirectmessages(self):
148
149
        self.api.direct_messages()

Mark Smith's avatar
Mark Smith committed
150
    @tape.use_cassette('testsentdirectmessages.json')
151
152
    def testsentdirectmessages(self):
        self.api.sent_direct_messages()
Josh Roesslein's avatar
Josh Roesslein committed
153

Mark Smith's avatar
Mark Smith committed
154
    @tape.use_cassette('testsendanddestroydirectmessage.json')
Josh Roesslein's avatar
Josh Roesslein committed
155
156
    def testsendanddestroydirectmessage(self):
        # send
Joshua Roesslein's avatar
Joshua Roesslein committed
157
        sent_dm = self.api.send_direct_message(username, text='test message')
Josh Roesslein's avatar
Josh Roesslein committed
158
159
160
161
162
163
164
165
166
167
168
        self.assertEqual(sent_dm.text, 'test message')
        self.assertEqual(sent_dm.sender.screen_name, username)
        self.assertEqual(sent_dm.recipient.screen_name, username)

        # destroy
        destroyed_dm = self.api.destroy_direct_message(sent_dm.id)
        self.assertEqual(destroyed_dm.text, sent_dm.text)
        self.assertEqual(destroyed_dm.id, sent_dm.id)
        self.assertEqual(destroyed_dm.sender.screen_name, username)
        self.assertEqual(destroyed_dm.recipient.screen_name, username)

Mark Smith's avatar
Mark Smith committed
169
    @tape.use_cassette('testcreatedestroyfriendship.json')
170
    def testcreatedestroyfriendship(self):
Josh Roesslein's avatar
Josh Roesslein committed
171
172
173
        enemy = self.api.destroy_friendship('twitter')
        self.assertEqual(enemy.screen_name, 'twitter')

174
175
176
177
        # Wait 5 seconds to allow Twitter time
        # to process the friendship destroy request.
        sleep(5)

178
179
180
        friend = self.api.create_friendship('twitter')
        self.assertEqual(friend.screen_name, 'twitter')

Mark Smith's avatar
Mark Smith committed
181
    @tape.use_cassette('testshowfriendship.json')
Josh Roesslein's avatar
Josh Roesslein committed
182
    def testshowfriendship(self):
Joshua Roesslein's avatar
Joshua Roesslein committed
183
        source, target = self.api.show_friendship(target_screen_name='twitter')
Josh Roesslein's avatar
Josh Roesslein committed
184
185
186
        self.assert_(isinstance(source, Friendship))
        self.assert_(isinstance(target, Friendship))

Mark Smith's avatar
Mark Smith committed
187
    @tape.use_cassette('testfriendsids.json')
188
189
190
    def testfriendsids(self):
        self.api.friends_ids(username)

Mark Smith's avatar
Mark Smith committed
191
    @tape.use_cassette('testfollowersids.json')
192
193
194
    def testfollowersids(self):
        self.api.followers_ids(username)

Mark Smith's avatar
Mark Smith committed
195
    @tape.use_cassette('testfriends.json')
196
197
198
    def testfriends(self):
        self.api.friends(username)

Mark Smith's avatar
Mark Smith committed
199
    @tape.use_cassette('testfollowers.json')
200
201
202
    def testfollowers(self):
        self.api.followers(username)

Mark Smith's avatar
Mark Smith committed
203
    @tape.use_cassette('testverifycredentials.json')
204
    def testverifycredentials(self):
205
        self.assertNotEqual(self.api.verify_credentials(), False)
206

207
208
209
210
211
212
213
214
        # make sure that `me.status.entities` is not an empty dict
        me = self.api.verify_credentials(include_entities=True)
        self.assertTrue(me.status.entities)

        # `status` shouldn't be included
        me = self.api.verify_credentials(skip_status=True)
        self.assertFalse(hasattr(me, 'status'))

Mark Smith's avatar
Mark Smith committed
215
    @tape.use_cassette('testratelimitstatus.json')
216
217
218
    def testratelimitstatus(self):
        self.api.rate_limit_status()

219
    """ TODO(josh): Remove once this deprecated API is gone.
220
221
222
    def testsetdeliverydevice(self):
        self.api.set_delivery_device('im')
        self.api.set_delivery_device('none')
223
    """
224

Mark Smith's avatar
Mark Smith committed
225
    @tape.use_cassette('testupdateprofilecolors.json')
226
227
    def testupdateprofilecolors(self):
        original = self.api.me()
Josh Roesslein's avatar
Josh Roesslein committed
228
        updated = self.api.update_profile_colors('000', '000', '000', '000', '000')
229
230
231
232
233
234
235
236
237
238

        # restore colors
        self.api.update_profile_colors(
            original.profile_background_color,
            original.profile_text_color,
            original.profile_link_color,
            original.profile_sidebar_fill_color,
            original.profile_sidebar_border_color
        )

Joshua Roesslein's avatar
Joshua Roesslein committed
239
240
241
242
243
        self.assertEqual(updated.profile_background_color, '000000')
        self.assertEqual(updated.profile_text_color, '000000')
        self.assertEqual(updated.profile_link_color, '000000')
        self.assertEqual(updated.profile_sidebar_fill_color, '000000')
        self.assertEqual(updated.profile_sidebar_border_color, '000000')
244

245
    """
246
247
248
249
250
    def testupateprofileimage(self):
        self.api.update_profile_image('examples/profile.png')

    def testupdateprofilebg(self):
        self.api.update_profile_background_image('examples/bg.png')
251
    """
252

Mark Smith's avatar
Mark Smith committed
253
    @tape.use_cassette('testupdateprofilebannerimage.yaml', serializer='yaml')
254
255
256
    def testupdateprofilebannerimage(self):
        self.api.update_profile_banner('examples/banner.png')

Mark Smith's avatar
Mark Smith committed
257
    @tape.use_cassette('testupdateprofile.json')
258
259
260
261
262
263
264
265
266
    def testupdateprofile(self):
        original = self.api.me()
        profile = {
            'name': 'Tweepy test 123',
            'location': 'pytopia',
            'description': 'just testing things out'
        }
        updated = self.api.update_profile(**profile)
        self.api.update_profile(
267
            name = original.name, url = original.url,
268
269
270
271
            location = original.location, description = original.description
        )

        for k,v in profile.items():
Josh Roesslein's avatar
Josh Roesslein committed
272
            if k == 'email': continue
273
274
            self.assertEqual(getattr(updated, k), v)

Mark Smith's avatar
Mark Smith committed
275
    @tape.use_cassette('testfavorites.json')
276
277
278
    def testfavorites(self):
        self.api.favorites()

Mark Smith's avatar
Mark Smith committed
279
    @tape.use_cassette('testcreatedestroyfavorite.json')
280
    def testcreatedestroyfavorite(self):
Josh Roesslein's avatar
Josh Roesslein committed
281
282
        self.api.create_favorite(4901062372)
        self.api.destroy_favorite(4901062372)
283

Mark Smith's avatar
Mark Smith committed
284
    @tape.use_cassette('testcreatedestroyblock.json')
285
286
287
    def testcreatedestroyblock(self):
        self.api.create_block('twitter')
        self.api.destroy_block('twitter')
Josh Roesslein's avatar
Josh Roesslein committed
288
        self.api.create_friendship('twitter') # restore
289

Mark Smith's avatar
Mark Smith committed
290
    @tape.use_cassette('testblocks.json')
291
292
293
    def testblocks(self):
        self.api.blocks()

Mark Smith's avatar
Mark Smith committed
294
    @tape.use_cassette('testblocksids.json')
295
296
297
    def testblocksids(self):
        self.api.blocks_ids()

Joshua Roesslein's avatar
Joshua Roesslein committed
298
299
300
301
302
303
304
305
306
307
    # TODO: Rewrite test to be less brittle. It fails way too often.
    # def testcreateupdatedestroylist(self):
    #     params = {
    #         'owner_screen_name': username,
    #         'slug': 'tweeps'
    #     }
    #     l = self.api.create_list(name=params['slug'], **params)
    #     l = self.api.update_list(list_id=l.id, description='updated!')
    #     self.assertEqual(l.description, 'updated!')
    #     self.api.destroy_list(list_id=l.id)
Josh Roesslein's avatar
Josh Roesslein committed
308

Mark Smith's avatar
Mark Smith committed
309
    @tape.use_cassette('testlistsall.json')
Joshua Roesslein's avatar
Joshua Roesslein committed
310
311
    def testlistsall(self):
        self.api.lists_all()
Josh Roesslein's avatar
Josh Roesslein committed
312

Mark Smith's avatar
Mark Smith committed
313
    @tape.use_cassette('testlistsmemberships.json')
Josh Roesslein's avatar
Josh Roesslein committed
314
315
316
    def testlistsmemberships(self):
        self.api.lists_memberships()

Mark Smith's avatar
Mark Smith committed
317
    @tape.use_cassette('testlistssubscriptions.json')
Josh Roesslein's avatar
Josh Roesslein committed
318
319
320
    def testlistssubscriptions(self):
        self.api.lists_subscriptions()

Mark Smith's avatar
Mark Smith committed
321
    @tape.use_cassette('testlisttimeline.json')
Josh Roesslein's avatar
Josh Roesslein committed
322
    def testlisttimeline(self):
Joshua's avatar
Joshua committed
323
        self.api.list_timeline('applepie', 'stars')
Josh Roesslein's avatar
Josh Roesslein committed
324

Mark Smith's avatar
Mark Smith committed
325
    @tape.use_cassette('testgetlist.json')
Josh Roesslein's avatar
Josh Roesslein committed
326
    def testgetlist(self):
Joshua Roesslein's avatar
Joshua Roesslein committed
327
        self.api.get_list(owner_screen_name='applepie', slug='stars')
Josh Roesslein's avatar
Josh Roesslein committed
328

Mark Smith's avatar
Mark Smith committed
329
    @tape.use_cassette('testaddremovelistmember.json')
Josh Roesslein's avatar
Josh Roesslein committed
330
    def testaddremovelistmember(self):
331
332
333
334
335
336
337
338
339
340
        params = {
            'slug': 'test',
            'owner_screen_name': username,
            'screen_name': 'twitter'
        }

        def assert_list(l):
            self.assertEqual(l.name, params['slug'])

        assert_list(self.api.add_list_member(**params))
341
        sleep(3)
342
        assert_list(self.api.remove_list_member(**params))
Josh Roesslein's avatar
Josh Roesslein committed
343

Mark Smith's avatar
Mark Smith committed
344
    @tape.use_cassette('testaddremovelistmembers.json')
345
346
347
348
    def testaddremovelistmembers(self):
        params = {
            'slug': 'test',
            'owner_screen_name': username,
kk6's avatar
kk6 committed
349
            'screen_name': ['twitterapi', 'twittermobile']
350
351
352
353
354
355
356
357
        }

        def assert_list(l):
            self.assertEqual(l.name, params['slug'])

        assert_list(self.api.add_list_members(**params))
        assert_list(self.api.remove_list_members(**params))

Mark Smith's avatar
Mark Smith committed
358
    @tape.use_cassette('testlistmembers.json')
Josh Roesslein's avatar
Josh Roesslein committed
359
    def testlistmembers(self):
Joshua's avatar
Joshua committed
360
        self.api.list_members('applepie', 'stars')
Josh Roesslein's avatar
Josh Roesslein committed
361

Mark Smith's avatar
Mark Smith committed
362
    @tape.use_cassette('testshowlistmember.json')
Joshua Roesslein's avatar
Joshua Roesslein committed
363
364
    def testshowlistmember(self):
        self.assertTrue(self.api.show_list_member(owner_screen_name='applepie', slug='stars', screen_name='NathanFillion'))
Josh Roesslein's avatar
Josh Roesslein committed
365

Mark Smith's avatar
Mark Smith committed
366
    @tape.use_cassette('testsubscribeunsubscribelist.json')
Josh Roesslein's avatar
Josh Roesslein committed
367
    def testsubscribeunsubscribelist(self):
Joshua Roesslein's avatar
Joshua Roesslein committed
368
369
370
371
372
373
        params = {
            'owner_screen_name': 'applepie',
            'slug': 'stars'
        }
        self.api.subscribe_list(**params)
        self.api.unsubscribe_list(**params)
Josh Roesslein's avatar
Josh Roesslein committed
374

Mark Smith's avatar
Mark Smith committed
375
    @tape.use_cassette('testlistsubscribers.json')
Josh Roesslein's avatar
Josh Roesslein committed
376
    def testlistsubscribers(self):
Joshua's avatar
Joshua committed
377
        self.api.list_subscribers('applepie', 'stars')
Josh Roesslein's avatar
Josh Roesslein committed
378

Mark Smith's avatar
Mark Smith committed
379
    @tape.use_cassette('testshowlistsubscriber.json')
Joshua Roesslein's avatar
Joshua Roesslein committed
380
    def testshowlistsubscriber(self):
Joshua Roesslein's avatar
Joshua Roesslein committed
381
        self.assertTrue(self.api.show_list_subscriber('tweepytest', 'test', 'applepie'))
Josh Roesslein's avatar
Josh Roesslein committed
382

Mark Smith's avatar
Mark Smith committed
383
    @tape.use_cassette('testsavedsearches.json')
384
385
386
    def testsavedsearches(self):
        s = self.api.create_saved_search('test')
        self.api.saved_searches()
Josh Roesslein's avatar
Josh Roesslein committed
387
        self.assertEqual(self.api.get_saved_search(s.id).query, 'test')
388
389
        self.api.destroy_saved_search(s.id)

Mark Smith's avatar
Mark Smith committed
390
    @tape.use_cassette('testsearch.json')
391
    def testsearch(self):
Josh Roesslein's avatar
Josh Roesslein committed
392
        self.api.search('tweepy')
393

Mark Smith's avatar
Mark Smith committed
394
    @tape.use_cassette('testgeoapis.json')
395
    def testgeoapis(self):
396
397
398
399
        def place_name_in_list(place_name, place_list):
            """Return True if a given place_name is in place_list."""
            return any([x.full_name.lower() == place_name.lower() for x in place_list])

400
401
        twitter_hq = self.api.geo_similar_places(lat='37.7821120598956',
                                                 long='-122.400612831116',
Mark Smith's avatar
Mark Smith committed
402
                                                 name='South of Market Child Care')
403
        # Assumes that twitter_hq is first Place returned...
404
        self.assertEqual(twitter_hq[0].id, '1d019624e6b4dcff')
405
        # Test various API functions using Austin, TX, USA
Mark Smith's avatar
Mark Smith committed
406
        self.assertEqual(self.api.geo_id(id='1ffd3558f2e98349').full_name, 'Dogpatch, San Francisco')
407
408
        self.assertTrue(place_name_in_list('Austin, TX',
            self.api.reverse_geocode(lat=30.267370168467806, long= -97.74261474609375))) # Austin, TX, USA
409

Mark Smith's avatar
Mark Smith committed
410
    @tape.use_cassette('testsupportedlanguages.json')
411
412
413
414
415
416
417
418
419
    def testsupportedlanguages(self):
        languages = self.api.supported_languages()
        expected_dict = {
            "name": "English",
            "code": "en",
            "status": "production"
        }
        self.assertTrue(expected_dict in languages)

Mark Smith's avatar
Mark Smith committed
420
    @tape.use_cassette('testcachedresult.json')
Joshua Roesslein's avatar
Joshua Roesslein committed
421
422
423
424
425
426
427
    def testcachedresult(self):
        self.api.cache = MemoryCache()
        self.api.home_timeline()
        self.assertFalse(self.api.cached_result)
        self.api.home_timeline()
        self.assertTrue(self.api.cached_result)

428

Mark Smith's avatar
Mark Smith committed
429
class TweepyCacheTests(unittest.TestCase):
Josh Roesslein's avatar
Josh Roesslein committed
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
    timeout = 2.0
    memcache_servers = ['127.0.0.1:11211']  # must be running for test to pass

    def _run_tests(self, do_cleanup=True):
        # test store and get
        self.cache.store('testkey', 'testvalue')
        self.assertEqual(self.cache.get('testkey'), 'testvalue',
            'Stored value does not match retrieved value')

        # test timeout
        sleep(self.timeout)
        self.assertEqual(self.cache.get('testkey'), None,
            'Cache entry should have expired')

        # test cleanup
        if do_cleanup:
            self.cache.store('testkey', 'testvalue')
            sleep(self.timeout)
            self.cache.cleanup()
            self.assertEqual(self.cache.count(), 0, 'Cache cleanup failed')

        # test count
        for i in range(0, 20):
            self.cache.store('testkey%i' % i, 'testvalue')
        self.assertEqual(self.cache.count(), 20, 'Count is wrong')

        # test flush
        self.cache.flush()
        self.assertEqual(self.cache.count(), 0, 'Cache failed to flush')

    def testmemorycache(self):
        self.cache = MemoryCache(timeout=self.timeout)
        self._run_tests()

    def testfilecache(self):
        os.mkdir('cache_test_dir')
Mark Smith's avatar
Mark Smith committed
466
467
468
469
470
471
472
473
        try:
            self.cache = FileCache('cache_test_dir', self.timeout)
            self._run_tests()
            self.cache.flush()
        finally:
            if os.path.exists('cache_test_dir'):
                shutil.rmtree('cache_test_dir')

474

475
if __name__ == '__main__':
Josh Roesslein's avatar
Josh Roesslein committed
476
    unittest.main()