Build Update for wikimedia/pywikibot-core
-------------------------------------
Build: #3323
Status: Errored
Duration: 1 hour, 19 minutes, and 58 seconds
Commit: 5ef185f (master)
Author: xqt
Message: [IMPR] default parameter for Options.format() may be optional
- change default parameter from mandatory positional
to predefined named parameter. All format() methods
are able to use None as default parameter.
- Some tests added
Change-Id: I8a329ee88ed5d1f46ea896eb1dc2767ddd8896c9
View the changeset: https://github.com/wikimedia/pywikibot-core/compare/df4f81721066...5ef185f8…
View the full build log and details: https://travis-ci.org/wikimedia/pywikibot-core/builds/115706063
--
You can configure recipients for build notifications in your .travis.yml file. See https://docs.travis-ci.com/user/notifications
Build Update for wikimedia/pywikibot-core
-------------------------------------
Build: #3322
Status: Errored
Duration: 1 hour, 16 minutes, and 13 seconds
Commit: df4f817 (master)
Author: darthbhyrava
Message: Implement Coordinate.precisionToDim
Enable precision to dim conversion by implementing Coordinate.precisionToDim
Add corresponding tests in wikibase_tests
Bug: T89670
Change-Id: I2f1432603218f0ede2b0f703ef3c5046928440b3
View the changeset: https://github.com/wikimedia/pywikibot-core/compare/95a1beeb836f...df4f8172…
View the full build log and details: https://travis-ci.org/wikimedia/pywikibot-core/builds/115647363
--
You can configure recipients for build notifications in your .travis.yml file. See https://docs.travis-ci.com/user/notifications
jenkins-bot has submitted this change and it was merged.
Change subject: Implement Coordinate.precisionToDim
......................................................................
Implement Coordinate.precisionToDim
Enable precision to dim conversion by implementing Coordinate.precisionToDim
Add corresponding tests in wikibase_tests
Bug: T89670
Change-Id: I2f1432603218f0ede2b0f703ef3c5046928440b3
---
M pywikibot/__init__.py
M tests/wikibase_tests.py
2 files changed, 43 insertions(+), 2 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index 4fe6801..f9e750c 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -354,6 +354,8 @@
@rtype: float or None
"""
+ if self._dim is None and self._precision is None:
+ raise ValueError('No values set for dim or precision')
if self._precision is None and self._dim is not None:
radius = 6378137 # TODO: Support other globes
self._precision = math.degrees(
@@ -365,8 +367,32 @@
self._precision = value
def precisionToDim(self):
- """Convert precision from Wikibase to GeoData's dim."""
- raise NotImplementedError
+ """Convert precision from Wikibase to GeoData's dim and return the latter.
+
+ dim is calculated if the Coordinate doesn't have a dimension, and precision is set.
+ When neither dim nor precision are set, ValueError is thrown.
+
+ Carrying on from the earlier derivation of precision, since
+ precision = math.degrees(dim/(radius*math.cos(math.radians(self.lat)))), we get
+ dim = math.radians(precision)*radius*math.cos(math.radians(self.lat))
+ But this is not valid, since it returns a float value for dim which is an integer.
+ We must round it off to the nearest integer.
+
+ Therefore::
+ dim = int(round(math.radians(precision)*radius*math.cos(math.radians(self.lat))))
+
+ @rtype: int or None
+ """
+ if self._dim is None and self._precision is None:
+ raise ValueError('No values set for dim or precision')
+ if self._dim is None and self._precision is not None:
+ radius = 6378137
+ self._dim = int(
+ round(
+ math.radians(self._precision) * radius * math.cos(math.radians(self.lat))
+ )
+ )
+ return self._dim
class WbTime(_WbRepresentation):
diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py
index ed3cd7e..a0d8265 100644
--- a/tests/wikibase_tests.py
+++ b/tests/wikibase_tests.py
@@ -144,6 +144,21 @@
dry = True
+ def test_Coordinate_dim(self):
+ """Test Coordinate."""
+ repo = self.get_repo()
+ x = pywikibot.Coordinate(site=repo, lat=12.0, lon=13.0, precision=5.0)
+ self.assertEqual(x.precisionToDim(), 544434)
+ self.assertIsInstance(x.precisionToDim(), int)
+ y = pywikibot.Coordinate(site=repo, lat=12.0, lon=13.0, dim=54444)
+ self.assertEqual(y.precision, 0.500005084017101)
+ self.assertIsInstance(y.precision, float)
+ z = pywikibot.Coordinate(site=repo, lat=12.0, lon=13.0)
+ with self.assertRaises(ValueError):
+ z.precision
+ with self.assertRaises(ValueError):
+ z.precisionToDim()
+
def test_WbTime(self):
"""Test WbTime."""
repo = self.get_repo()
--
To view, visit https://gerrit.wikimedia.org/r/275112
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I2f1432603218f0ede2b0f703ef3c5046928440b3
Gerrit-PatchSet: 15
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Darthbhyrava <hbhyrava(a)gmail.com>
Gerrit-Reviewer: Darthbhyrava <hbhyrava(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Polybuildr <v.a.ghaisas(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: page.py: Create a new function to clear cached page attributes
......................................................................
page.py: Create a new function to clear cached page attributes
- Add _cache_attrs as a new attribute to BasePage. It contains a list
of possibly cached attributes.
- Create a new function called clear_cache inside BasePage that tries to
remove all _cache_attrs of the page. (T114624)
- Call the above function inside site.deletepage,
page.latest_revision_id.deleter, and page.purge methods to make sure that
any outdated cached data is cleared. (T126949 and T114625)
- Update the related test function in page_tests.py.
Bug: T114625
Bug: T114624
Bug: T126949
Change-Id: Id1a9e9bab704108df2e01ffdc388c0c2924dcdc5
---
M pywikibot/page.py
M pywikibot/site.py
M tests/page_tests.py
3 files changed, 24 insertions(+), 2 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index b1a731c..c0c8294 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -89,6 +89,13 @@
Will be subclassed by Page, WikibasePage, and FlowPage.
"""
+ _cache_attrs = (
+ '_text', '_pageid', '_catinfo', '_templates', '_protection',
+ '_contentmodel', '_langlinks', '_isredir', '_coords',
+ '_preloadedtext', '_timestamp', '_applicable_protections',
+ '_flowinfo', '_quality', '_pageprops', '_revid', '_quality_text'
+ )
+
def __init__(self, source, title=u"", ns=0):
"""
Instantiate a Page object.
@@ -1270,12 +1277,22 @@
"""
return self.site.watch(self, unwatch)
+ def clear_cache(self):
+ """Clear the cached attributes of the page."""
+ self._revisions = {}
+ for attr in self._cache_attrs:
+ try:
+ delattr(self, attr)
+ except AttributeError:
+ pass
+
def purge(self, **kwargs):
"""
Purge the server's cache for this page.
@rtype: bool
"""
+ self.clear_cache()
return self.site.purgepages([self], **kwargs)
def touch(self, callback=None, botflag=False, **kwargs):
@@ -3579,7 +3596,7 @@
@latest_revision_id.deleter
def latest_revision_id(self, value):
- del self._revid
+ self.clear_cache()
@staticmethod
def _normalizeLanguages(data):
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 3b16319..4f37f8c 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -5127,6 +5127,8 @@
% err.code,
_logger)
raise
+ else:
+ page.clear_cache()
finally:
self.unlock_page(page)
diff --git a/tests/page_tests.py b/tests/page_tests.py
index 48829f9..9eb7d83 100644
--- a/tests/page_tests.py
+++ b/tests/page_tests.py
@@ -874,9 +874,12 @@
p = pywikibot.Page(site, u'User:Unicodesnowman/DeleteTest')
# Ensure the page exists
p.text = 'pywikibot unit test page'
- p.save('unit test', botflag=True)
+ p.save('#redirect[[unit test]]', botflag=True)
+ self.assertEqual(p.isRedirectPage(), True)
# Test deletion
p.delete(reason='pywikibot unit test', prompt=False, mark=False)
+ self.assertEqual(p._pageid, 0)
+ self.assertEqual(p.isRedirectPage(), False)
self.assertRaises(pywikibot.NoPage, p.get, force=True)
# Test undeleting last two revisions
del_revs = list(p.loadDeletedRevisions())
--
To view, visit https://gerrit.wikimedia.org/r/271980
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Id1a9e9bab704108df2e01ffdc388c0c2924dcdc5
Gerrit-PatchSet: 12
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>