[PATCH 4 of 5 V2] tests: use absolute_import, print_funtion in multiple files

Robert Stanca robert.stanca7 at gmail.com
Fri Apr 1 02:12:06 UTC 2016


# HG changeset patch
# User Robert Stanca <robert.stanca7 at gmail.com>
# Date 1459470362 -10800
#      Fri Apr 01 03:26:02 2016 +0300
# Node ID 254e1fc8ec44b23af5e51cf971fdee5702065ff4
# Parent  31d3df7a74590e2e1fcd27a763c56bb312d6e464
tests: use absolute_import, print_funtion in multiple files

Eliminate Python3 compatibility warnings

diff -r 31d3df7a7459 -r 254e1fc8ec44 tests/test-check-py3-compat.t
--- a/tests/test-check-py3-compat.t	Fri Apr 01 02:55:17 2016 +0300
+++ b/tests/test-check-py3-compat.t	Fri Apr 01 03:26:02 2016 +0300
@@ -72,14 +72,8 @@
   tests/test-lrucachedict.py not using absolute_import
   tests/test-lrucachedict.py requires print_function
   tests/test-manifest.py not using absolute_import
-  tests/test-minirst.py not using absolute_import
-  tests/test-minirst.py requires print_function
-  tests/test-parseindex2.py not using absolute_import
-  tests/test-parseindex2.py requires print_function
   tests/test-pathencode.py not using absolute_import
   tests/test-pathencode.py requires print_function
-  tests/test-propertycache.py not using absolute_import
-  tests/test-propertycache.py requires print_function
   tests/test-revlog-ancestry.py not using absolute_import
   tests/test-revlog-ancestry.py requires print_function
   tests/test-run-tests.py not using absolute_import
@@ -264,9 +258,6 @@
   tests/test-ancestor.py: invalid syntax: Missing parentheses in call to 'print' (<unknown>, line *) (glob)
   tests/test-demandimport.py: invalid syntax: invalid syntax (<unknown>, line *) (glob)
   tests/test-lrucachedict.py: invalid syntax: invalid syntax (<unknown>, line *) (glob)
-  tests/test-minirst.py: invalid syntax: Missing parentheses in call to 'print' (<unknown>, line *) (glob)
-  tests/test-parseindex*.py: invalid syntax: Missing parentheses in call to 'print' (<unknown>, line *) (glob)
-  tests/test-propertycache.py: invalid syntax: Missing parentheses in call to 'print' (<unknown>, line *) (glob)
   tests/test-revlog-ancestry.py: invalid syntax: Missing parentheses in call to 'print' (<unknown>, line *) (glob)
   tests/test-status-inprocess.py: invalid syntax: Missing parentheses in call to 'print' (<unknown>, line *) (glob)
   tests/test-trusted.py: invalid syntax: invalid syntax (<unknown>, line *) (glob)
diff -r 31d3df7a7459 -r 254e1fc8ec44 tests/test-minirst.py
--- a/tests/test-minirst.py	Fri Apr 01 02:55:17 2016 +0300
+++ b/tests/test-minirst.py	Fri Apr 01 03:26:02 2016 +0300
@@ -1,26 +1,31 @@
-from pprint import pprint
-from mercurial import minirst
+from __future__ import absolute_import, print_function
+from pprint import (
+    pprint,
+)
+from mercurial import (
+    minirst,
+)
 
 def debugformat(text, form, **kwargs):
     if form == 'html':
-        print "html format:"
+        print("html format:")
         out = minirst.format(text, style=form, **kwargs)
     else:
-        print "%d column format:" % form
+        print("%d column format:" % form)
         out = minirst.format(text, width=form, **kwargs)
 
-    print "-" * 70
+    print("-" * 70)
     if type(out) == tuple:
-        print out[0][:-1]
-        print "-" * 70
+        print(out[0][:-1])
+        print("-" * 70)
         pprint(out[1])
     else:
-        print out[:-1]
-    print "-" * 70
-    print
+        print(out[:-1])
+    print("-" * 70)
+    print()
 
 def debugformats(title, text, **kwargs):
-    print "== %s ==" % title
+    print("== %s ==" % title)
     debugformat(text, 60, **kwargs)
     debugformat(text, 30, **kwargs)
     debugformat(text, 'html', **kwargs)
@@ -241,7 +246,7 @@
 rst = minirst.maketable(data, 2, True)
 table = ''.join(rst)
 
-print table
+print(table)
 
 debugformats('table', table)
 
@@ -251,7 +256,7 @@
 rst = minirst.maketable(data, 1, False)
 table = ''.join(rst)
 
-print table
+print(table)
 
 debugformats('table+nl', table)
 
diff -r 31d3df7a7459 -r 254e1fc8ec44 tests/test-parseindex2.py
--- a/tests/test-parseindex2.py	Fri Apr 01 02:55:17 2016 +0300
+++ b/tests/test-parseindex2.py	Fri Apr 01 03:26:02 2016 +0300
@@ -3,8 +3,14 @@
 It also checks certain aspects of the parsers module as a whole.
 """
 
-from mercurial import parsers
-from mercurial.node import nullid, nullrev
+from __future__ import absolute_import, print_function
+from mercurial import (
+    parsers,
+)
+from mercurial.node import (
+    nullid,
+    nullrev,
+)
 import struct
 import subprocess
 import sys
@@ -122,10 +128,10 @@
         hexstring = hex(hexversion)
     except TypeError:
         hexstring = None
-    print ("FAILED: version test #%s with Python %s and patched "
-           "sys.hexversion %r (%r):\n Expected %s but got:\n-->'%s'\n" %
-           (testnumber, sys.version_info, hexversion, hexstring, expected,
-            stdout))
+    print("FAILED: version test #%s with Python %s and patched "
+          "sys.hexversion %r (%r):\n Expected %s but got:\n-->'%s'\n" %
+          (testnumber, sys.version_info, hexversion, hexstring, expected,
+           stdout))
 
 def testversionokay(testnumber, hexversion):
     stdout, stderr = importparsers(hexversion)
@@ -170,7 +176,7 @@
     except TypeError:
         pass
     else:
-        print "Expected to get TypeError."
+        print("Expected to get TypeError.")
 
    # Check parsers.parse_index2() on an index file against the original
    # Python implementation of parseindex, both with and without inlined data.
@@ -182,10 +188,10 @@
     c_res_2 = parse_index2(data_non_inlined, False)
 
     if py_res_1 != c_res_1:
-        print "Parse index result (with inlined data) differs!"
+        print("Parse index result (with inlined data) differs!")
 
     if py_res_2 != c_res_2:
-        print "Parse index result (no inlined data) differs!"
+        print("Parse index result (no inlined data) differs!")
 
     ix = parsers.parse_index2(data_inlined, True)[0]
     for i, r in enumerate(ix):
@@ -193,11 +199,11 @@
             i = -1
         try:
             if ix[r[7]] != i:
-                print 'Reverse lookup inconsistent for %r' % r[7].encode('hex')
+                print('Reverse lookup inconsistent for %r' % r[7].encode('hex'))
         except TypeError:
             # pure version doesn't support this
             break
 
-    print "done"
+    print("done")
 
 runtest()
diff -r 31d3df7a7459 -r 254e1fc8ec44 tests/test-propertycache.py
--- a/tests/test-propertycache.py	Fri Apr 01 02:55:17 2016 +0300
+++ b/tests/test-propertycache.py	Fri Apr 01 03:26:02 2016 +0300
@@ -4,7 +4,9 @@
 property cache of both localrepo and repoview to prevent
 regression."""
 
-import os, subprocess
+from __future__ import absolute_import, print_function
+import os
+import subprocess
 import mercurial.localrepo
 import mercurial.repoview
 import mercurial.util
@@ -47,133 +49,133 @@
 repo = mercurial.hg.repository(ui, path=repopath).unfiltered()
 
 
-print ''
-print '=== property cache ==='
-print ''
-print 'calllog:', calllog
-print 'cached value (unfiltered):',
-print vars(repo).get('testcachedfoobar', 'NOCACHE')
+print('')
+print('=== property cache ===')
+print('')
+print('calllog:', calllog)
+print('cached value (unfiltered):',
+    vars(repo).get('testcachedfoobar', 'NOCACHE'))
 
-print ''
-print '= first access on unfiltered, should do a call'
-print 'access:', repo.testcachedfoobar
-print 'calllog:', calllog
-print 'cached value (unfiltered):',
-print vars(repo).get('testcachedfoobar', 'NOCACHE')
+print('')
+print('= first access on unfiltered, should do a call')
+print('access:', repo.testcachedfoobar)
+print('calllog:', calllog)
+print('cached value (unfiltered):',
+    vars(repo).get('testcachedfoobar', 'NOCACHE'))
 
-print ''
-print '= second access on unfiltered, should not do call'
-print 'access', repo.testcachedfoobar
-print 'calllog:', calllog
-print 'cached value (unfiltered):',
-print vars(repo).get('testcachedfoobar', 'NOCACHE')
+print('')
+print('= second access on unfiltered, should not do call')
+print('access', repo.testcachedfoobar)
+print('calllog:', calllog)
+print('cached value (unfiltered):',
+    vars(repo).get('testcachedfoobar', 'NOCACHE'))
 
-print ''
-print '= first access on "visible" view, should do a call'
+print('')
+print('= first access on "visible" view, should do a call')
 visibleview = repo.filtered('visible')
-print 'cached value ("visible" view):',
-print vars(visibleview).get('testcachedfoobar', 'NOCACHE')
-print 'access:', visibleview.testcachedfoobar
-print 'calllog:', calllog
-print 'cached value (unfiltered):',
-print vars(repo).get('testcachedfoobar', 'NOCACHE')
-print 'cached value ("visible" view):',
-print vars(visibleview).get('testcachedfoobar', 'NOCACHE')
+print('cached value ("visible" view):',
+    vars(visibleview).get('testcachedfoobar', 'NOCACHE'))
+print('access:', visibleview.testcachedfoobar)
+print('calllog:', calllog)
+print('cached value (unfiltered):',
+    vars(repo).get('testcachedfoobar', 'NOCACHE'))
+print('cached value ("visible" view):',
+    vars(visibleview).get('testcachedfoobar', 'NOCACHE'))
 
-print ''
-print '= second access on "visible view", should not do call'
-print 'access:', visibleview.testcachedfoobar
-print 'calllog:', calllog
-print 'cached value (unfiltered):',
-print vars(repo).get('testcachedfoobar', 'NOCACHE')
-print 'cached value ("visible" view):',
-print vars(visibleview).get('testcachedfoobar', 'NOCACHE')
+print('')
+print('= second access on "visible view", should not do call')
+print('access:', visibleview.testcachedfoobar)
+print('calllog:', calllog)
+print('cached value (unfiltered):',
+    vars(repo).get('testcachedfoobar', 'NOCACHE'))
+print('cached value ("visible" view):',
+    vars(visibleview).get('testcachedfoobar', 'NOCACHE'))
 
-print ''
-print '= no effect on other view'
+print('')
+print('= no effect on other view')
 immutableview = repo.filtered('immutable')
-print 'cached value ("immutable" view):',
-print vars(immutableview).get('testcachedfoobar', 'NOCACHE')
-print 'access:', immutableview.testcachedfoobar
-print 'calllog:', calllog
-print 'cached value (unfiltered):',
-print vars(repo).get('testcachedfoobar', 'NOCACHE')
-print 'cached value ("visible" view):',
-print vars(visibleview).get('testcachedfoobar', 'NOCACHE')
-print 'cached value ("immutable" view):',
-print vars(immutableview).get('testcachedfoobar', 'NOCACHE')
+print('cached value ("immutable" view):',
+    vars(immutableview).get('testcachedfoobar', 'NOCACHE'))
+print('access:', immutableview.testcachedfoobar)
+print('calllog:', calllog)
+print('cached value (unfiltered):',
+    vars(repo).get('testcachedfoobar', 'NOCACHE'))
+print('cached value ("visible" view):',
+    vars(visibleview).get('testcachedfoobar', 'NOCACHE'))
+print('cached value ("immutable" view):',
+    vars(immutableview).get('testcachedfoobar', 'NOCACHE'))
 
 # unfiltered property cache test
-print ''
-print ''
-print '=== unfiltered property cache ==='
-print ''
-print 'unficalllog:', unficalllog
-print 'cached value (unfiltered):      ',
-print vars(repo).get('testcachedunfifoobar', 'NOCACHE')
-print 'cached value ("visible" view):  ',
-print vars(visibleview).get('testcachedunfifoobar', 'NOCACHE')
-print 'cached value ("immutable" view):',
-print vars(immutableview).get('testcachedunfifoobar', 'NOCACHE')
+print('')
+print('')
+print('=== unfiltered property cache ===')
+print('')
+print('unficalllog:', unficalllog)
+print('cached value (unfiltered):      ',
+    vars(repo).get('testcachedunfifoobar', 'NOCACHE'))
+print('cached value ("visible" view):  ',
+    vars(visibleview).get('testcachedunfifoobar', 'NOCACHE'))
+print('cached value ("immutable" view):',
+    vars(immutableview).get('testcachedunfifoobar', 'NOCACHE'))
 
-print ''
-print '= first access on unfiltered, should do a call'
-print 'access (unfiltered):', repo.testcachedunfifoobar
-print 'unficalllog:', unficalllog
-print 'cached value (unfiltered):      ',
-print vars(repo).get('testcachedunfifoobar', 'NOCACHE')
+print('')
+print('= first access on unfiltered, should do a call')
+print('access (unfiltered):', repo.testcachedunfifoobar)
+print('unficalllog:', unficalllog)
+print('cached value (unfiltered):      ',
+    vars(repo).get('testcachedunfifoobar', 'NOCACHE'))
 
-print ''
-print '= second access on unfiltered, should not do call'
-print 'access (unfiltered):', repo.testcachedunfifoobar
-print 'unficalllog:', unficalllog
-print 'cached value (unfiltered):      ',
-print vars(repo).get('testcachedunfifoobar', 'NOCACHE')
+print('')
+print('= second access on unfiltered, should not do call')
+print('access (unfiltered):', repo.testcachedunfifoobar)
+print('unficalllog:', unficalllog)
+print('cached value (unfiltered):      ',
+    vars(repo).get('testcachedunfifoobar', 'NOCACHE'))
 
-print ''
-print '= access on view should use the unfiltered cache'
-print 'access (unfiltered):      ', repo.testcachedunfifoobar
-print 'access ("visible" view):  ', visibleview.testcachedunfifoobar
-print 'access ("immutable" view):', immutableview.testcachedunfifoobar
-print 'unficalllog:', unficalllog
-print 'cached value (unfiltered):      ',
-print vars(repo).get('testcachedunfifoobar', 'NOCACHE')
-print 'cached value ("visible" view):  ',
-print vars(visibleview).get('testcachedunfifoobar', 'NOCACHE')
-print 'cached value ("immutable" view):',
-print vars(immutableview).get('testcachedunfifoobar', 'NOCACHE')
+print('')
+print('= access on view should use the unfiltered cache')
+print('access (unfiltered):      ', repo.testcachedunfifoobar)
+print('access ("visible" view):  ', visibleview.testcachedunfifoobar)
+print('access ("immutable" view):', immutableview.testcachedunfifoobar)
+print('unficalllog:', unficalllog)
+print('cached value (unfiltered):      ',
+    vars(repo).get('testcachedunfifoobar', 'NOCACHE'))
+print('cached value ("visible" view):  ',
+    vars(visibleview).get('testcachedunfifoobar', 'NOCACHE'))
+print('cached value ("immutable" view):',
+    vars(immutableview).get('testcachedunfifoobar', 'NOCACHE'))
 
-print ''
-print '= even if we clear the unfiltered cache'
+print('')
+print('= even if we clear the unfiltered cache')
 del repo.__dict__['testcachedunfifoobar']
-print 'cached value (unfiltered):      ',
-print vars(repo).get('testcachedunfifoobar', 'NOCACHE')
-print 'cached value ("visible" view):  ',
-print vars(visibleview).get('testcachedunfifoobar', 'NOCACHE')
-print 'cached value ("immutable" view):',
-print vars(immutableview).get('testcachedunfifoobar', 'NOCACHE')
-print 'unficalllog:', unficalllog
-print 'access ("visible" view):  ', visibleview.testcachedunfifoobar
-print 'unficalllog:', unficalllog
-print 'cached value (unfiltered):      ',
-print vars(repo).get('testcachedunfifoobar', 'NOCACHE')
-print 'cached value ("visible" view):  ',
-print vars(visibleview).get('testcachedunfifoobar', 'NOCACHE')
-print 'cached value ("immutable" view):',
-print vars(immutableview).get('testcachedunfifoobar', 'NOCACHE')
-print 'access ("immutable" view):', immutableview.testcachedunfifoobar
-print 'unficalllog:', unficalllog
-print 'cached value (unfiltered):      ',
-print vars(repo).get('testcachedunfifoobar', 'NOCACHE')
-print 'cached value ("visible" view):  ',
-print vars(visibleview).get('testcachedunfifoobar', 'NOCACHE')
-print 'cached value ("immutable" view):',
-print vars(immutableview).get('testcachedunfifoobar', 'NOCACHE')
-print 'access (unfiltered):      ', repo.testcachedunfifoobar
-print 'unficalllog:', unficalllog
-print 'cached value (unfiltered):      ',
-print vars(repo).get('testcachedunfifoobar', 'NOCACHE')
-print 'cached value ("visible" view):  ',
-print vars(visibleview).get('testcachedunfifoobar', 'NOCACHE')
-print 'cached value ("immutable" view):',
-print vars(immutableview).get('testcachedunfifoobar', 'NOCACHE')
+print('cached value (unfiltered):      ',
+    vars(repo).get('testcachedunfifoobar', 'NOCACHE'))
+print('cached value ("visible" view):  ',
+    vars(visibleview).get('testcachedunfifoobar', 'NOCACHE'))
+print('cached value ("immutable" view):',
+    vars(immutableview).get('testcachedunfifoobar', 'NOCACHE'))
+print('unficalllog:', unficalllog)
+print('access ("visible" view):  ', visibleview.testcachedunfifoobar)
+print('unficalllog:', unficalllog)
+print('cached value (unfiltered):      ',
+    vars(repo).get('testcachedunfifoobar', 'NOCACHE'))
+print('cached value ("visible" view):  ',
+    vars(visibleview).get('testcachedunfifoobar', 'NOCACHE'))
+print('cached value ("immutable" view):',
+    vars(immutableview).get('testcachedunfifoobar', 'NOCACHE'))
+print('access ("immutable" view):', immutableview.testcachedunfifoobar)
+print('unficalllog:', unficalllog)
+print('cached value (unfiltered):      ',
+    vars(repo).get('testcachedunfifoobar', 'NOCACHE'))
+print('cached value ("visible" view):  ',
+    vars(visibleview).get('testcachedunfifoobar', 'NOCACHE'))
+print('cached value ("immutable" view):',
+    vars(immutableview).get('testcachedunfifoobar', 'NOCACHE'))
+print('access (unfiltered):      ', repo.testcachedunfifoobar)
+print('unficalllog:', unficalllog)
+print('cached value (unfiltered):      ',
+    vars(repo).get('testcachedunfifoobar', 'NOCACHE'))
+print('cached value ("visible" view):  ',
+    vars(visibleview).get('testcachedunfifoobar', 'NOCACHE'))
+print('cached value ("immutable" view):',
+    vars(immutableview).get('testcachedunfifoobar', 'NOCACHE'))


More information about the Mercurial-devel mailing list