jenkins-bot has submitted this change and it was merged.
Change subject: [LIB] use calendar method for days of months
......................................................................
[LIB] use calendar method for days of months
- default value 2000 is used of a leap year.
- additional generator tests are provided
Bug: T104787
Change-Id: I584650a862dd6302ec7c46389fdf0cb1efc0828f
---
M pywikibot/date.py
M pywikibot/pagegenerators.py
M tests/pagegenerators_tests.py
3 files changed, 58 insertions(+), 16 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/date.py b/pywikibot/date.py
index 92ef02b..163b720 100644
--- a/pywikibot/date.py
+++ b/pywikibot/date.py
@@ -20,7 +20,7 @@
import re
import sys
-from pywikibot.tools import first_lower, first_upper
+from pywikibot.tools import first_lower, first_upper, deprecated
if sys.version_info[0] > 2:
unicode = str
@@ -2313,9 +2313,15 @@
formatLimits[dayMnthFmts[monthId]] = _formatLimit_DayOfMonth30
+@deprecated("calendar.monthrange")
def getNumberOfDaysInMonth(month):
- """Return the number of days in a given month, 1 being January, etc."""
- return formatLimits[dayMnthFmts[month - 1]][2] - 1
+ """
+ Return the maximum number of days in a given month, 1 being January, etc.
+
+ For February alway 29 will be given, even it is not a leap year.
+ """
+ # use year 2000 which is a leap year
+ return calendar.monthrange(2000, month)[1]
def getAutoFormat(lang, title, ignoreFirstLetterCase=True):
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py
index 0489d59..4fe6fad 100644
--- a/pywikibot/pagegenerators.py
+++ b/pywikibot/pagegenerators.py
@@ -23,6 +23,7 @@
__version__ = '$Id$'
#
+import calendar
import codecs
import datetime
import itertools
@@ -2305,12 +2306,14 @@
yield pywikibot.Page(pywikibot.Link(current_year, site))
-def DayPageGenerator(startMonth=1, endMonth=12, site=None):
+def DayPageGenerator(startMonth=1, endMonth=12, site=None, year=2000):
"""
Day page generator.
@param site: Site for generator results.
@type site: L{pywikibot.site.BaseSite}
+ @param year: considering leap year.
+ @type year: int
"""
if site is None:
site = pywikibot.Site()
@@ -2318,7 +2321,7 @@
firstPage = pywikibot.Page(site, fd(startMonth, 1))
pywikibot.output(u"Starting with %s" % firstPage.title(asLink=True))
for month in range(startMonth, endMonth + 1):
- for day in range(1, date.getNumberOfDaysInMonth(month) + 1):
+ for day in range(1, calendar.monthrange(year, month)[1] + 1):
yield pywikibot.Page(pywikibot.Link(fd(month, day), site))
diff --git a/tests/pagegenerators_tests.py b/tests/pagegenerators_tests.py
index 5e20097..5411b9c 100755
--- a/tests/pagegenerators_tests.py
+++ b/tests/pagegenerators_tests.py
@@ -2,13 +2,14 @@
# -*- coding: utf-8 -*-
"""Test pagegenerators module."""
#
-# (C) Pywikibot team, 2014
+# (C) Pywikibot team, 2014-2015
#
# Distributed under the terms of the MIT license.
from __future__ import unicode_literals
__version__ = '$Id$'
+import calendar
import datetime
import os
import sys
@@ -318,24 +319,56 @@
"""Test the day page generator."""
- def test_basic(self):
- site = self.get_site()
- fd = date.FormatDate(site)
- startMonth = 1
- endMonth = 12
+ @classmethod
+ def setUpClass(cls):
+ super(TestDayPageGenerator, cls).setUpClass()
+ cls.site = cls.get_site()
+ cls.fd = date.FormatDate(cls.site)
- gen = pagegenerators.DayPageGenerator(startMonth, endMonth, site)
+ def _run_test(self, startMonth=1, endMonth=12, year=2000):
+ params = {
+ 'startMonth': startMonth,
+ 'endMonth': endMonth,
+ 'site': self.site,
+ }
+ if year != 2000:
+ params['year'] = year
+ # use positional parameter
+ gen1 = pagegenerators.DayPageGenerator(startMonth, endMonth, self.site,
+ year)
+ # use keyworded parameter and default for year
+ gen2 = pagegenerators.DayPageGenerator(**params)
- for page in pagegenerators.DayPageGenerator(startMonth, endMonth, site):
+ for page in gen1:
self.assertIsInstance(page, pywikibot.Page)
self.assertTrue(page.isAutoTitle)
expected = []
for month in range(startMonth, endMonth + 1):
- for day in range(1, date.getNumberOfDaysInMonth(month) + 1):
- expected.append(fd(month, day))
+ for day in range(1, calendar.monthrange(year, month)[1] + 1):
+ expected.append(self.fd(month, day))
- self.assertPageTitlesEqual(gen, expected)
+ self.assertPageTitlesEqual(gen2, expected)
+
+ def test_basic(self):
+ """General test for day page generator."""
+ self._run_test()
+
+ def test_year_2001(self):
+ """Test for day page generator of year 2001."""
+ self._run_test(2, year=2001)
+
+ def test_year_2100(self):
+ """Test for day page generator of year 2100."""
+ self._run_test(endMonth=2, year=2100)
+
+ def test_start_0(self):
+ """Test for day page generator with startMonth 0."""
+ self.assertRaises(calendar.IllegalMonthError, self._run_test, 0)
+
+ def test_end_13(self):
+ """Test for day page generator with endMonth 13."""
+ self.assertRaises(calendar.IllegalMonthError, self._run_test, 12, 13)
class TestPreloadingGenerator(DefaultSiteTestCase):
--
To view, visit https://gerrit.wikimedia.org/r/223287
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I584650a862dd6302ec7c46389fdf0cb1efc0828f
Gerrit-PatchSet: 6
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Add djvulibre-bin to travis apt package list
......................................................................
Add djvulibre-bin to travis apt package list
This is needed for the djvu tests.
Support added: https://github.com/travis-ci/travis-ci/issues/3998
Bug: T66853
Change-Id: If677e4c66b03048980d77d42a9333a12c00a6112
---
M .travis.yml
1 file changed, 1 insertion(+), 0 deletions(-)
Approvals:
John Vandenberg: Looks good to me, but someone else must approve
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/.travis.yml b/.travis.yml
index 0004dbf..39c880c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -17,6 +17,7 @@
addons:
apt:
packages:
+ - djvulibre-bin
- graphviz
- liblua5.1-0-dev
--
To view, visit https://gerrit.wikimedia.org/r/224199
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: If677e4c66b03048980d77d42a9333a12c00a6112
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
Build Update for wikimedia/pywikibot-core
-------------------------------------
Build: #2517
Status: Fixed
Duration: 26 minutes and 39 seconds
Commit: ce849a1 (master)
Author: xqt
Message: Updated pywikibot/core
Project: pywikibot/i18n b119ef3c6a32dbb0b3443d890ea88527fee7b20c
Remove other obsolete files again
site code is no longer used for L10N messages, files are already renamed.
Change-Id: Ib9a27f3ee838608f77152435a9b3c525d8ba79aa
View the changeset: https://github.com/wikimedia/pywikibot-core/compare/64c422019c93...ce849a1f…
View the full build log and details: https://travis-ci.org/wikimedia/pywikibot-core/builds/70310032
--
You can configure recipients for build notifications in your .travis.yml file. See http://docs.travis-ci.com/user/notifications
jenkins-bot has submitted this change and it was merged.
Change subject: Fix links to CC-BY-SA 3.0 in docs
......................................................................
Fix links to CC-BY-SA 3.0 in docs
Change-Id: I8a8092dca3206ea585cb3a5d5b71bf4ceb1360a0
---
M docs/index.rst
M docs/licenses.rst
2 files changed, 6 insertions(+), 3 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/docs/index.rst b/docs/index.rst
index 9ef9559..3c1b87d 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -15,7 +15,7 @@
Pywikibot supports Python 2.6.5, 2.7 and 3.2+.
Pywikibot and this documentation are licensed under the :ref:`MIT license <licenses-MIT>`;
-manual pages on mediawiki.org are licensed under the `CC-BY-SA 3.0 <licenses-CCBYSA>` license.
+manual pages on mediawiki.org are licensed under the `CC-BY-SA 3.0`_ license.
The documentation consists of four major parts:
@@ -52,3 +52,6 @@
licenses
credits
+
+
+.. _CC-BY-SA 3.0: http://creativecommons.org/licenses/by-sa/3.0/
diff --git a/docs/licenses.rst b/docs/licenses.rst
index c73274d..c973eb1 100644
--- a/docs/licenses.rst
+++ b/docs/licenses.rst
@@ -3,7 +3,7 @@
The framework itself and this documentation are available under the
:ref:`MIT license <licenses-MIT>`; manual pages on mediawiki.org are
-available under the `CC-BY-SA 3.0 <licenses-CCBYSA>` license.
+available under the `CC-BY-SA 3.0`_ license.
.. _licenses-MIT:
@@ -35,4 +35,4 @@
OTHER DEALINGS IN THE SOFTWARE.
-.. _licenses-CCBYSA: http://creativecommons.org/licenses/by-sa/3.0/
+.. _CC-BY-SA 3.0: http://creativecommons.org/licenses/by-sa/3.0/
--
To view, visit https://gerrit.wikimedia.org/r/223785
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8a8092dca3206ea585cb3a5d5b71bf4ceb1360a0
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: jenkins-bot <>