jenkins-bot has submitted this change and it was merged.

Change subject: improved checks for precision when initializing WbTime objects
......................................................................


improved checks for precision when initializing WbTime objects

also used the 'self' keyword instead of the hardcoded class name
and added two tests

Change-Id: Ieffc18ebac19050ceb4d71246a042db1d4b29db3
---
M pywikibot/__init__.py
M tests/wikibase_tests.py
2 files changed, 13 insertions(+), 11 deletions(-)

Approvals:
  Xqt: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index 784ca29..6843ec6 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -224,21 +224,21 @@
         """
         if year is None:
             raise ValueError('no year given')
-        self.precision = WbTime.PRECISION['second']
+        self.precision = self.PRECISION['second']
         if second is None:
-            self.precision = WbTime.PRECISION['minute']
+            self.precision = self.PRECISION['minute']
             second = 0
         if minute is None:
-            self.precision = WbTime.PRECISION['hour']
+            self.precision = self.PRECISION['hour']
             minute = 0
         if hour is None:
-            self.precision = WbTime.PRECISION['day']
+            self.precision = self.PRECISION['day']
             hour = 0
         if day is None:
-            self.precision = WbTime.PRECISION['month']
+            self.precision = self.PRECISION['month']
             day = 1
         if month is None:
-            self.precision = WbTime.PRECISION['year']
+            self.precision = self.PRECISION['year']
             month = 1
         self.year = long(year)
         self.month = month
@@ -253,10 +253,10 @@
 
         # if precision is given it overwrites the autodetection above
         if precision is not None:
-            if isinstance(precision, int):
+            if isinstance(precision, int) and precision in 
self.PRECISION.values():
                 self.precision = precision
-            elif precision in WbTime.PRECISION:
-                self.precision = WbTime.PRECISION[precision]
+            elif precision in self.PRECISION:
+                self.precision = self.PRECISION[precision]
             else:
                 raise ValueError('Invalid precision: "%s"' % precision)
 
@@ -274,8 +274,8 @@
         """
         Function which converts the the data to a UTC date/time string
         """
-        return WbTime.FORMATSTR.format(self.year, self.month, self.day,
-                                        self.hour, self.minute, self.second)
+        return self.FORMATSTR.format(self.year, self.month, self.day,
+                                     self.hour, self.minute, self.second)
 
     def toWikibase(self):
         """
diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py
index fc0e267..d1338ad 100644
--- a/tests/wikibase_tests.py
+++ b/tests/wikibase_tests.py
@@ -49,6 +49,8 @@
         # test WbTime
         t = pywikibot.WbTime(year=2010, hour=12, minute=43)
         self.assertEqual(t.toTimestr(), '+00000002010-01-01T12:43:00Z')
+        self.assertRaises(ValueError, pywikibot.WbTime, precision=15)
+        self.assertRaises(ValueError, pywikibot.WbTime, 
precision='invalid_precision')
 
         # test WikibasePage.__cmp__
         self.assertEqual(pywikibot.ItemPage.fromPage(mainpage), 
pywikibot.ItemPage(repo, 'q5296'))

-- 
To view, visit https://gerrit.wikimedia.org/r/129975
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ieffc18ebac19050ceb4d71246a042db1d4b29db3
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: Ricordisamoa <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to