Patchwork [1,of,5,pure-fix] tests: migrate test-bdiff.py to use unittest (part 1 of 4)

login
register
mail settings
Submitter Pierre-Yves David
Date Dec. 15, 2016, 6:48 p.m.
Message ID <2f4724e8-87ca-1a2f-06f5-a2677d159d0a@ens-lyon.org>
Download mbox | patch
Permalink /patch/17927/
State Not Applicable
Headers show

Comments

Pierre-Yves David - Dec. 15, 2016, 6:48 p.m.
On 12/15/2016 05:36 PM, Augie Fackler wrote:
> On Thu, Dec 15, 2016 at 11:32 AM, Augie Fackler <raf@durin42.com> 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 ?
Augie Fackler - Dec. 15, 2016, 10:33 p.m.
> On Dec 15, 2016, at 1:48 PM, Pierre-Yves David <pierre-yves.david@ens-lyon.org> wrote:
> 
> 
> 
> On 12/15/2016 05:36 PM, Augie Fackler wrote:
>> On Thu, Dec 15, 2016 at 11:32 AM, Augie Fackler <raf@durin42.com> 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 ?

Per IRC conversation, I’ve taken marmoute’s fix to the import checker, will fix my patches to pass the corrected import checker and will then push all six of them. We may revisit the mechanism by which pure is fixed later, but this at least makes the build green.

Patch

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,