From patchwork Thu Dec 15 18:48:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [1, of, 5, pure-fix] tests: migrate test-bdiff.py to use unittest (part 1 of 4) From: Pierre-Yves David X-Patchwork-Id: 17927 Message-Id: <2f4724e8-87ca-1a2f-06f5-a2677d159d0a@ens-lyon.org> To: Augie Fackler , mercurial-devel Date: Thu, 15 Dec 2016 19:48:22 +0100 On 12/15/2016 05:36 PM, Augie Fackler wrote: > On Thu, Dec 15, 2016 at 11:32 AM, Augie Fackler wrote: >> @@ -1,44 +1,52 @@ >> from __future__ import absolute_import, print_function >> +import silenttestrunner >> import struct >> +import unittest >> + > > I got some weirdly inconsistent import-checking behavior out of these > lines on one machine, but can't reproduce it now. Given that this > looks very similar to the equivalent code in test-manifest.py, I'm not > going to sweat it. Apparently the import check do not take in account the change between stdlib / local when checking for lexical order. The following patch seems to fix that. Do you want a formal patch on the list or should I push that ? diff --git a/contrib/import-checker.py b/contrib/import-checker.py --- a/contrib/import-checker.py +++ b/contrib/import-checker.py @@ -391,6 +391,7 @@ def verify_modern_convention(module, roo seennonsymbollocal = False # The last name to be imported (for sorting). lastname = None + laststdlib = None # Relative import levels encountered so far. seenlevels = set() @@ -412,16 +413,18 @@ def verify_modern_convention(module, roo name = node.names[0].name asname = node.names[0].asname + stdlib = name in stdlib_modules + # Ignore sorting rules on imports inside blocks. if node.col_offset == root_col_offset: - if lastname and name < lastname: + if lastname and name < lastname and laststdlib == stdlib: yield msg('imports not lexically sorted: %s < %s', name, lastname) - lastname = name + lastname = name + laststdlib = stdlib # stdlib imports should be before local imports. - stdlib = name in stdlib_modules if stdlib and seenlocal and node.col_offset == root_col_offset: yield msg('stdlib import "%s" follows local import: %s', name, seenlocal) diff --git a/tests/test-bdiff.py b/tests/test-bdiff.py --- a/tests/test-bdiff.py +++ b/tests/test-bdiff.py @@ -1,8 +1,10 @@ from __future__ import absolute_import, print_function -import silenttestrunner + import struct import unittest +import silenttestrunner + from mercurial import ( bdiff, mpatch,