jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/621876 )
Change subject: [cleanup] Remove unicodecsv check in wikistats_tests.py ......................................................................
[cleanup] Remove unicodecsv check in wikistats_tests.py
Also reorder imports in wikistats.py
Change-Id: I791f5fb6c2ce6ffca8c9109d918a9ee956220ef6 --- M pywikibot/data/wikistats.py M tests/wikistats_tests.py 2 files changed, 9 insertions(+), 15 deletions(-)
Approvals: Matěj Suchánek: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/data/wikistats.py b/pywikibot/data/wikistats.py index 5c2f0f4..b163d62 100644 --- a/pywikibot/data/wikistats.py +++ b/pywikibot/data/wikistats.py @@ -4,10 +4,10 @@ # (C) Pywikibot team, 2014-2020 # # Distributed under the terms of the MIT license. -import csv - from collections import defaultdict +from csv import DictReader from io import BytesIO, StringIO +from xml.etree import ElementTree
import pywikibot from pywikibot.comms import http @@ -130,7 +130,7 @@
raw = self.raw_cached(table, 'csv') f = StringIO(raw.decode('utf8')) - reader = csv.DictReader(f) + reader = DictReader(f) data = list(reader) self._data['csv'][table] = data
@@ -146,8 +146,6 @@ if table in self._data['xml']: return self._data['xml'][table]
- from xml.etree import ElementTree - raw = self.raw_cached(table, 'xml') f = BytesIO(raw) tree = ElementTree.parse(f) diff --git a/tests/wikistats_tests.py b/tests/wikistats_tests.py index a68926e..5f67c0c 100644 --- a/tests/wikistats_tests.py +++ b/tests/wikistats_tests.py @@ -7,7 +7,9 @@ # import sys
-from pywikibot.data.wikistats import WikiStats, csv +from contextlib import suppress + +from pywikibot.data.wikistats import WikiStats
from tests.aspects import unittest, TestCase
@@ -62,8 +64,6 @@
def test_csv(self): """Test CSV.""" - if not csv: - self.skipTest('unicodecsv not installed.') ws = WikiStats() data = ws.get_dict('wikipedia', 'csv') self.assertIsInstance(data, dict) @@ -72,8 +72,7 @@ self.assertGreater(int(data['en']['total']), int(data['en']['good'])) data = data['en'] self.assertTrue(all(isinstance(key, str) - for key in data.keys() - if key is not None)) + for key in data.keys() if key is not None)) self.assertIsInstance(data['total'], str) self.assertIn('prefix', data) self.assertIn('total', data) @@ -88,15 +87,12 @@ self.assertGreater(int(data['fr']['total']), int(data['fr']['good'])) data = data['fr'] self.assertTrue(all(isinstance(key, str) - for key in data.keys() - if key is not None)) + for key in data.keys() if key is not None)) self.assertIsInstance(data['total'], str) self.assertIn('prefix', data) self.assertIn('total', data)
if __name__ == '__main__': # pragma: no cover - try: + with suppress(SystemExit): unittest.main() - except SystemExit: - pass
pywikibot-commits@lists.wikimedia.org