jenkins-bot has submitted this change and it was merged.
Change subject: [bugfix] Additional wikistats tests ......................................................................
[bugfix] Additional wikistats tests
- expand test suite and test sorting order of languages_by_size - remove indexed tests
Bug: T128990 Change-Id: Iff6266e4bcbebe2f859bcba4feb326fa8be26091 --- M tests/wikistats_tests.py 1 file changed, 32 insertions(+), 6 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/tests/wikistats_tests.py b/tests/wikistats_tests.py index e255968..2aec49d 100644 --- a/tests/wikistats_tests.py +++ b/tests/wikistats_tests.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Test cases for the WikiStats dataset.""" # -# (C) Pywikibot team, 2014 +# (C) Pywikibot team, 2014-2016 # # Distributed under the terms of the MIT license. # @@ -9,6 +9,8 @@
__version__ = '$Id$' # + +import sys
from pywikibot.data.wikistats import WikiStats, csv from pywikibot.tools import UnicodeType @@ -27,15 +29,39 @@ ws = WikiStats() data = ws.sorted('wikipedia', 'total') top = data[0] + bottom = data[-1] + self.assertIn('good', top) self.assertIn('prefix', top) self.assertIn('total', top) - self.assertEqual(top['prefix'], 'en') + self.assertIn('good', bottom) + self.assertIn('prefix', bottom) + self.assertIn('total', bottom) + self.assertIsInstance(top['good'], UnicodeType) self.assertTrue(all(isinstance(key, UnicodeType) for key in top.keys() if key is not None)) self.assertIsInstance(top['total'], UnicodeType) - self.assertEqual(ws.languages_by_size('wikipedia')[0], 'en') - self.assertEqual(ws.languages_by_size('wikisource')[0], 'fr') + self.assertIsInstance(bottom['good'], UnicodeType) + self.assertIsInstance(bottom['total'], UnicodeType) + self.assertGreater(int(top['total']), int(bottom['good'])) + self.assertGreater(int(top['good']), int(bottom['good'])) + self.assertGreater(int(top['total']), int(bottom['total'])) + + def test_sorting_order(self): + """Test sorting order of languages_by_size.""" + FAMILY = 'wikipedia' + ws = WikiStats() + data = ws.get_dict(FAMILY) + last = sys.maxint + last_code = '' + for code in ws.languages_by_size(FAMILY): + curr = int(data[code]['good']) + self.assertGreaterEqual( + last, curr, + '{0} ({1}) is greater than {2} ({3}).' + ''.format(code, curr, last_code, last)) + last = curr + last_code = code
def test_csv(self): """Test CSV.""" @@ -46,7 +72,7 @@ self.assertIsInstance(data, dict) self.assertIn('en', data) self.assertIn('ht', data) - self.assertGreater(int(data['en']['total']), 4000000) + self.assertGreater(int(data['en']['total']), int(data['en']['good'])) data = data['en'] self.assertTrue(all(isinstance(key, UnicodeType) for key in data.keys() @@ -62,7 +88,7 @@ self.assertIsInstance(data, dict) self.assertIn('en', data) self.assertIn('id', data) - self.assertGreater(int(data['fr']['total']), 1600000) + self.assertGreater(int(data['fr']['total']), int(data['fr']['good'])) data = data['fr'] self.assertTrue(all(isinstance(key, UnicodeType) for key in data.keys()