jenkins-bot has submitted this change and it was merged.
Change subject: [flake8] Check PEP-8 naming conventions ......................................................................
[flake8] Check PEP-8 naming conventions
- no abbreviation when importing Timestamp or MediaWikiVersion
Change-Id: Id0c12977992e4284a0709454e9060b475c81ffdc --- M pywikibot/proofreadpage.py M pywikibot/tools/ip.py M pywikibot/userinterfaces/gui.py M scripts/maintenance/make_i18n_dict.py M scripts/revertbot.py M tests/mediawikiversion_tests.py M tests/replacebot_tests.py M tests/timestamp_tests.py M tox.ini 9 files changed, 53 insertions(+), 40 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/proofreadpage.py b/pywikibot/proofreadpage.py index 4fdba01..306bd74 100644 --- a/pywikibot/proofreadpage.py +++ b/pywikibot/proofreadpage.py @@ -202,7 +202,7 @@ return self._quality return self.ql
- def decompose(fn): + def decompose(fn): # flake8: disable=N805 """Decorator.
Decompose text if needed and recompose text. @@ -499,7 +499,7 @@
self._cached = False
- def check_if_cached(fn): + def check_if_cached(fn): # flake8: disable=N805 """Decorator to check if data are cached and cache them if needed.""" def wrapper(self, *args, **kwargs): if self._cached is False: diff --git a/pywikibot/tools/ip.py b/pywikibot/tools/ip.py index aca5045..675eed8 100644 --- a/pywikibot/tools/ip.py +++ b/pywikibot/tools/ip.py @@ -33,7 +33,7 @@ else: _ipaddr_version = StrictVersion(_ipaddr_version) if _ipaddr_version >= StrictVersion('2.1.10'): - from ipaddr import IPAddress as ip_address + from ipaddr import IPAddress as ip_address # flake8: disable=N813 else: _ipaddr_e = ImportError('ipaddr %s is broken.' % _ipaddr_version)
diff --git a/pywikibot/userinterfaces/gui.py b/pywikibot/userinterfaces/gui.py index 4d3e33e..454c005 100644 --- a/pywikibot/userinterfaces/gui.py +++ b/pywikibot/userinterfaces/gui.py @@ -22,7 +22,7 @@ if sys.version_info[0] > 2: import tkinter as Tkinter from tkinter.scrolledtext import ScrolledText - from tkinter import simpledialog as tkSimpleDialog + from tkinter import simpledialog as tkSimpleDialog # flake8: disable=N812 else: import Tkinter import tkSimpleDialog diff --git a/scripts/maintenance/make_i18n_dict.py b/scripts/maintenance/make_i18n_dict.py index 16edd6a..c73f055 100755 --- a/scripts/maintenance/make_i18n_dict.py +++ b/scripts/maintenance/make_i18n_dict.py @@ -43,7 +43,7 @@ from pywikibot import config
-class i18nBot(object): +class i18nBot(object): # flake8: disable=N801
"""I18n bot."""
diff --git a/scripts/revertbot.py b/scripts/revertbot.py index 836ef5a..0022ef9 100755 --- a/scripts/revertbot.py +++ b/scripts/revertbot.py @@ -141,7 +141,7 @@ pywikibot.output(msg)
-class myRevertBot(BaseRevertBot): +class RevertBot(BaseRevertBot):
"""Example revert bot."""
@@ -161,6 +161,9 @@ return False
+myRevertBot = RevertBot # for compatibility only + + def main(*args): """ Process command line arguments and invoke bot. diff --git a/tests/mediawikiversion_tests.py b/tests/mediawikiversion_tests.py index 4abb82b..e387928 100644 --- a/tests/mediawikiversion_tests.py +++ b/tests/mediawikiversion_tests.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Tests for the tools.MediaWikiVersion class.""" # -# (C) Pywikibot team, 2008-2014 +# (C) Pywikibot team, 2008-2016 # # Distributed under the terms of the MIT license. # @@ -10,7 +10,7 @@ __version__ = '$Id$'
-from pywikibot.tools import MediaWikiVersion as V +from pywikibot.tools import MediaWikiVersion
from tests.aspects import unittest, TestCase
@@ -23,7 +23,7 @@
def _make(self, version): """Create a MediaWikiVersion instance and check that the str stays.""" - v = V(version) + v = MediaWikiVersion(version) self.assertEqual(str(v), version) return v
@@ -74,17 +74,18 @@
def test_invalid_versions(self): """Verify that insufficient version fail creating.""" - self.assertRaises(ValueError, V, 'invalid') - self.assertRaises(ValueError, V, '1number') - self.assertRaises(ValueError, V, '1.missing') + self.assertRaises(ValueError, MediaWikiVersion, 'invalid') + self.assertRaises(ValueError, MediaWikiVersion, '1number') + self.assertRaises(ValueError, MediaWikiVersion, '1.missing')
- self.assertRaises(AssertionError, V, '1.23wmf-1') + self.assertRaises(AssertionError, MediaWikiVersion, '1.23wmf-1')
def test_generator(self): """Test from_generator classmethod.""" - self.assertEqual(V.from_generator('MediaWiki 1.2.3'), + self.assertEqual(MediaWikiVersion.from_generator('MediaWiki 1.2.3'), self._make('1.2.3')) - self.assertRaises(ValueError, V.from_generator, 'Invalid 1.2.3') + self.assertRaises(ValueError, MediaWikiVersion.from_generator, + 'Invalid 1.2.3')
if __name__ == '__main__': # pragma: no cover diff --git a/tests/replacebot_tests.py b/tests/replacebot_tests.py index e062477..60ac7ef 100644 --- a/tests/replacebot_tests.py +++ b/tests/replacebot_tests.py @@ -45,14 +45,14 @@
changed_pages = -42 # show that weird number to show this was used
- def __init__(inner_self, *args, **kwargs): + def __init__(inner_self, *args, **kwargs): # flake8: disable=N805 # Unpatch already here, as otherwise super calls will use # this class' super which is the class itself replace.ReplaceRobot = self._original_bot super(FakeReplaceBot, inner_self).__init__(*args, **kwargs) self.bots.append(inner_self)
- def run(inner_self): + def run(inner_self): # flake8: disable=N805 """Nothing to do here.""" inner_self.changed_pages = -47 # show that run was called
diff --git a/tests/timestamp_tests.py b/tests/timestamp_tests.py index 5d6eb9d..f970a8d 100644 --- a/tests/timestamp_tests.py +++ b/tests/timestamp_tests.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Tests for the Timestamp class.""" # -# (C) Pywikibot team, 2014 +# (C) Pywikibot team, 2014-2016 # # Distributed under the terms of the MIT license. # @@ -12,7 +12,7 @@ import calendar import datetime
-from pywikibot import Timestamp as T +from pywikibot import Timestamp
from tests.aspects import unittest, TestCase
@@ -25,26 +25,26 @@
def test_clone(self): """Test cloning a Timestamp instance.""" - t1 = T.utcnow() + t1 = Timestamp.utcnow() t2 = t1.clone() self.assertEqual(t1, t2) - self.assertIsInstance(t2, T) + self.assertIsInstance(t2, Timestamp)
def test_instantiate_from_instance(self): """Test passing instance to factory methods works.""" - t1 = T.utcnow() - self.assertIsNot(t1, T.fromISOformat(t1)) - self.assertEqual(t1, T.fromISOformat(t1)) - self.assertIsInstance(T.fromISOformat(t1), T) - self.assertIsNot(t1, T.fromtimestampformat(t1)) - self.assertEqual(t1, T.fromtimestampformat(t1)) - self.assertIsInstance(T.fromtimestampformat(t1), T) + t1 = Timestamp.utcnow() + self.assertIsNot(t1, Timestamp.fromISOformat(t1)) + self.assertEqual(t1, Timestamp.fromISOformat(t1)) + self.assertIsInstance(Timestamp.fromISOformat(t1), Timestamp) + self.assertIsNot(t1, Timestamp.fromtimestampformat(t1)) + self.assertEqual(t1, Timestamp.fromtimestampformat(t1)) + self.assertIsInstance(Timestamp.fromtimestampformat(t1), Timestamp)
def test_iso_format(self): """Test conversion from and to ISO format.""" - t1 = T.utcnow() + t1 = Timestamp.utcnow() ts1 = t1.isoformat() - t2 = T.fromISOformat(ts1) + t2 = Timestamp.fromISOformat(ts1) ts2 = t2.isoformat() # MediaWiki ISO format doesn't include microseconds self.assertNotEqual(t1, t2) @@ -54,9 +54,9 @@
def test_mediawiki_format(self): """Test conversion from and to timestamp format.""" - t1 = T.utcnow() + t1 = Timestamp.utcnow() ts1 = t1.totimestampformat() - t2 = T.fromtimestampformat(ts1) + t2 = Timestamp.fromtimestampformat(ts1) ts2 = t2.totimestampformat() # MediaWiki timestamp format doesn't include microseconds self.assertNotEqual(t1, t2) @@ -66,13 +66,13 @@
def test_add_timedelta(self): """Test addin a timedelta to a Timestamp.""" - t1 = T.utcnow() + t1 = Timestamp.utcnow() t2 = t1 + datetime.timedelta(days=1) if t1.month != t2.month: self.assertEqual(1, t2.day) else: self.assertEqual(t1.day + 1, t2.day) - self.assertIsInstance(t2, T) + self.assertIsInstance(t2, Timestamp)
def test_add_timedate(self): """Test unsupported additions raise NotImplemented.""" @@ -82,24 +82,24 @@ self.assertIs(t3, NotImplemented)
# Now check that the pywikibot sub-class behaves the same way - t1 = T.utcnow() + t1 = Timestamp.utcnow() t2 = t1 + datetime.timedelta(days=1) t3 = t1.__add__(t2) self.assertIs(t3, NotImplemented)
def test_sub_timedelta(self): """Test substracting a timedelta from a Timestamp.""" - t1 = T.utcnow() + t1 = Timestamp.utcnow() t2 = t1 - datetime.timedelta(days=1) if t1.month != t2.month: self.assertEqual(calendar.monthrange(t2.year, t2.month)[1], t2.day) else: self.assertEqual(t1.day - 1, t2.day) - self.assertIsInstance(t2, T) + self.assertIsInstance(t2, Timestamp)
def test_sub_timedate(self): """Test subtracting two timestamps.""" - t1 = T.utcnow() + t1 = Timestamp.utcnow() t2 = t1 - datetime.timedelta(days=1) td = t1 - t2 self.assertIsInstance(td, datetime.timedelta) diff --git a/tox.ini b/tox.ini index e87318d..83ce047 100644 --- a/tox.ini +++ b/tox.ini @@ -63,6 +63,7 @@ flake8-tuple>=0.2.8 flake8-print>=2.0.1 git+https://github.com/jayvdb/flake8-mock@use-ascii-readme + pep8-naming
[testenv:nose] commands = @@ -128,8 +129,9 @@ # D103: Missing docstring in public function # E402: module level import not at top of file; see T87409 # H201: Except: format +# N802, N803, N806 : naming convention # P102,P103: string does contain unindexed parameters; see I36355923 -ignore = C401,C402,C405,E402,D105,D211,FI10,FI12,FI13,FI15,FI16,FI17,FI5,H101,H201,H236,H301,H404,H405,I100,I101 +ignore = C401,C402,C405,E402,D105,D211,FI10,FI12,FI13,FI15,FI16,FI17,FI5,H101,H201,H236,H301,H404,H405,I100,I101,N802,N803,N806 exclude = .tox,.git,./*.egg,ez_setup.py,build,externals,user-config.py,./scripts/i18n/* min-version = 2.6 max_line_length = 100 @@ -140,19 +142,26 @@ generate_family_file.py : +T001, T003 pwb.py : +T001, T003 pywikibot/date.py,pywikibot/family.py,pywikibot/fixes.py,pywikibot/textlib.py,pywikibot/userinterfaces/terminal_interface_unix.py,pywikibot/userinterfaces/terminal_interface_win32.py,pywikibot/families/wikipedia_family.py : +E241 + pywikibot/textlib.py : +N801 + pywikibot/userinterfaces/transliteration.py : +N801 + pywikibot/userinterfaces/win32_unicode.py : +N801, N812 tests/page_tests.py : +E241 scripts/,/pagegenerators.parameterHelp/ : +E241 scripts/blockreview.py,scripts/imagetransfer.py,scripts/interwiki.py,scripts/maintenance/wikimedia_sites.py : +E241 - tests/ui_tests.py : +D102, D103 + tests/ui_tests.py : +D102, D103, N801 tests/__init__.py,tests/aspects.py,tests/script_tests.py,tests/site_detect_tests.py : +T001, T003 tests/pwb/ : +T001, T003 + tests/,/from pywikibot.tools import/ : +N813 scripts/imagetransfer.py : +T001, T003 + scripts/checkimages.py,scripts/imagecopy.py,scripts/imagecopy_self.py : +N801 scripts/maintenance/make_i18n_dict.py : +T001, T003 scripts/archive/featured.py : +D102, D103 scripts/script_wui.py : +D102 scripts/makecat.py : +D103 scripts/interwiki.py,/""/ : +P102 pywikibot/__init__.py,/link_regex/ : +P103 + # valid N805 naming convention exceptions + pywikibot/userinterfaces/terminal_interface.py,/from pywikibot.userinterfaces.terminal_interface_.* import .* as UI/ : +N814 # invalidly detected as {} format string: tests/textlib_tests.py,/self.assert.*{{/ : +P103 # __dict__ used in a discouraged manner
pywikibot-commits@lists.wikimedia.org