本文整理汇总了Python中pywikibot.data.api.CachedRequest._uniquedescriptionstr方法的典型用法代码示例。如果您正苦于以下问题:Python CachedRequest._uniquedescriptionstr方法的具体用法?Python CachedRequest._uniquedescriptionstr怎么用?Python CachedRequest._uniquedescriptionstr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pywikibot.data.api.CachedRequest
的用法示例。
在下文中一共展示了CachedRequest._uniquedescriptionstr方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_unicode
# 需要导入模块: from pywikibot.data.api import CachedRequest [as 别名]
# 或者: from pywikibot.data.api.CachedRequest import _uniquedescriptionstr [as 别名]
def test_unicode(self):
"""Test caching with Unicode content."""
self.mocksite._userinfo = {'name': u'محمد الفلسطيني'}
self.mocksite._loginstatus = 0
req = CachedRequest(expiry=1, site=self.mocksite,
parameters={'action': 'query', 'meta': 'siteinfo'})
en_user_path = req._cachefile_path()
self.mocksite._namespaces = {2: [u'مستخدم']}
req = CachedRequest(expiry=1, site=self.mocksite,
parameters={'action': 'query', 'meta': 'siteinfo'})
expect = (u'MockSite()User(User:محمد الفلسطيني)' +
"[('action', 'query'), ('meta', 'siteinfo')]")
self.assertEqual(repr(req._uniquedescriptionstr()), repr(expect))
self.assertEqual(req._uniquedescriptionstr().encode('utf-8'),
expect.encode('utf-8'))
ar_user_path = req._cachefile_path()
self.assertEqual(en_user_path, ar_user_path)
示例2: test_unicode
# 需要导入模块: from pywikibot.data.api import CachedRequest [as 别名]
# 或者: from pywikibot.data.api.CachedRequest import _uniquedescriptionstr [as 别名]
def test_unicode(self):
self.mocksite._userinfo = {"name": "محمد الفلسطيني"}
self.mocksite._loginstatus = 0
req = CachedRequest(expiry=1, site=self.mocksite, action="query", meta="siteinfo")
en_user_path = req._cachefile_path()
self.mocksite._namespaces = {2: ["مستخدم"]}
req = CachedRequest(expiry=1, site=self.mocksite, action="query", meta="siteinfo")
expect = "MockSite()User(User:محمد الفلسطيني)" + "[('action', 'query'), ('meta', 'siteinfo')]"
self.assertEqual(repr(req._uniquedescriptionstr()), repr(expect))
self.assertEqual(req._uniquedescriptionstr().encode("utf-8"), expect.encode("utf-8"))
ar_user_path = req._cachefile_path()
self.assertEqual(en_user_path, ar_user_path)
示例3: test_unicode
# 需要导入模块: from pywikibot.data.api import CachedRequest [as 别名]
# 或者: from pywikibot.data.api.CachedRequest import _uniquedescriptionstr [as 别名]
def test_unicode(self):
self.mocksite._userinfo = {'name': u'محمد الفلسطيني'}
self.mocksite._loginstatus = 0
req = CachedRequest(expiry=1, site=self.mocksite,
action='query', meta='siteinfo')
en_user_path = req._cachefile_path()
self.mocksite._namespaces = {2: [u'مستخدم']}
req = CachedRequest(expiry=1, site=self.mocksite,
action='query', meta='siteinfo')
expect = u'MockSite()User(User:محمد الفلسطيني)' + \
"[('action', 'query'), ('meta', 'siteinfo')]"
self.assertEqual(repr(req._uniquedescriptionstr()), repr(expect))
self.assertEqual(req._uniquedescriptionstr().encode('utf-8'),
expect.encode('utf-8'))
ar_user_path = req._cachefile_path()
self.assertEqual(en_user_path, ar_user_path)
示例4: DryCachedRequestTests
# 需要导入模块: from pywikibot.data.api import CachedRequest [as 别名]
# 或者: from pywikibot.data.api.CachedRequest import _uniquedescriptionstr [as 别名]
class DryCachedRequestTests(SiteAttributeTestCase):
"""Test CachedRequest using real site objects."""
sites = {
'basesite': {
'family': 'wikipedia',
'code': 'en',
},
'altsite': {
'family': 'wikipedia',
'code': 'de',
},
}
dry = True
def setUp(self):
"""Initialize the fake requests."""
super(DryCachedRequestTests, self).setUp()
self.parms = {'action': 'query',
'meta': 'userinfo'}
self.req = CachedRequest(expiry=1, site=self.basesite,
parameters=self.parms)
self.expreq = CachedRequest(expiry=0, site=self.basesite,
parameters=self.parms)
self.diffreq = CachedRequest(
expiry=1, site=self.basesite,
parameters={'action': 'query', 'meta': 'siteinfo'})
self.diffsite = CachedRequest(
expiry=1, site=self.altsite,
parameters={'action': 'query', 'meta': 'userinfo'})
# When using ** the paramters are still unicode
self.deprecated_explicit = CachedRequest(
expiry=1, site=self.basesite, action='query', meta='userinfo')
self.deprecated_asterisks = CachedRequest(
expiry=1, site=self.basesite, **self.parms)
def test_expiry_formats(self):
"""Test using a timedelta as expiry."""
self.assertEqual(self.req.expiry,
CachedRequest(datetime.timedelta(days=1), site=self.basesite,
parameters=self.parms).expiry)
def test_expired(self):
"""Test if the request is expired."""
self.assertFalse(self.req._expired(datetime.datetime.now()))
self.assertTrue(self.req._expired(datetime.datetime.now() - datetime.timedelta(days=2)))
def test_parameter_types(self):
"""Test _uniquedescriptionstr is identical using different ways."""
# This test is done as create_file_name and cachefile_path only use
# the hashed name which is not very helpful
self.assertEqual(self.req._uniquedescriptionstr(),
self.req._uniquedescriptionstr())
self.assertEqual(self.req._uniquedescriptionstr(),
self.expreq._uniquedescriptionstr())
self.assertEqual(self.req._uniquedescriptionstr(),
self.deprecated_explicit._uniquedescriptionstr())
self.assertEqual(self.req._uniquedescriptionstr(),
self.deprecated_asterisks._uniquedescriptionstr())
self.assertNotEqual(self.req._uniquedescriptionstr(),
self.diffreq._uniquedescriptionstr())
self.assertNotEqual(self.req._uniquedescriptionstr(),
self.diffsite._uniquedescriptionstr())
def test_get_cache_dir(self):
"""Test that 'apicache' is in the cache dir."""
retval = self.req._get_cache_dir()
self.assertIn('apicache', retval)
def test_create_file_name(self):
"""Test the file names for the cache."""
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.assertEqual(self.req._create_file_name(),
self.deprecated_explicit._create_file_name())
self.assertEqual(self.req._create_file_name(),
self.deprecated_asterisks._create_file_name())
self.assertNotEqual(self.req._create_file_name(), self.diffreq._create_file_name())
def test_cachefile_path(self):
"""Test the file paths for the cache."""
self.assertEqual(self.req._cachefile_path(), self.req._cachefile_path())
self.assertEqual(self.req._cachefile_path(), self.expreq._cachefile_path())
self.assertEqual(self.req._cachefile_path(),
self.deprecated_explicit._cachefile_path())
self.assertEqual(self.req._cachefile_path(),
self.deprecated_asterisks._cachefile_path())
self.assertNotEqual(self.req._cachefile_path(), self.diffreq._cachefile_path())
self.assertNotEqual(self.req._cachefile_path(), self.diffsite._cachefile_path())