http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11696
Revision: 11696 Author: legoktm Date: 2013-06-28 02:09:18 +0000 (Fri, 28 Jun 2013) Log Message: ----------- pep8 fixes
Modified Paths: -------------- branches/rewrite/tests/__init__.py branches/rewrite/tests/api_tests.py branches/rewrite/tests/dry_api_tests.py
Modified: branches/rewrite/tests/__init__.py =================================================================== --- branches/rewrite/tests/__init__.py 2013-06-27 19:38:50 UTC (rev 11695) +++ branches/rewrite/tests/__init__.py 2013-06-28 02:09:18 UTC (rev 11696) @@ -11,27 +11,29 @@ from pywikibot.data.api import Request as _original_Request from pywikibot.data.api import CachedRequest
+ class TestRequest(CachedRequest): def __init__(self, *args, **kwargs): super(TestRequest, self).__init__(0, *args, **kwargs) - + def _get_cache_dir(self): path = os.path.join(os.path.split(__file__)[0], 'apicache') self._make_dir(path) return path - + def _expired(self, dt): return False - + def submit(self): cached_available = self._load_cache() if not cached_available: print str(self) return super(TestRequest, self).submit() - + + def patch_request(): pywikibot.data.api.Request = TestRequest - + + def unpatch_request(): pywikibot.data.api.Request = _original_Request -
Modified: branches/rewrite/tests/api_tests.py =================================================================== --- branches/rewrite/tests/api_tests.py 2013-06-27 19:38:50 UTC (rev 11695) +++ branches/rewrite/tests/api_tests.py 2013-06-28 02:09:18 UTC (rev 11696) @@ -44,21 +44,21 @@ "ns": 0, "title": "Broadcaster.com" }, - "13918157": {"pageid": 13918157, - "ns": 0, - "title": "Broadcaster (definition)" - }, + "13918157": {"pageid": 13918157, + "ns": 0, + "title": "Broadcaster (definition)" + }, "156658": {"pageid": 156658, "ns": 0, "title": "Wiktionary" }, - "47757": {"pageid": 47757, - "ns": 4, - "title": "Wikipedia:Disambiguation" - } + "47757": {"pageid": 47757, + "ns": 4, + "title": "Wikipedia:Disambiguation" + } } } - } + }
def testGeneratorResults(self): """Test that PageGenerator yields pages with expected attributes."""
Modified: branches/rewrite/tests/dry_api_tests.py =================================================================== --- branches/rewrite/tests/dry_api_tests.py 2013-06-27 19:38:50 UTC (rev 11695) +++ branches/rewrite/tests/dry_api_tests.py 2013-06-28 02:09:18 UTC (rev 11696) @@ -11,28 +11,30 @@ diffreq = CachedRequest(expiry=1, site=pywikibot.getSite('en'), action='query', meta='siteinfo') diffsite = CachedRequest(expiry=1, site=pywikibot.getSite('de'), action='query', meta='userinfo')
+ def test_expiry_formats(): - import datetime - assert(req.expiry == CachedRequest(datetime.timedelta(days=1), **parms).expiry) + import datetime + assert(req.expiry == CachedRequest(datetime.timedelta(days=1), **parms).expiry)
+ def test_get_cache_dir(): - retval = req._get_cache_dir() - assert('apicache' in retval) - + retval = req._get_cache_dir() + assert('apicache' in retval) + + 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_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))) - - - \ No newline at end of file
pywikipedia-svn@lists.wikimedia.org