jenkins-bot has submitted this change and it was merged.
Change subject: move date.test() to testsuite
......................................................................
move date.test() to testsuite
testMapEntry and test procedures are removed from date library and
its content moved to date_tests.py. We have only one test method
which runs through the whole date.format. If the test failes there
it reports the current format keys.
Change-Id: I596cb53339bbe43e39b37331a41ff937f7a1161c
---
M pywikibot/date.py
A tests/date_tests.py
2 files changed, 50 insertions(+), 85 deletions(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/date.py b/pywikibot/date.py
index ad57e2c..a1b85ad 100644
--- a/pywikibot/date.py
+++ b/pywikibot/date.py
@@ -10,7 +10,7 @@
# (C) Andre Engels, 2004-2005
# (C) Yuri Astrakhan, 2005-2006 FirstnameLastname(a)gmail.com
# (years/decades/centuries/millenniums str <=> int conversions)
-# (C) Pywikibot team, 2004-2013
+# (C) Pywikibot team, 2004-2014
#
# Distributed under the terms of the MIT license.
#
@@ -2324,89 +2324,6 @@
else:
return formats['YearAD'][lang](year)
-#
-# Map testing methods
-#
-
-
-def printMonthArray(lang, pattern, capitalize):
- """
- """
- for s in makeMonthNamedList(lang, pattern, capitalize):
- pywikibot.output(s)
-
-
-def testMapEntry(formatName, showAll=True, value=None):
- """This is a test function, to be used interactivelly to test the
validity
- of the above maps. To test, run this function with the map name, value to
- be tested, and the final value expected.
- Usage example:
- run python interpreter
- >>> import date
- >>> date.testMapEntry('DecadeAD', 1992, 1990)
- >>> date.testMapEntry('CenturyAD', 20, 20)
-
- """
-
- step = 1
- if formatName in decadeFormats:
- step = 10
- predicate, start, stop = formatLimits[formatName]
- if value is not None:
- start, stop = value, value + 1
- if showAll:
- pywikibot.output(u"Processing %s with limits from %d to %d and step
%d"
- % (formatName, start, stop - 1, step))
-
- for code, convFunc in formats[formatName].items():
-## import time
-## startClock = time.clock()
- for value in range(start, stop, step):
- try:
- if not predicate(value):
- raise AssertionError(
- " Not a valid value for this format.")
- newValue = convFunc(convFunc(value))
- if newValue != value:
- raise AssertionError(
- " %s != %s: assert failed, values didn't
match"
- % (newValue, value))
- if showAll:
- pywikibot.output(u"date.formats['%s']['%s'](%d):
'%s' -> %d"
- % (formatName, code, value, convFunc(value),
- newValue))
- except:
- pywikibot.output(u"********** Error in
date.formats['%s']['%s'](%d)"
- % (formatName, code, value))
- raise
-## print(u"%s\t%s\t%f" % (formatName, code, time.clock() - startClock))
-
-
-def test(quick=False, showAll=False):
- """This is a test function, to be used interactively to test entire
- format conversion map at once
-
- Usage example:
- run python interpreter
- >>> import date
- >>> date.test()
-
- """
- for formatName in formats:
- if quick:
- # Only test the first value in the test range
- testMapEntry(formatName, showAll, formatLimits[formatName][1])
- else:
- # Extensive test! Test decade rounding
- testMapEntry(formatName, showAll)
- pywikibot.output(u"'%s' complete." % formatName)
- if quick:
-## print(u'Date module quick consistency test passed')
- pass
- else:
- print(u'Date module has been fully tested')
-
if __name__ == "__main__":
- # Test the date file
- test(quick=False)
+ print(__doc__)
diff --git a/tests/date_tests.py b/tests/date_tests.py
new file mode 100644
index 0000000..32477ba
--- /dev/null
+++ b/tests/date_tests.py
@@ -0,0 +1,48 @@
+# -*- coding: utf-8 -*-
+#
+# (C) Pywikipedia bot team, 2014
+#
+# Distributed under the terms of the MIT license.
+#
+__version__ = '$Id$'
+
+from utils import unittest
+
+import pywikibot
+import pywikibot.date as date
+
+
+class TestDate(unittest.TestCase):
+ """Test cases for date library"""
+
+ def testMapEntry(self):
+ """Tests the validity of the pywikibot.date format
maps."""
+ for formatName in date.formats:
+ step = 1
+ if formatName in date.decadeFormats:
+ step = 10
+ predicate, start, stop = date.formatLimits[formatName]
+
+ for code, convFunc in date.formats[formatName].items():
+ for value in range(start, stop, step):
+ self.assertTrue(
+ predicate(value),
+
"date.formats['%(formatName)s']['%(code)s']:\n"
+ "invalid value %(value)d" % locals())
+
+ newValue = convFunc(convFunc(value))
+ self.assertEqual(
+ newValue, value,
+
"date.formats['%(formatName)s']['%(code)s']:\n"
+ "value %(newValue)d does not match %(value)s"
+ % locals())
+
+
+if __name__ == '__main__':
+ try:
+ try:
+ unittest.main()
+ except SystemExit:
+ pass
+ finally:
+ pywikibot.stopme()
--
To view, visit
https://gerrit.wikimedia.org/r/108630
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I596cb53339bbe43e39b37331a41ff937f7a1161c
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: jenkins-bot <>