http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11697
Revision: 11697 Author: legoktm Date: 2013-06-28 02:24:51 +0000 (Fri, 28 Jun 2013) Log Message: ----------- Convert to use unittests module
Modified Paths: -------------- branches/rewrite/tests/dry_api_tests.py
Modified: branches/rewrite/tests/dry_api_tests.py =================================================================== --- branches/rewrite/tests/dry_api_tests.py 2013-06-28 02:09:18 UTC (rev 11696) +++ branches/rewrite/tests/dry_api_tests.py 2013-06-28 02:24:51 UTC (rev 11697) @@ -1,40 +1,41 @@ import datetime import pywikibot from pywikibot.data.api import CachedRequest +import unittest
-parms = {'site': pywikibot.getSite('en'), - 'action': 'query', - 'meta': 'userinfo'}
-req = CachedRequest(expiry=1, **parms) -expreq = CachedRequest(expiry=0, **parms) -diffreq = CachedRequest(expiry=1, site=pywikibot.getSite('en'), action='query', meta='siteinfo') -diffsite = CachedRequest(expiry=1, site=pywikibot.getSite('de'), action='query', meta='userinfo') +class DryAPITests(unittest.TestCase):
+ def setUp(self): + self.parms = {'site': pywikibot.Site('en'), + 'action': 'query', + 'meta': 'userinfo'} + self.req = CachedRequest(expiry=1, **self.parms) + self.expreq = CachedRequest(expiry=0, **self.parms) + self.diffreq = CachedRequest(expiry=1, site=pywikibot.Site('en'), action='query', meta='siteinfo') + self.diffsite = CachedRequest(expiry=1, site=pywikibot.Site('de'), action='query', meta='userinfo')
-def test_expiry_formats(): - import datetime - assert(req.expiry == CachedRequest(datetime.timedelta(days=1), **parms).expiry) + def test_expiry_formats(self): + self.assertEqual(self.req.expiry, CachedRequest(datetime.timedelta(days=1), **self.parms).expiry)
+ def test_get_cache_dir(self): + retval = self.req._get_cache_dir() + self.assertIn('apicache', retval)
-def test_get_cache_dir(): - retval = req._get_cache_dir() - assert('apicache' in retval) + def test_create_file_name(self): + self.assertEqual(self.req._create_file_name(), self.req._create_file_name()) + self.assertEqual(self.req._create_file_name(), self.expreq._create_file_name()) + self.assertNotEqual(self.req._create_file_name(), self.diffreq._create_file_name())
+ def test_cachefile_path(self): + self.assertEqual(self.req._cachefile_path(), self.req._cachefile_path()) + self.assertEqual(self.req._cachefile_path(), self.expreq._cachefile_path()) + self.assertNotEqual(self.req._cachefile_path(), self.diffreq._cachefile_path()) + self.assertNotEqual(self.req._cachefile_path(), self.diffsite._cachefile_path())
-def test_create_file_name(): - assert(req._create_file_name() == req._create_file_name()) - assert(req._create_file_name() == expreq._create_file_name()) - assert(req._create_file_name() != diffreq._create_file_name()) + def test_expired(self): + self.assertFalse(self.req._expired(datetime.datetime.now())) + self.assertTrue(self.req._expired(datetime.datetime.now() - datetime.timedelta(days=2)))
- -def test_cachefile_path(): - assert(req._cachefile_path() == req._cachefile_path()) - assert(req._cachefile_path() == expreq._cachefile_path()) - assert(req._cachefile_path() != diffreq._cachefile_path()) - assert(req._cachefile_path() != diffsite._cachefile_path()) - - -def test_expired(): - assert(not req._expired(datetime.datetime.now())) - assert(req._expired(datetime.datetime.now() - datetime.timedelta(days=2))) +if __name__ == '__main__': + unittest.main()
pywikipedia-svn@lists.wikimedia.org