[pacman-dev] [PATCH 0/8] Wondering if Python 3 could run the tests?
The short answer is: yes, it can. The slightly longer answer is: with these patches the test framework is compatible with any Python from 2.5 up to 3.3. Relax: none of these patches actually change which version gets used during a build. This is just an exploration of what is needed to get over the bump from Python 2 to 3. This experiment came about as I was working on the -Qk(k) unit tests. I realized that I had used a 2.7 specific feature, and I stopped to grep through the code and the mailing list to see if that was a no-no. That lead me to trying out 2.6 and then 2.5 to see what version the framework needed. Patch 1 is about that lower end of the scale. This naturally got me wondering about the upper end and how much pain it would be to move in that direction. Python offers tools to help migration. Patch 2 came from running "python2 -3". And patches 3 thru 7 came from "2to3" (split into commits by the specific issue). After those the code was syntactically acceptable to 3.3, and so the last two issues, fixed in Patch 8, came from runtime exceptions. Most of the difficult work was setting up a test environment for the pactest framework so I could be assured that the changes suggested by the migration tools wouldn't break anything. And splitting up what "2to3" reported into commits that would make sense. I am ambivalent on the prosepect of accepting these patches into the code base. Python 2.7 isn't going to disappear tomorrow, so there's no fire. There are no features in 3.x that are must-have solutions to a pain point. Nothing's really broken, so these patches aren't really fixing anything. All very true. The only advantage I can think of is that it might entice more people into writing more tests if they could use they shiny (overly hyped?) new 3.x features instead of that old boring 2.7 stuff. At the very least I would suggest that it would be very helpful to explicitly state somewhere in the test framework code the minimum version needed. I've determined it could be set to 2.5 (no, I did not check lower than that), but it would make much more sense to pick 2.7. Assuming, that is, that the consensus will be that jumping to 3.x is a bridge too far. Jeremy Heiner (8): Restore ability to run tests with version 2.5 of Python. Use Python's "exec" instead of deprecated "execfile". Python 3 octal literals broke backwards compatibility. Add shims to return views on Python dicts. Add shims to return a new Python StringIO instance. Use Python's "range" instead of deprecated "xrange". Add parens around tuples in Python for comprehensions. Allow tests to be run with either version 2 or 3 of Python. test/pacman/pmdb.py | 7 +++--- test/pacman/pmpkg.py | 11 +++++---- test/pacman/pmtest.py | 14 +++++++---- test/pacman/tests/depconflict100.py | 2 +- test/pacman/tests/depconflict120.py | 2 +- test/pacman/tests/epoch005.py | 2 +- test/pacman/tests/fileconflict001.py | 2 +- test/pacman/tests/fileconflict002.py | 2 +- test/pacman/tests/query006.py | 3 +-- test/pacman/tests/remove052.py | 2 +- test/pacman/tests/smoke001.py | 4 +-- test/pacman/tests/smoke003.py | 4 +-- test/pacman/tests/sync030.py | 2 +- test/pacman/tests/sync031.py | 2 +- test/pacman/tests/sync040.py | 2 +- test/pacman/tests/sync041.py | 2 +- test/pacman/tests/sync405.py | 2 +- test/pacman/tests/sync406.py | 2 +- test/pacman/tests/sync891.py | 2 +- test/pacman/tests/sync892.py | 2 +- test/pacman/tests/sync893.py | 2 +- test/pacman/tests/sync898.py | 2 +- test/pacman/tests/sync990.py | 2 +- test/pacman/tests/sync992.py | 2 +- test/pacman/tests/upgrade005.py | 2 +- test/pacman/tests/upgrade013.py | 2 +- test/pacman/tests/upgrade014.py | 2 +- test/pacman/tests/upgrade030.py | 2 +- test/pacman/tests/upgrade031.py | 2 +- test/pacman/tests/upgrade032.py | 2 +- test/pacman/tests/upgrade040.py | 2 +- test/pacman/tests/upgrade041.py | 2 +- test/pacman/tests/upgrade042.py | 2 +- test/pacman/tests/upgrade043.py | 2 +- test/pacman/tests/upgrade046.py | 2 +- test/pacman/tests/upgrade050.py | 2 +- test/pacman/tests/upgrade059.py | 2 +- test/pacman/tests/upgrade060.py | 2 +- test/pacman/tests/upgrade061.py | 2 +- test/pacman/tests/upgrade073.py | 2 +- test/pacman/tests/upgrade090.py | 2 +- test/pacman/tests/xfercommand001.py | 2 +- test/pacman/util.py | 47 ++++++++++++++++++++++++++++++------ 43 files changed, 99 insertions(+), 63 deletions(-) -- 1.8.4
Running the tests with various Python versions revealed that exactly one 2.6 feature had been introduced: sys.maxsize was used in the "query006" test. Now it uses sys.maxsize where available and falls back to use sys.maxint. Note that the test function is not affected at all. The only possible consequence of this change is that the test might not be flagged as expected to fail, and thus "TODO" might not be appended to the failure message. The only effect would be to overstate the severity of a failure on this test. And this could only happen in environments where (without this patch) the test would crash the whole pactest framework with an AttributeError. The "mode001" test was running but indicated a failure on the 2.5 runtime. Package tars built by the pactest framework on that runtime had permissions set to 0666 for files (instead of 0644) when the caller failed to explicitly set that field in the TarInfo. With this patch the tests were run by the author with these Python versions: 2.5.6, 2.6.8 and 2.7.5. On all those runtimes these five tests (all marked expected to fail) failed: query006, replace110, sync403, sync406, upgrade078. And all other tests passed. What does this accomplish? By itself, not much. Obviously nobody is using 2.5, or if they are they haven't mentioned the AttributeError. And nobody is going to start. But it sets up a test of the testing framework for the sequence of commits to follow. Having extended the range of runtimes back to 2.5, the next several commits aim to extend it forward without breaking anything for these older runtimes. Signed-off-by: Jeremy Heiner <ScalaProtractor at gmail.com> --- test/pacman/pmpkg.py | 2 ++ test/pacman/tests/query006.py | 3 +-- test/pacman/util.py | 9 +++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/test/pacman/pmpkg.py b/test/pacman/pmpkg.py index 9b3147a..c60f11b 100644 --- a/test/pacman/pmpkg.py +++ b/test/pacman/pmpkg.py @@ -162,6 +162,8 @@ def makepkg(self, path): info.mode = fileinfo["perms"] elif fileinfo["isdir"]: info.mode = 0755 + elif not fileinfo["islink"]: + info.mode = 0644 if fileinfo["isdir"]: info.type = tarfile.DIRTYPE tar.addfile(info) diff --git a/test/pacman/tests/query006.py b/test/pacman/tests/query006.py index 0f6f762..ed7ac40 100644 --- a/test/pacman/tests/query006.py +++ b/test/pacman/tests/query006.py @@ -25,6 +25,5 @@ self.addrule("PACMAN_OUTPUT=^Install Date.* 2286") # expect failure on 32bit systems -import sys -if sys.maxsize <= 2**32: +if util.sys_maxsize <= 2**32: self.expectfailure = True diff --git a/test/pacman/util.py b/test/pacman/util.py index 14035d7..62f88f9 100644 --- a/test/pacman/util.py +++ b/test/pacman/util.py @@ -19,6 +19,7 @@ import os import re +import sys import hashlib import tap @@ -47,6 +48,14 @@ def vprint(msg): if verbose: tap.diag(msg) + +# +# Python version sensitive stuff +# + +sys_maxsize = sys.maxsize if sys.hexversion >= 0x02060000 else sys.maxint + + # # Methods to generate files # -- 1.8.4
On 10/10/13 10:35, Jeremy Heiner wrote:
Running the tests with various Python versions revealed that exactly one 2.6 feature had been introduced: sys.maxsize was used in the "query006" test. Now it uses sys.maxsize where available and falls back to use sys.maxint.
python-2.5 is EOL upstream. I see no need to support software that is not supported by its developers. Allan
On 10/10/13 12:45, Allan McRae wrote:
On 10/10/13 10:35, Jeremy Heiner wrote:
Running the tests with various Python versions revealed that exactly one 2.6 feature had been introduced: sys.maxsize was used in the "query006" test. Now it uses sys.maxsize where available and falls back to use sys.maxint.
python-2.5 is EOL upstream. I see no need to support software that is not supported by its developers.
In fact, python 2.6 will be EOL with 2.6.9 which is released this month. I'd say not even to support that. Allan
On Wed, Oct 9, 2013 at 11:16 PM, Allan McRae <allan@archlinux.org> wrote:
In fact, python 2.6 will be EOL with 2.6.9 which is released this month. I'd say not even to support that.
I wholeheartedly agree, but obviously I haven't earned the right yet to post patches that make decisions of that impact. And I thought it would be interesting to have an inventory of what features were already in use. I only included 2.5 in my testing because in all the code there was only just one use of a 2.6 feature. How does everyone feel about adding "if version less than 2.7 then throw an exception" to pactest main to document this decision? Jeremy
This was the only issue reported by "python2 -3". Signed-off-by: Jeremy Heiner <ScalaProtractor at gmail.com> --- test/pacman/pmtest.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/pacman/pmtest.py b/test/pacman/pmtest.py index b343d55..c183161 100644 --- a/test/pacman/pmtest.py +++ b/test/pacman/pmtest.py @@ -100,7 +100,11 @@ def load(self): if os.path.isfile(self.name): # all tests expect this to be available from pmpkg import pmpkg - execfile(self.name) + input = open(self.name) + try: # a "with" would be perfect here... + exec(input.read()) + finally: # ...but isn't available in Python 2.5 + input.close() else: raise IOError("file %s does not exist!" % self.name) -- 1.8.4
On 10/10/13 10:35, Jeremy Heiner wrote:
This was the only issue reported by "python2 -3".
Signed-off-by: Jeremy Heiner <ScalaProtractor at gmail.com> --- test/pacman/pmtest.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/test/pacman/pmtest.py b/test/pacman/pmtest.py index b343d55..c183161 100644 --- a/test/pacman/pmtest.py +++ b/test/pacman/pmtest.py @@ -100,7 +100,11 @@ def load(self): if os.path.isfile(self.name): # all tests expect this to be available from pmpkg import pmpkg - execfile(self.name) + input = open(self.name) + try: # a "with" would be perfect here... + exec(input.read()) + finally: # ...but isn't available in Python 2.5
Why is that comment split in two? Anyway, there is no python-2.5, so use the with.
+ input.close() else: raise IOError("file %s does not exist!" % self.name)
Reported by 2to3. The suggested fix (use the 0o# format) won't work here because that syntax is not recognized by 2.5. Signed-off-by: Jeremy Heiner <ScalaProtractor at gmail.com> Conflicts: test/pacman/pmpkg.py --- test/pacman/pmpkg.py | 4 ++-- test/pacman/pmtest.py | 2 +- test/pacman/util.py | 10 +++++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/test/pacman/pmpkg.py b/test/pacman/pmpkg.py index c60f11b..0c1ea68 100644 --- a/test/pacman/pmpkg.py +++ b/test/pacman/pmpkg.py @@ -161,9 +161,9 @@ def makepkg(self, path): if fileinfo["hasperms"]: info.mode = fileinfo["perms"] elif fileinfo["isdir"]: - info.mode = 0755 + info.mode = util.PERM_DIR elif not fileinfo["islink"]: - info.mode = 0644 + info.mode = util.PERM_FILE if fileinfo["isdir"]: info.type = tarfile.DIRTYPE tar.addfile(info) diff --git a/test/pacman/pmtest.py b/test/pacman/pmtest.py index c183161..57e6538 100644 --- a/test/pacman/pmtest.py +++ b/test/pacman/pmtest.py @@ -134,7 +134,7 @@ def generate(self, pacman): for sys_dir in sys_dirs: if not os.path.isdir(sys_dir): vprint("\t%s" % sys_dir[len(self.root)+1:]) - os.makedirs(sys_dir, 0755) + os.makedirs(sys_dir, util.PERM_DIR) # Only the dynamically linked binary is needed for fakechroot shutil.copy("/bin/sh", bindir) if shell != "bin/sh": diff --git a/test/pacman/util.py b/test/pacman/util.py index 62f88f9..77dd804 100644 --- a/test/pacman/util.py +++ b/test/pacman/util.py @@ -55,6 +55,10 @@ def vprint(msg): sys_maxsize = sys.maxsize if sys.hexversion >= 0x02060000 else sys.maxint +# 2.5 won't accept 0o#, and 3.x won't accept 0#, so... +PERM_DIR = int("755",8) # 0o755 +PERM_FILE = int("644",8) # 0o644 + # # Methods to generate files @@ -93,12 +97,12 @@ def mkfile(base, name, data=""): path = os.path.join(base, filename) if info["isdir"]: if not os.path.isdir(path): - os.makedirs(path, 0755) + os.makedirs(path, PERM_DIR) return dir_path = os.path.dirname(path) if dir_path and not os.path.isdir(dir_path): - os.makedirs(dir_path, 0755) + os.makedirs(dir_path, PERM_DIR) if info["islink"]: os.symlink(info["link"], path) @@ -191,6 +195,6 @@ def mkdir(path): return elif os.path.isfile(path): raise OSError("'%s' already exists and is not a directory" % path) - os.makedirs(path, 0755) + os.makedirs(path, PERM_DIR) # vim: set ts=4 sw=4 et: -- 1.8.4
On 10/10/13 10:35, Jeremy Heiner wrote:
Reported by 2to3. The suggested fix (use the 0o# format) won't work here because that syntax is not recognized by 2.5.
No python-2.5. Use other format.
Signed-off-by: Jeremy Heiner <ScalaProtractor at gmail.com>
Conflicts: test/pacman/pmpkg.py --- test/pacman/pmpkg.py | 4 ++-- test/pacman/pmtest.py | 2 +- test/pacman/util.py | 10 +++++++--- 3 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/test/pacman/pmpkg.py b/test/pacman/pmpkg.py index c60f11b..0c1ea68 100644 --- a/test/pacman/pmpkg.py +++ b/test/pacman/pmpkg.py @@ -161,9 +161,9 @@ def makepkg(self, path): if fileinfo["hasperms"]: info.mode = fileinfo["perms"] elif fileinfo["isdir"]: - info.mode = 0755 + info.mode = util.PERM_DIR elif not fileinfo["islink"]: - info.mode = 0644 + info.mode = util.PERM_FILE if fileinfo["isdir"]: info.type = tarfile.DIRTYPE tar.addfile(info) diff --git a/test/pacman/pmtest.py b/test/pacman/pmtest.py index c183161..57e6538 100644 --- a/test/pacman/pmtest.py +++ b/test/pacman/pmtest.py @@ -134,7 +134,7 @@ def generate(self, pacman): for sys_dir in sys_dirs: if not os.path.isdir(sys_dir): vprint("\t%s" % sys_dir[len(self.root)+1:]) - os.makedirs(sys_dir, 0755) + os.makedirs(sys_dir, util.PERM_DIR) # Only the dynamically linked binary is needed for fakechroot shutil.copy("/bin/sh", bindir) if shell != "bin/sh": diff --git a/test/pacman/util.py b/test/pacman/util.py index 62f88f9..77dd804 100644 --- a/test/pacman/util.py +++ b/test/pacman/util.py @@ -55,6 +55,10 @@ def vprint(msg):
sys_maxsize = sys.maxsize if sys.hexversion >= 0x02060000 else sys.maxint
+# 2.5 won't accept 0o#, and 3.x won't accept 0#, so... +PERM_DIR = int("755",8) # 0o755 +PERM_FILE = int("644",8) # 0o644 +
# # Methods to generate files @@ -93,12 +97,12 @@ def mkfile(base, name, data=""): path = os.path.join(base, filename) if info["isdir"]: if not os.path.isdir(path): - os.makedirs(path, 0755) + os.makedirs(path, PERM_DIR) return
dir_path = os.path.dirname(path) if dir_path and not os.path.isdir(dir_path): - os.makedirs(dir_path, 0755) + os.makedirs(dir_path, PERM_DIR)
if info["islink"]: os.symlink(info["link"], path) @@ -191,6 +195,6 @@ def mkdir(path): return elif os.path.isfile(path): raise OSError("'%s' already exists and is not a directory" % path) - os.makedirs(path, 0755) + os.makedirs(path, PERM_DIR)
# vim: set ts=4 sw=4 et:
Reported by 2to3. The .items, .keys, and .values methods in Python 2 make expensive copies, so the test framework uses the .iter* flavors. But in Python 3 the .iter* (and even the 2.7 .view*) flavors are removed and the original methods return fast views. The shims examine the runtime's version and calls the right method to avoid making copies. Signed-off-by: Jeremy Heiner <ScalaProtractor at gmail.com> --- test/pacman/pmdb.py | 4 ++-- test/pacman/pmpkg.py | 2 +- test/pacman/pmtest.py | 6 +++--- test/pacman/util.py | 15 ++++++++++++--- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/test/pacman/pmdb.py b/test/pacman/pmdb.py index b7b3522..f4bc71d 100644 --- a/test/pacman/pmdb.py +++ b/test/pacman/pmdb.py @@ -236,7 +236,7 @@ def generate(self): for pkg, entry in pkg_entries: path = os.path.join(self.dbdir, pkg.fullname()) util.mkdir(path) - for name, data in entry.iteritems(): + for name, data in util.itemsview(entry): util.mkfile(path, name, data) if self.dbfile: @@ -247,7 +247,7 @@ def generate(self): info = tarfile.TarInfo(pkg.fullname()) info.type = tarfile.DIRTYPE tar.addfile(info) - for name, data in entry.iteritems(): + for name, data in util.itemsview(entry): filename = os.path.join(pkg.fullname(), name) info = tarfile.TarInfo(filename) info.size = len(data) diff --git a/test/pacman/pmpkg.py b/test/pacman/pmpkg.py index 0c1ea68..69734b0 100644 --- a/test/pacman/pmpkg.py +++ b/test/pacman/pmpkg.py @@ -225,7 +225,7 @@ def local_backup_entries(self): def installfile(self): data = [] - for key, value in self.install.iteritems(): + for key, value in util.itemsview(self.install): if value: data.append("%s() {\n%s\n}\n" % (key, value)) diff --git a/test/pacman/pmtest.py b/test/pacman/pmtest.py index 57e6538..a3e4a47 100644 --- a/test/pacman/pmtest.py +++ b/test/pacman/pmtest.py @@ -58,7 +58,7 @@ def findpkg(self, name, version, allow_local=False): """Find a package object matching the name and version specified in either sync databases or the local package collection. The local database is allowed to match if allow_local is True.""" - for db in self.db.itervalues(): + for db in util.valuesview(self.db): if db.is_local and not allow_local: continue pkg = db.getpkg(name) @@ -154,7 +154,7 @@ def generate(self, pacman): vprint("\t%s" % os.path.join(util.TMPDIR, pkg.filename())) pkg.finalize() pkg.makepkg(tmpdir) - for key, value in self.db.iteritems(): + for key, value in util.itemsview(self.db): for pkg in value.pkgs: pkg.finalize() if key == "local" and not self.createlocalpkgs: @@ -170,7 +170,7 @@ def generate(self, pacman): # Creating sync database archives vprint(" Creating databases") - for key, value in self.db.iteritems(): + for key, value in util.itemsview(self.db): vprint("\t" + value.treename) value.generate() diff --git a/test/pacman/util.py b/test/pacman/util.py index 77dd804..107a224 100644 --- a/test/pacman/util.py +++ b/test/pacman/util.py @@ -59,6 +59,15 @@ def vprint(msg): PERM_DIR = int("755",8) # 0o755 PERM_FILE = int("644",8) # 0o644 +def keysview(x): + return x.keys() if sys.hexversion >= 0x03000000 else x.iterkeys() + +def valuesview(x): + return x.values() if sys.hexversion >= 0x03000000 else x.itervalues() + +def itemsview(x): + return x.items() if sys.hexversion >= 0x03000000 else x.iteritems() + # # Methods to generate files @@ -125,13 +134,13 @@ def writedata(filename, data): def mkcfgfile(filename, root, option, db): # Options data = ["[options]"] - for key, value in option.iteritems(): + for key, value in itemsview(option): data.extend(["%s = %s" % (key, j) for j in value]) # Repositories # sort by repo name so tests can predict repo order, rather than be # subjects to the whims of python dict() ordering - for key in sorted(db.iterkeys()): + for key in sorted(keysview(db)): if key != "local": value = db[key] data.append("[%s]\n" \ @@ -139,7 +148,7 @@ def mkcfgfile(filename, root, option, db): "Server = file://%s" \ % (value.treename, value.getverify(), \ os.path.join(root, SYNCREPO, value.treename))) - for optkey, optval in value.option.iteritems(): + for optkey, optval in itemsview(value.option): data.extend(["%s = %s" % (optkey, j) for j in optval]) mkfile(root, filename, "\n".join(data)) -- 1.8.4
On 10 October 2013 00:35, Jeremy Heiner <scalaprotractor@gmail.com> wrote:
Reported by 2to3. The .items, .keys, and .values methods in Python 2 make expensive copies, so the test framework uses the .iter* flavors. But in Python 3 the .iter* (and even the 2.7 .view*) flavors are removed and the original methods return fast views. The shims examine the runtime's version and calls the right method to avoid making copies.
Perhaps it might be simpler to just use Python 3’s items() etc methods directly. That tends to also work with Python < 3 in most cases. I admit I’ve never used Pacman’s test suite so perhaps the extra expense would be significant under Python 2? Anyway unless there is a good reason to still prefer Python 2.7, I’d say keep it simple and use plain Python 3 code.
Signed-off-by: Jeremy Heiner <ScalaProtractor at gmail.com> --- test/pacman/pmdb.py | 4 ++-- test/pacman/pmpkg.py | 2 +- test/pacman/pmtest.py | 6 +++--- test/pacman/util.py | 15 ++++++++++++--- 4 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/test/pacman/pmdb.py b/test/pacman/pmdb.py index b7b3522..f4bc71d 100644 --- a/test/pacman/pmdb.py +++ b/test/pacman/pmdb.py @@ -236,7 +236,7 @@ def generate(self): for pkg, entry in pkg_entries: path = os.path.join(self.dbdir, pkg.fullname()) util.mkdir(path) - for name, data in entry.iteritems(): + for name, data in util.itemsview(entry): util.mkfile(path, name, data)
if self.dbfile: @@ -247,7 +247,7 @@ def generate(self): info = tarfile.TarInfo(pkg.fullname()) info.type = tarfile.DIRTYPE tar.addfile(info) - for name, data in entry.iteritems(): + for name, data in util.itemsview(entry): filename = os.path.join(pkg.fullname(), name) info = tarfile.TarInfo(filename) info.size = len(data) diff --git a/test/pacman/pmpkg.py b/test/pacman/pmpkg.py index 0c1ea68..69734b0 100644 --- a/test/pacman/pmpkg.py +++ b/test/pacman/pmpkg.py @@ -225,7 +225,7 @@ def local_backup_entries(self):
def installfile(self): data = [] - for key, value in self.install.iteritems(): + for key, value in util.itemsview(self.install): if value: data.append("%s() {\n%s\n}\n" % (key, value))
diff --git a/test/pacman/pmtest.py b/test/pacman/pmtest.py index 57e6538..a3e4a47 100644 --- a/test/pacman/pmtest.py +++ b/test/pacman/pmtest.py @@ -58,7 +58,7 @@ def findpkg(self, name, version, allow_local=False): """Find a package object matching the name and version specified in either sync databases or the local package collection. The local database is allowed to match if allow_local is True.""" - for db in self.db.itervalues(): + for db in util.valuesview(self.db): if db.is_local and not allow_local: continue pkg = db.getpkg(name) @@ -154,7 +154,7 @@ def generate(self, pacman): vprint("\t%s" % os.path.join(util.TMPDIR, pkg.filename())) pkg.finalize() pkg.makepkg(tmpdir) - for key, value in self.db.iteritems(): + for key, value in util.itemsview(self.db): for pkg in value.pkgs: pkg.finalize() if key == "local" and not self.createlocalpkgs: @@ -170,7 +170,7 @@ def generate(self, pacman):
# Creating sync database archives vprint(" Creating databases") - for key, value in self.db.iteritems(): + for key, value in util.itemsview(self.db): vprint("\t" + value.treename) value.generate()
diff --git a/test/pacman/util.py b/test/pacman/util.py index 77dd804..107a224 100644 --- a/test/pacman/util.py +++ b/test/pacman/util.py @@ -59,6 +59,15 @@ def vprint(msg): PERM_DIR = int("755",8) # 0o755 PERM_FILE = int("644",8) # 0o644
+def keysview(x): + return x.keys() if sys.hexversion >= 0x03000000 else x.iterkeys() + +def valuesview(x): + return x.values() if sys.hexversion >= 0x03000000 else x.itervalues() + +def itemsview(x): + return x.items() if sys.hexversion >= 0x03000000 else x.iteritems() +
# # Methods to generate files @@ -125,13 +134,13 @@ def writedata(filename, data): def mkcfgfile(filename, root, option, db): # Options data = ["[options]"] - for key, value in option.iteritems(): + for key, value in itemsview(option): data.extend(["%s = %s" % (key, j) for j in value])
# Repositories # sort by repo name so tests can predict repo order, rather than be # subjects to the whims of python dict() ordering - for key in sorted(db.iterkeys()): + for key in sorted(keysview(db)): if key != "local": value = db[key] data.append("[%s]\n" \ @@ -139,7 +148,7 @@ def mkcfgfile(filename, root, option, db): "Server = file://%s" \ % (value.treename, value.getverify(), \ os.path.join(root, SYNCREPO, value.treename))) - for optkey, optval in value.option.iteritems(): + for optkey, optval in itemsview(value.option): data.extend(["%s = %s" % (optkey, j) for j in optval])
mkfile(root, filename, "\n".join(data)) -- 1.8.4
On Thu, Oct 10, 2013 at 12:43 AM, Martin Panter <vadmium+patch@gmail.com> wrote:
On 10 October 2013 00:35, Jeremy Heiner <scalaprotractor@gmail.com> wrote: Perhaps it might be simpler to just use Python 3’s items() etc methods directly. That tends to also work with Python < 3 in most cases. I admit I’ve never used Pacman’s test suite so perhaps the extra expense would be significant under Python 2?
Hi, Martin. That is a great question. My "run all tests under 2.5, 2.6, and 2.7" script takes 85 seconds either way. So it seems that avoiding the copying gives no real boost. Jeremy
Reported by 2to3. StringIO moves to the io module in Python 3. Signed-off-by: Jeremy Heiner <ScalaProtractor at gmail.com> --- test/pacman/pmdb.py | 3 +-- test/pacman/pmpkg.py | 5 ++--- test/pacman/util.py | 8 ++++++++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/test/pacman/pmdb.py b/test/pacman/pmdb.py index f4bc71d..7ee3a1e 100644 --- a/test/pacman/pmdb.py +++ b/test/pacman/pmdb.py @@ -19,7 +19,6 @@ import os import shutil -from StringIO import StringIO import tarfile import pmpkg @@ -251,7 +250,7 @@ def generate(self): filename = os.path.join(pkg.fullname(), name) info = tarfile.TarInfo(filename) info.size = len(data) - tar.addfile(info, StringIO(data)) + tar.addfile(info, util.new_StringIO(data)) tar.close() # TODO: this is a bit unnecessary considering only one test uses it serverpath = os.path.join(self.root, util.SYNCREPO, self.treename) diff --git a/test/pacman/pmpkg.py b/test/pacman/pmpkg.py index 69734b0..8f4a9bc 100644 --- a/test/pacman/pmpkg.py +++ b/test/pacman/pmpkg.py @@ -21,7 +21,6 @@ import tempfile import stat import shutil -from StringIO import StringIO import tarfile import util @@ -152,7 +151,7 @@ def makepkg(self, path): for name, data in archive_files: info = tarfile.TarInfo(name) info.size = len(data) - tar.addfile(info, StringIO(data)) + tar.addfile(info, util.new_StringIO(data)) # Generate package file system for name in self.files: @@ -175,7 +174,7 @@ def makepkg(self, path): # TODO wow what a hack, adding a newline to match mkfile? filedata = name + "\n" info.size = len(filedata) - tar.addfile(info, StringIO(filedata)) + tar.addfile(info, util.new_StringIO(filedata)) tar.close() diff --git a/test/pacman/util.py b/test/pacman/util.py index 107a224..86d0eb2 100644 --- a/test/pacman/util.py +++ b/test/pacman/util.py @@ -68,6 +68,14 @@ def valuesview(x): def itemsview(x): return x.items() if sys.hexversion >= 0x03000000 else x.iteritems() +def new_StringIO(source): + if sys.hexversion >= 0x03000000: + import io + return io.StringIO(source) + else: + import StringIO + return StringIO.StringIO(source) + # # Methods to generate files -- 1.8.4
Reported by 2to3. Python 3 throws out the old range, renames the old xrange to be the new range, leaving no xrange. A shim could be used, but using the less efficient version does not have a noticeable impact on the run time. This observed (lack of an) effect is as described in the Python 2 docs for xrange. The largest range created is only 1000 elements big, and the memory cost of those ranges is negligible when compared to that of all the pmpkg instances created. Signed-off-by: Jeremy Heiner <ScalaProtractor at gmail.com> --- test/pacman/tests/smoke001.py | 4 ++-- test/pacman/tests/smoke003.py | 4 ++-- test/pacman/tests/xfercommand001.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/pacman/tests/smoke001.py b/test/pacman/tests/smoke001.py index 16576b7..ccc9db4 100644 --- a/test/pacman/tests/smoke001.py +++ b/test/pacman/tests/smoke001.py @@ -4,7 +4,7 @@ self.addpkg2db("local", p) -for i in xrange(1000): +for i in range(1000): p = pmpkg("pkg%03d" % i) p.depends = ["pkg%03d" % (i+1)] p.files = ["usr/share/pkg%03d" % i] @@ -14,7 +14,7 @@ self.args = "-U %s" % " ".join(pkglist) self.addrule("PACMAN_RETCODE=0") -#for i in xrange(1000): +#for i in range(1000): # self.addrule("PKG_EXIST=pkg%03d" %i) # picked 3 random packages to test for, since the loop is too much to handle self.addrule("PKG_EXIST=pkg050") diff --git a/test/pacman/tests/smoke003.py b/test/pacman/tests/smoke003.py index c2460fb..74083c7 100644 --- a/test/pacman/tests/smoke003.py +++ b/test/pacman/tests/smoke003.py @@ -1,11 +1,11 @@ self.description = "Remove a thousand packages in a single transaction" -for i in xrange(1000): +for i in range(1000): p = pmpkg("pkg%03dname" % i) p.files = ["usr/share/pkg%03d/file" % i] self.addpkg2db("local", p) -pkglist = ["pkg%03dname" % i for i in xrange(100, 1000)] +pkglist = ["pkg%03dname" % i for i in range(100, 1000)] self.args = "-R %s" % " ".join(pkglist) self.addrule("PACMAN_RETCODE=0") diff --git a/test/pacman/tests/xfercommand001.py b/test/pacman/tests/xfercommand001.py index a645cf7..0d244dc 100644 --- a/test/pacman/tests/xfercommand001.py +++ b/test/pacman/tests/xfercommand001.py @@ -7,7 +7,7 @@ numpkgs = 10 pkgnames = [] -for i in xrange(numpkgs): +for i in range(numpkgs): name = "pkg_%s" % i pkgnames.append(name) p = pmpkg(name) -- 1.8.4
Reported by 2to3. These are optional in Python 2, but required in 3. Signed-off-by: Jeremy Heiner <ScalaProtractor at gmail.com> --- test/pacman/tests/depconflict100.py | 2 +- test/pacman/tests/depconflict120.py | 2 +- test/pacman/tests/fileconflict001.py | 2 +- test/pacman/tests/fileconflict002.py | 2 +- test/pacman/tests/remove052.py | 2 +- test/pacman/tests/sync030.py | 2 +- test/pacman/tests/sync031.py | 2 +- test/pacman/tests/sync040.py | 2 +- test/pacman/tests/sync041.py | 2 +- test/pacman/tests/sync405.py | 2 +- test/pacman/tests/sync406.py | 2 +- test/pacman/tests/sync891.py | 2 +- test/pacman/tests/sync892.py | 2 +- test/pacman/tests/sync893.py | 2 +- test/pacman/tests/sync898.py | 2 +- test/pacman/tests/sync990.py | 2 +- test/pacman/tests/sync992.py | 2 +- test/pacman/tests/upgrade005.py | 2 +- test/pacman/tests/upgrade013.py | 2 +- test/pacman/tests/upgrade014.py | 2 +- test/pacman/tests/upgrade030.py | 2 +- test/pacman/tests/upgrade031.py | 2 +- test/pacman/tests/upgrade032.py | 2 +- test/pacman/tests/upgrade040.py | 2 +- test/pacman/tests/upgrade041.py | 2 +- test/pacman/tests/upgrade042.py | 2 +- test/pacman/tests/upgrade043.py | 2 +- test/pacman/tests/upgrade046.py | 2 +- test/pacman/tests/upgrade050.py | 2 +- test/pacman/tests/upgrade059.py | 2 +- test/pacman/tests/upgrade060.py | 2 +- test/pacman/tests/upgrade061.py | 2 +- test/pacman/tests/upgrade073.py | 2 +- test/pacman/tests/upgrade090.py | 2 +- 34 files changed, 34 insertions(+), 34 deletions(-) diff --git a/test/pacman/tests/depconflict100.py b/test/pacman/tests/depconflict100.py index 948017d..72cbec6 100644 --- a/test/pacman/tests/depconflict100.py +++ b/test/pacman/tests/depconflict100.py @@ -7,7 +7,7 @@ sp2 = pmpkg("pkg2", "1.0-2") self.addpkg2db("sync", sp2) -self.args = "-S %s" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp2)]) self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_EXIST=pkg1") diff --git a/test/pacman/tests/depconflict120.py b/test/pacman/tests/depconflict120.py index a9f3f6b..8e9ab06 100644 --- a/test/pacman/tests/depconflict120.py +++ b/test/pacman/tests/depconflict120.py @@ -11,7 +11,7 @@ lp.provides = ["imaginary"] self.addpkg2db("local", lp) -self.args = "-S %s" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp2)]) self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_EXIST=pkg1") diff --git a/test/pacman/tests/fileconflict001.py b/test/pacman/tests/fileconflict001.py index b1ad5e1..4777f93 100644 --- a/test/pacman/tests/fileconflict001.py +++ b/test/pacman/tests/fileconflict001.py @@ -18,7 +18,7 @@ "dir/symdir/file"] self.addpkg(p2) -self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)]) self.addrule("PACMAN_RETCODE=1") self.addrule("!PKG_EXIST=pkg1") diff --git a/test/pacman/tests/fileconflict002.py b/test/pacman/tests/fileconflict002.py index 1e6113c..17ca618 100644 --- a/test/pacman/tests/fileconflict002.py +++ b/test/pacman/tests/fileconflict002.py @@ -13,7 +13,7 @@ "dir/symdir/file"] self.addpkg(p2) -self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)]) self.addrule("PACMAN_RETCODE=1") self.addrule("!PKG_EXIST=pkg1") diff --git a/test/pacman/tests/remove052.py b/test/pacman/tests/remove052.py index df1e0db..4c444e4 100644 --- a/test/pacman/tests/remove052.py +++ b/test/pacman/tests/remove052.py @@ -13,7 +13,7 @@ lp3.reason = 1 self.addpkg2db("local", lp3) -self.args = "-Rs %s" % " ".join([p.name for p in lp1, lp3]) +self.args = "-Rs %s" % " ".join([p.name for p in (lp1, lp3)]) self.addrule("PACMAN_RETCODE=0") self.addrule("!PKG_EXIST=pkg1") diff --git a/test/pacman/tests/sync030.py b/test/pacman/tests/sync030.py index 1fd9750..b904ddb 100644 --- a/test/pacman/tests/sync030.py +++ b/test/pacman/tests/sync030.py @@ -10,7 +10,7 @@ for p in p1, p2: self.addpkg2db("sync", p) -self.args = "-S --asdeps %s" % " ".join([p.name for p in p1, p2]) +self.args = "-S --asdeps %s" % " ".join([p.name for p in (p1, p2)]) self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_VERSION=pkg1|1.0-2") diff --git a/test/pacman/tests/sync031.py b/test/pacman/tests/sync031.py index 4aa2ee3..7c5556e 100644 --- a/test/pacman/tests/sync031.py +++ b/test/pacman/tests/sync031.py @@ -10,7 +10,7 @@ for p in p1, p2: self.addpkg2db("sync", p) -self.args = "-S --asexplicit %s" % " ".join([p.name for p in p1, p2]) +self.args = "-S --asexplicit %s" % " ".join([p.name for p in (p1, p2)]) self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_VERSION=pkg1|1.0-2") diff --git a/test/pacman/tests/sync040.py b/test/pacman/tests/sync040.py index e5641fe..fa0b82d 100644 --- a/test/pacman/tests/sync040.py +++ b/test/pacman/tests/sync040.py @@ -8,7 +8,7 @@ for p in sp1, sp2: self.addpkg2db("sync", p); -self.args = "-S %s" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp2)]) self.addrule("PACMAN_RETCODE=1") for p in sp1, sp2: diff --git a/test/pacman/tests/sync041.py b/test/pacman/tests/sync041.py index 328728e..a90bb1a 100644 --- a/test/pacman/tests/sync041.py +++ b/test/pacman/tests/sync041.py @@ -9,7 +9,7 @@ for p in sp1, sp2: self.addpkg2db("sync", p); -self.args = "-S %s" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp2)]) self.addrule("PACMAN_RETCODE=1") self.addrule("!PKG_EXIST=pkg1") diff --git a/test/pacman/tests/sync405.py b/test/pacman/tests/sync405.py index 941a1af..602b1d3 100644 --- a/test/pacman/tests/sync405.py +++ b/test/pacman/tests/sync405.py @@ -15,7 +15,7 @@ lp.conflicts = ["phonon"] self.addpkg2db("local", lp) -self.args = "-S %s" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp2)]) self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_EXIST=kdelibs") diff --git a/test/pacman/tests/sync406.py b/test/pacman/tests/sync406.py index c15862f..516f89a 100644 --- a/test/pacman/tests/sync406.py +++ b/test/pacman/tests/sync406.py @@ -19,7 +19,7 @@ lp.conflicts = ["phonon"] self.addpkg2db("local", lp) -self.args = "-S %s" % " ".join([p.name for p in sp1, sp4]) +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp4)]) self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_EXIST=kdelibs") diff --git a/test/pacman/tests/sync891.py b/test/pacman/tests/sync891.py index 9b99e94..50f43fa 100644 --- a/test/pacman/tests/sync891.py +++ b/test/pacman/tests/sync891.py @@ -14,7 +14,7 @@ for p in lp1, lp2: self.addpkg2db("local", p) -self.args = "-S %s" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp2)]) self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_EXIST=pkg1") diff --git a/test/pacman/tests/sync892.py b/test/pacman/tests/sync892.py index dfd889e..d4171fe 100644 --- a/test/pacman/tests/sync892.py +++ b/test/pacman/tests/sync892.py @@ -16,7 +16,7 @@ for p in lp1, lp2: self.addpkg2db("local", p) -self.args = "-S %s --ask=4" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s --ask=4" % " ".join([p.name for p in (sp1, sp2)]) self.addrule("PACMAN_RETCODE=0") self.addrule("!PKG_EXIST=pkg1") diff --git a/test/pacman/tests/sync893.py b/test/pacman/tests/sync893.py index e96bb7b..ee0bdab 100644 --- a/test/pacman/tests/sync893.py +++ b/test/pacman/tests/sync893.py @@ -13,7 +13,7 @@ lp2 = pmpkg("pkg2") self.addpkg2db("local", lp2) -self.args = "-S %s --ask=4" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s --ask=4" % " ".join([p.name for p in (sp1, sp2)]) self.addrule("PACMAN_RETCODE=1") self.addrule("PKG_EXIST=pkg1") diff --git a/test/pacman/tests/sync898.py b/test/pacman/tests/sync898.py index 8fd59f1..dfedd6f 100644 --- a/test/pacman/tests/sync898.py +++ b/test/pacman/tests/sync898.py @@ -11,7 +11,7 @@ lp1 = pmpkg("pkg1") self.addpkg2db("local", lp1) -self.args = "-S %s" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp2)]) self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_VERSION=pkg1|1.0-2") diff --git a/test/pacman/tests/sync990.py b/test/pacman/tests/sync990.py index 6ac5a1f..38346b9 100644 --- a/test/pacman/tests/sync990.py +++ b/test/pacman/tests/sync990.py @@ -11,7 +11,7 @@ for p in sp1, sp2, sp3: self.addpkg2db("sync", p) -self.args = "-S %s" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp2)]) self.addrule("PACMAN_RETCODE=1") self.addrule("!PKG_EXIST=pkg1") diff --git a/test/pacman/tests/sync992.py b/test/pacman/tests/sync992.py index 63faaab..3b53893 100644 --- a/test/pacman/tests/sync992.py +++ b/test/pacman/tests/sync992.py @@ -15,7 +15,7 @@ lp1 = pmpkg("pkg2", "0.1-1") self.addpkg2db("local", lp1) -self.args = "-S %s --ask=4" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s --ask=4" % " ".join([p.name for p in (sp1, sp2)]) self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_EXIST=pkg1") diff --git a/test/pacman/tests/upgrade005.py b/test/pacman/tests/upgrade005.py index 0f8c13e..e0f77a6 100644 --- a/test/pacman/tests/upgrade005.py +++ b/test/pacman/tests/upgrade005.py @@ -14,7 +14,7 @@ for p in p1, p2, p3: self.addpkg(p) -self.args = "-U %s" % " ".join([p.filename() for p in p1, p2, p3]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2, p3)]) self.addrule("PACMAN_RETCODE=0") for p in p1, p2, p3: diff --git a/test/pacman/tests/upgrade013.py b/test/pacman/tests/upgrade013.py index 5a32759..4497f19 100644 --- a/test/pacman/tests/upgrade013.py +++ b/test/pacman/tests/upgrade013.py @@ -13,7 +13,7 @@ for p in p1, p2: self.addpkg(p) -self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)]) self.addrule("PACMAN_RETCODE=1") self.addrule("!PKG_EXIST=dummy") diff --git a/test/pacman/tests/upgrade014.py b/test/pacman/tests/upgrade014.py index 93c2fe2..2ef759d 100644 --- a/test/pacman/tests/upgrade014.py +++ b/test/pacman/tests/upgrade014.py @@ -13,7 +13,7 @@ for p in p1, p2: self.addpkg(p) -self.args = "-U --force %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U --force %s" % " ".join([p.filename() for p in (p1, p2)]) self.addrule("PACMAN_RETCODE=0") for p in p1, p2: diff --git a/test/pacman/tests/upgrade030.py b/test/pacman/tests/upgrade030.py index 8a6c473..ff09f72 100644 --- a/test/pacman/tests/upgrade030.py +++ b/test/pacman/tests/upgrade030.py @@ -14,7 +14,7 @@ for p in p1, p2: self.addpkg(p) -self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)]) self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_REASON=pkg1|0") diff --git a/test/pacman/tests/upgrade031.py b/test/pacman/tests/upgrade031.py index 856de98..a76a3d8 100644 --- a/test/pacman/tests/upgrade031.py +++ b/test/pacman/tests/upgrade031.py @@ -10,7 +10,7 @@ for p in p1, p2: self.addpkg(p) -self.args = "-U --asdeps %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U --asdeps %s" % " ".join([p.filename() for p in (p1, p2)]) self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_VERSION=pkg1|1.0-2") diff --git a/test/pacman/tests/upgrade032.py b/test/pacman/tests/upgrade032.py index 85e048e..6348a0f 100644 --- a/test/pacman/tests/upgrade032.py +++ b/test/pacman/tests/upgrade032.py @@ -10,7 +10,7 @@ for p in p1, p2: self.addpkg(p) -self.args = "-U --asexplicit %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U --asexplicit %s" % " ".join([p.filename() for p in (p1, p2)]) self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_VERSION=pkg1|1.0-2") diff --git a/test/pacman/tests/upgrade040.py b/test/pacman/tests/upgrade040.py index e17c717..a445743 100644 --- a/test/pacman/tests/upgrade040.py +++ b/test/pacman/tests/upgrade040.py @@ -20,7 +20,7 @@ for p in p1, p2: self.addpkg(p) -self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)]) self.addrule("PACMAN_RETCODE=0") for p in p1, p2: diff --git a/test/pacman/tests/upgrade041.py b/test/pacman/tests/upgrade041.py index 20da4f1..349d0f8 100644 --- a/test/pacman/tests/upgrade041.py +++ b/test/pacman/tests/upgrade041.py @@ -20,7 +20,7 @@ for p in p1, p2: self.addpkg(p) -self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)]) self.addrule("PACMAN_RETCODE=0") for p in p1, p2: diff --git a/test/pacman/tests/upgrade042.py b/test/pacman/tests/upgrade042.py index 4475499..df22393 100644 --- a/test/pacman/tests/upgrade042.py +++ b/test/pacman/tests/upgrade042.py @@ -17,7 +17,7 @@ p2.depends = [ "bash" ] self.addpkg(p2) -self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)]) self.filesystem = ["etc/profile"] diff --git a/test/pacman/tests/upgrade043.py b/test/pacman/tests/upgrade043.py index f531cb8..62a7bd0 100644 --- a/test/pacman/tests/upgrade043.py +++ b/test/pacman/tests/upgrade043.py @@ -17,7 +17,7 @@ p2.backup = ["etc/profile"] self.addpkg(p2) -self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)]) self.filesystem = ["etc/profile"] diff --git a/test/pacman/tests/upgrade046.py b/test/pacman/tests/upgrade046.py index d9ac66b..0b59ca6 100644 --- a/test/pacman/tests/upgrade046.py +++ b/test/pacman/tests/upgrade046.py @@ -20,7 +20,7 @@ for p in p1, p2: self.addpkg(p) -self.args = "-U --force %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U --force %s" % " ".join([p.filename() for p in (p1, p2)]) self.addrule("PACMAN_RETCODE=0") for p in p1, p2: diff --git a/test/pacman/tests/upgrade050.py b/test/pacman/tests/upgrade050.py index f05b0b6..bdda582 100644 --- a/test/pacman/tests/upgrade050.py +++ b/test/pacman/tests/upgrade050.py @@ -8,7 +8,7 @@ p2 = pmpkg("pkg2") self.addpkg(p2) -self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)]) self.addrule("PACMAN_RETCODE=1") self.addrule("!PKG_EXIST=pkg1") diff --git a/test/pacman/tests/upgrade059.py b/test/pacman/tests/upgrade059.py index 9cd9f1f..26a5810 100644 --- a/test/pacman/tests/upgrade059.py +++ b/test/pacman/tests/upgrade059.py @@ -18,7 +18,7 @@ p3 = pmpkg("pkg3", "1.0-2") self.addpkg(p3) -self.args = "-U %s" % " ".join([p.filename() for p in p2, p3]) +self.args = "-U %s" % " ".join([p.filename() for p in (p2, p3)]) self.addrule("PACMAN_RETCODE=1") self.addrule("PKG_EXIST=pkg1") diff --git a/test/pacman/tests/upgrade060.py b/test/pacman/tests/upgrade060.py index 7a28f3e..510562c 100644 --- a/test/pacman/tests/upgrade060.py +++ b/test/pacman/tests/upgrade060.py @@ -14,7 +14,7 @@ p2 = pmpkg("pkg2", "1.1-1") self.addpkg(p2) -self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)]) self.addrule("PACMAN_RETCODE=1") self.addrule("PKG_VERSION=pkg1|1.0-1") diff --git a/test/pacman/tests/upgrade061.py b/test/pacman/tests/upgrade061.py index 310e504..fd20c8b 100644 --- a/test/pacman/tests/upgrade061.py +++ b/test/pacman/tests/upgrade061.py @@ -15,7 +15,7 @@ p2 = pmpkg("pkg2", "1.0-2") self.addpkg(p2) -self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)]) self.addrule("PACMAN_RETCODE=1") self.addrule("PKG_VERSION=pkg1|1.0-1") diff --git a/test/pacman/tests/upgrade073.py b/test/pacman/tests/upgrade073.py index 752a233..7455ec1 100644 --- a/test/pacman/tests/upgrade073.py +++ b/test/pacman/tests/upgrade073.py @@ -15,7 +15,7 @@ for p in p1, p2, p3: self.addpkg(p) -self.args = "-U %s" % " ".join([p.filename() for p in p1, p2, p3]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2, p3)]) self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_VERSION=dummy|1.0-2") diff --git a/test/pacman/tests/upgrade090.py b/test/pacman/tests/upgrade090.py index cdd4cac..9eb8894 100644 --- a/test/pacman/tests/upgrade090.py +++ b/test/pacman/tests/upgrade090.py @@ -16,7 +16,7 @@ sp.files = ["bin/dep"] self.addpkg2db("sync", sp) -self.args = "-U %s --ask=16" % " ".join([p.filename() for p in p1, p2, p3]) +self.args = "-U %s --ask=16" % " ".join([p.filename() for p in (p1, p2, p3)]) self.addrule("PACMAN_RETCODE=0") for p in p1, p2, sp: -- 1.8.4
Discovered by running with 3.3.2. One test changed to avoid a lexical scoping change (fortunately the standard zip function is supported by all necessary versions and does what is needed). The other changes were to adjust to the more strict separation Python 3 puts between Unicode and byte data. Signed-off-by: Jeremy Heiner <ScalaProtractor at gmail.com> Conflicts: test/pacman/util.py --- test/pacman/tests/epoch005.py | 2 +- test/pacman/util.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/test/pacman/tests/epoch005.py b/test/pacman/tests/epoch005.py index 6215170..3e2073a 100644 --- a/test/pacman/tests/epoch005.py +++ b/test/pacman/tests/epoch005.py @@ -8,7 +8,7 @@ "1234327518932650063289125782697892:1.0-1", ) -pkgvers = [(n, versions[n]) for n in range(len(versions))] +pkgvers = zip(range(len(versions)), versions) for k, v in pkgvers: sp = pmpkg("pkg_%d" % k, v) self.addpkg2db("sync", sp) diff --git a/test/pacman/util.py b/test/pacman/util.py index 86d0eb2..9283852 100644 --- a/test/pacman/util.py +++ b/test/pacman/util.py @@ -71,11 +71,14 @@ def itemsview(x): def new_StringIO(source): if sys.hexversion >= 0x03000000: import io - return io.StringIO(source) + return io.BytesIO(source.encode("utf8")) else: import StringIO return StringIO.StringIO(source) +def chars2bytes(source): + return source.encode("utf8") if sys.hexversion >= 0x03000000 else source + # # Methods to generate files @@ -181,7 +184,7 @@ def getmd5sum(filename): def mkmd5sum(data): checksum = hashlib.md5() - checksum.update("%s\n" % data) + checksum.update(chars2bytes("%s\n" % data)) return checksum.hexdigest() -- 1.8.4
On 10 October 2013 00:35, Jeremy Heiner <scalaprotractor@gmail.com> wrote:
Discovered by running with 3.3.2. One test changed to avoid a lexical scoping change (fortunately the standard zip function is supported by all necessary versions and does what is needed). The other changes were to adjust to the more strict separation Python 3 puts between Unicode and byte data.
Signed-off-by: Jeremy Heiner <ScalaProtractor at gmail.com>
Conflicts: test/pacman/util.py --- test/pacman/tests/epoch005.py | 2 +- test/pacman/util.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/test/pacman/tests/epoch005.py b/test/pacman/tests/epoch005.py index 6215170..3e2073a 100644 --- a/test/pacman/tests/epoch005.py +++ b/test/pacman/tests/epoch005.py @@ -8,7 +8,7 @@ "1234327518932650063289125782697892:1.0-1", )
-pkgvers = [(n, versions[n]) for n in range(len(versions))] +pkgvers = zip(range(len(versions)), versions) for k, v in pkgvers: sp = pmpkg("pkg_%d" % k, v) self.addpkg2db("sync", sp) diff --git a/test/pacman/util.py b/test/pacman/util.py index 86d0eb2..9283852 100644 --- a/test/pacman/util.py +++ b/test/pacman/util.py @@ -71,11 +71,14 @@ def itemsview(x): def new_StringIO(source): if sys.hexversion >= 0x03000000: import io - return io.StringIO(source) + return io.BytesIO(source.encode("utf8"))
To me, having learnt Python 3 before Python 2, I found the name new_StringIO() misleading, since you are actually returning a BytesIO object. Anyway, the “io” module was added in Python 2.6, so maybe you can get rid of the whole workaround.
else: import StringIO return StringIO.StringIO(source)
+def chars2bytes(source): + return source.encode("utf8") if sys.hexversion >= 0x03000000 else source +
Python 2 can also do str.encode("utf8"), why only do it for Python 3?
# # Methods to generate files @@ -181,7 +184,7 @@ def getmd5sum(filename):
def mkmd5sum(data): checksum = hashlib.md5() - checksum.update("%s\n" % data) + checksum.update(chars2bytes("%s\n" % data)) return checksum.hexdigest()
-- 1.8.4
On Thu, Oct 10, 2013 at 12:50 AM, Martin Panter <vadmium+patch@gmail.com> wrote:
To me, having learnt Python 3 before Python 2, I found the name new_StringIO() misleading, since you are actually returning a BytesIO object. Anyway, the “io” module was added in Python 2.6, so maybe you can get rid of the whole workaround.
Yeah, in retrospect that wasn't the best choice of name. It was accurate for the commit that introduced the function, but then the later commit changed to BytesIO and it didn't occur to me to clean up the name.
Python 2 can also do str.encode("utf8"), why only do it for Python 3?
Only to avoid changing the behavior under Python 2. But I agree that it would be wiser to specify an encoding in all cases. Thanks, I'll incorporate that into a revised patch set (if there is a need for one). Jeremy
On 10/10/13 10:35, Jeremy Heiner wrote:
The short answer is: yes, it can.
The slightly longer answer is: with these patches the test framework is compatible with any Python from 2.5 up to 3.3. Relax: none of these patches actually change which version gets used during a build. This is just an exploration of what is needed to get over the bump from Python 2 to 3.
<snip> I believe that Andrew was working on this and he has a branch "python3" backs my guessing! So I will leave commenting on these to him! Allan
On Wed, Oct 9, 2013 at 8:53 PM, Allan McRae <allan@archlinux.org> wrote:
I believe that Andrew was working on this and he has a branch "python3" backs my guessing!
So I will leave commenting on these to him!
Allan
I'm not surprised to learn I'm again going where Andrew has gone before. Thanks for the pointer: I found and skimmed his branch's log, and will look deeper so I'm ready for when Andrew posts here. Jeremy
This series of patches incorporates all the suggestions posted to the dev list (thanks Allan and Martin!), as well as Andrew's python3 branch (thanks Andrew!). Setting 2.7 as the minimum runtime made things much easier. It would be easier still if Python 2 was abandoned... nudge, nudge, wink, wink, say no more. Jeremy Heiner (8): Bail early with a clear error message if Python runtime isn't 2.7+. Use "exec" instead of "execfile" (deprecated in Python 3). Use Python's "0o#" octal literal instead of deprecated "0#". Use dict iteration methods common to both Python 2 and 3. Avoid problematic use of Python's StringIO. Use Python's "range" instead of deprecated "xrange". Add parens around tuples in Python list comprehensions. Allow configure to select a Python 3 runtime. configure.ac | 2 +- test/pacman/pactest.py | 8 +++++++- test/pacman/pmdb.py | 12 ++++++------ test/pacman/pmenv.py | 3 +-- test/pacman/pmfile.py | 3 +-- test/pacman/pmpkg.py | 23 ++++++++++++++++------- test/pacman/pmrule.py | 3 +-- test/pacman/pmtest.py | 14 +++++++------- test/pacman/tests/depconflict100.py | 2 +- test/pacman/tests/depconflict120.py | 2 +- test/pacman/tests/fileconflict001.py | 2 +- test/pacman/tests/fileconflict002.py | 2 +- test/pacman/tests/remove052.py | 2 +- test/pacman/tests/smoke001.py | 4 ++-- test/pacman/tests/smoke003.py | 4 ++-- test/pacman/tests/sync030.py | 2 +- test/pacman/tests/sync031.py | 2 +- test/pacman/tests/sync040.py | 2 +- test/pacman/tests/sync041.py | 2 +- test/pacman/tests/sync405.py | 2 +- test/pacman/tests/sync406.py | 2 +- test/pacman/tests/sync891.py | 2 +- test/pacman/tests/sync892.py | 2 +- test/pacman/tests/sync893.py | 2 +- test/pacman/tests/sync898.py | 2 +- test/pacman/tests/sync990.py | 2 +- test/pacman/tests/sync992.py | 2 +- test/pacman/tests/upgrade005.py | 2 +- test/pacman/tests/upgrade013.py | 2 +- test/pacman/tests/upgrade014.py | 2 +- test/pacman/tests/upgrade030.py | 2 +- test/pacman/tests/upgrade031.py | 2 +- test/pacman/tests/upgrade032.py | 2 +- test/pacman/tests/upgrade040.py | 2 +- test/pacman/tests/upgrade041.py | 2 +- test/pacman/tests/upgrade042.py | 2 +- test/pacman/tests/upgrade043.py | 2 +- test/pacman/tests/upgrade046.py | 2 +- test/pacman/tests/upgrade050.py | 2 +- test/pacman/tests/upgrade059.py | 2 +- test/pacman/tests/upgrade060.py | 2 +- test/pacman/tests/upgrade061.py | 2 +- test/pacman/tests/upgrade073.py | 2 +- test/pacman/tests/upgrade090.py | 2 +- test/pacman/tests/xfercommand001.py | 2 +- test/pacman/util.py | 17 ++++++++--------- 46 files changed, 87 insertions(+), 76 deletions(-) -- 1.8.4
Prior to this a test that used a feature too new for the runtime would blow up when it was "exec"d (possibly in the middle of a run of a bunch of tests) with an error message that was not very helpful. Remove Python 2.5 and 2.6 runtimes from the list configure searches. 2.5 suffers the problem described above. The code currently will run on 2.6 but, as was noted on the dev list, that runtime is at the end of its life, so 2.7 is a better cutoff. Signed-off-by: Jeremy Heiner <ScalaProtractor at gmail.com> --- configure.ac | 2 +- test/pacman/pactest.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 42416a4..cfcc8d1 100644 --- a/configure.ac +++ b/configure.ac @@ -169,7 +169,7 @@ AC_SYS_LARGEFILE AC_PROG_AWK AC_PROG_CC_C99 AC_PROG_INSTALL -AC_CHECK_PROGS([PYTHON], [python2.7 python2.6 python2.5 python2 python], [false]) +AC_CHECK_PROGS([PYTHON], [python2.7 python2 python], [false]) AC_PATH_PROGS([BASH_SHELL], [bash bash4], [false]) # check for perl 5.10.1 (needed by makepkg-template) diff --git a/test/pacman/pactest.py b/test/pacman/pactest.py index d39fcaa..e21cde7 100755 --- a/test/pacman/pactest.py +++ b/test/pacman/pactest.py @@ -77,6 +77,12 @@ def create_parser(): if __name__ == "__main__": + + if sys.hexversion < 0x02070000: + # bailing now with clear message better than mid-run with unhelpful one + tap.bail("Python versions before 2.7 are not supported.") + sys.exit(1) + # instantiate env and parser objects root_path = tempfile.mkdtemp() env = pmenv.pmenv(root=root_path) -- 1.8.4
This was the only compatibility issue reported by "python2 -3". Signed-off-by: Jeremy Heiner <ScalaProtractor at gmail.com> --- test/pacman/pmtest.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/pacman/pmtest.py b/test/pacman/pmtest.py index b343d55..d12a5ed 100644 --- a/test/pacman/pmtest.py +++ b/test/pacman/pmtest.py @@ -100,7 +100,8 @@ def load(self): if os.path.isfile(self.name): # all tests expect this to be available from pmpkg import pmpkg - execfile(self.name) + with open(self.name) as input: + exec(input.read(),locals()) else: raise IOError("file %s does not exist!" % self.name) -- 1.8.4
Reported as a compatibility issue by 2to3. Signed-off-by: Jeremy Heiner <ScalaProtractor@gmail.com> --- test/pacman/pmpkg.py | 2 +- test/pacman/pmtest.py | 2 +- test/pacman/util.py | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/pacman/pmpkg.py b/test/pacman/pmpkg.py index 9b3147a..24ef1e2 100644 --- a/test/pacman/pmpkg.py +++ b/test/pacman/pmpkg.py @@ -161,7 +161,7 @@ def makepkg(self, path): if fileinfo["hasperms"]: info.mode = fileinfo["perms"] elif fileinfo["isdir"]: - info.mode = 0755 + info.mode = 0o755 if fileinfo["isdir"]: info.type = tarfile.DIRTYPE tar.addfile(info) diff --git a/test/pacman/pmtest.py b/test/pacman/pmtest.py index d12a5ed..731a9fc 100644 --- a/test/pacman/pmtest.py +++ b/test/pacman/pmtest.py @@ -131,7 +131,7 @@ def generate(self, pacman): for sys_dir in sys_dirs: if not os.path.isdir(sys_dir): vprint("\t%s" % sys_dir[len(self.root)+1:]) - os.makedirs(sys_dir, 0755) + os.makedirs(sys_dir, 0o755) # Only the dynamically linked binary is needed for fakechroot shutil.copy("/bin/sh", bindir) if shell != "bin/sh": diff --git a/test/pacman/util.py b/test/pacman/util.py index 14035d7..c1ab390 100644 --- a/test/pacman/util.py +++ b/test/pacman/util.py @@ -84,12 +84,12 @@ def mkfile(base, name, data=""): path = os.path.join(base, filename) if info["isdir"]: if not os.path.isdir(path): - os.makedirs(path, 0755) + os.makedirs(path, 0o755) return dir_path = os.path.dirname(path) if dir_path and not os.path.isdir(dir_path): - os.makedirs(dir_path, 0755) + os.makedirs(dir_path, 0o755) if info["islink"]: os.symlink(info["link"], path) @@ -182,6 +182,6 @@ def mkdir(path): return elif os.path.isfile(path): raise OSError("'%s' already exists and is not a directory" % path) - os.makedirs(path, 0755) + os.makedirs(path, 0o755) # vim: set ts=4 sw=4 et: -- 1.8.4
The .items, .keys, and .values methods in Python 2 make copies, so the test framework uses the .iter* flavors of those methods. But in Python 3 those .iter* (and even the 2.7 .view*) flavors are removed and the original methods return views. Measurements were taken under Python2 to see what impact the copying had, and there was none. Thus it is not worth the effort to avoid. Reported as a compatibility issue by 2to3. Signed-off-by: Jeremy Heiner <ScalaProtractor at gmail.com> --- test/pacman/pmdb.py | 4 ++-- test/pacman/pmpkg.py | 2 +- test/pacman/pmtest.py | 6 +++--- test/pacman/util.py | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/test/pacman/pmdb.py b/test/pacman/pmdb.py index b7b3522..53de91e 100644 --- a/test/pacman/pmdb.py +++ b/test/pacman/pmdb.py @@ -236,7 +236,7 @@ def generate(self): for pkg, entry in pkg_entries: path = os.path.join(self.dbdir, pkg.fullname()) util.mkdir(path) - for name, data in entry.iteritems(): + for name, data in entry.items(): util.mkfile(path, name, data) if self.dbfile: @@ -247,7 +247,7 @@ def generate(self): info = tarfile.TarInfo(pkg.fullname()) info.type = tarfile.DIRTYPE tar.addfile(info) - for name, data in entry.iteritems(): + for name, data in entry.items(): filename = os.path.join(pkg.fullname(), name) info = tarfile.TarInfo(filename) info.size = len(data) diff --git a/test/pacman/pmpkg.py b/test/pacman/pmpkg.py index 24ef1e2..6f7ae6e 100644 --- a/test/pacman/pmpkg.py +++ b/test/pacman/pmpkg.py @@ -223,7 +223,7 @@ def local_backup_entries(self): def installfile(self): data = [] - for key, value in self.install.iteritems(): + for key, value in self.install.items(): if value: data.append("%s() {\n%s\n}\n" % (key, value)) diff --git a/test/pacman/pmtest.py b/test/pacman/pmtest.py index 731a9fc..a1f3645d 100644 --- a/test/pacman/pmtest.py +++ b/test/pacman/pmtest.py @@ -58,7 +58,7 @@ def findpkg(self, name, version, allow_local=False): """Find a package object matching the name and version specified in either sync databases or the local package collection. The local database is allowed to match if allow_local is True.""" - for db in self.db.itervalues(): + for db in self.db.values(): if db.is_local and not allow_local: continue pkg = db.getpkg(name) @@ -151,7 +151,7 @@ def generate(self, pacman): vprint("\t%s" % os.path.join(util.TMPDIR, pkg.filename())) pkg.finalize() pkg.makepkg(tmpdir) - for key, value in self.db.iteritems(): + for key, value in self.db.items(): for pkg in value.pkgs: pkg.finalize() if key == "local" and not self.createlocalpkgs: @@ -167,7 +167,7 @@ def generate(self, pacman): # Creating sync database archives vprint(" Creating databases") - for key, value in self.db.iteritems(): + for key, value in self.db.items(): vprint("\t" + value.treename) value.generate() diff --git a/test/pacman/util.py b/test/pacman/util.py index c1ab390..ab5a6f4 100644 --- a/test/pacman/util.py +++ b/test/pacman/util.py @@ -112,13 +112,13 @@ def writedata(filename, data): def mkcfgfile(filename, root, option, db): # Options data = ["[options]"] - for key, value in option.iteritems(): + for key, value in option.items(): data.extend(["%s = %s" % (key, j) for j in value]) # Repositories # sort by repo name so tests can predict repo order, rather than be # subjects to the whims of python dict() ordering - for key in sorted(db.iterkeys()): + for key in sorted(db.keys()): if key != "local": value = db[key] data.append("[%s]\n" \ @@ -126,7 +126,7 @@ def mkcfgfile(filename, root, option, db): "Server = file://%s" \ % (value.treename, value.getverify(), \ os.path.join(root, SYNCREPO, value.treename))) - for optkey, optval in value.option.iteritems(): + for optkey, optval in value.option.items(): data.extend(["%s = %s" % (optkey, j) for j in optval]) mkfile(root, filename, "\n".join(data)) -- 1.8.4
2to3 reported that StringIO moved into the io module in Python 3 and suggested fixing the imports accordingly. But that is not a complete solution because of the more rigid separation between byte and char in Python 3. So in addition to fixing the imports, BytesIO are used, and the chars are encoded to bytes as needed. There was one hiccup in encoding in test sync600: the unicode strings which work in other tests for some reason cause problems here. This hiccup is only in 2.7, so a try block is used to fall back to use the unencoded string on that runtime only. One more bytes/chars mismatch (which is only revealed at run time) occurs in passing data to hashlib.md5, so this patch fixes that too. Signed-off-by: Jeremy Heiner <ScalaProtractor at gmail.com> --- test/pacman/pmdb.py | 5 +++-- test/pacman/pmpkg.py | 16 +++++++++++++--- test/pacman/util.py | 2 +- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/test/pacman/pmdb.py b/test/pacman/pmdb.py index 53de91e..b4de281 100644 --- a/test/pacman/pmdb.py +++ b/test/pacman/pmdb.py @@ -19,7 +19,7 @@ import os import shutil -from StringIO import StringIO +import io import tarfile import pmpkg @@ -250,8 +250,9 @@ def generate(self): for name, data in entry.items(): filename = os.path.join(pkg.fullname(), name) info = tarfile.TarInfo(filename) + data = data.encode('utf8') # 'utf8' req'd in 2.7 info.size = len(data) - tar.addfile(info, StringIO(data)) + tar.addfile(info, io.BytesIO(data)) tar.close() # TODO: this is a bit unnecessary considering only one test uses it serverpath = os.path.join(self.root, util.SYNCREPO, self.treename) diff --git a/test/pacman/pmpkg.py b/test/pacman/pmpkg.py index 6f7ae6e..5a5e78e 100644 --- a/test/pacman/pmpkg.py +++ b/test/pacman/pmpkg.py @@ -21,7 +21,7 @@ import tempfile import stat import shutil -from StringIO import StringIO +import io import tarfile import util @@ -151,8 +151,9 @@ def makepkg(self, path): tar = tarfile.open(self.path, "w:gz") for name, data in archive_files: info = tarfile.TarInfo(name) + data = data.encode('utf8') # 'utf8' req'd in 2.7 info.size = len(data) - tar.addfile(info, StringIO(data)) + tar.addfile(info, io.BytesIO(data)) # Generate package file system for name in self.files: @@ -172,8 +173,17 @@ def makepkg(self, path): else: # TODO wow what a hack, adding a newline to match mkfile? filedata = name + "\n" + try: + filedata = filedata.encode('utf8') # 'utf8' req'd in 2.7 + except: + import sys + if sys.hexversion >= 0x03000000: + raise + # else use unencoded data + # which works fine on 2.7 because it isn't careful + # to distinguish bytes from unicode chars. info.size = len(filedata) - tar.addfile(info, StringIO(filedata)) + tar.addfile(info, io.BytesIO(filedata)) tar.close() diff --git a/test/pacman/util.py b/test/pacman/util.py index ab5a6f4..4d5ba8a 100644 --- a/test/pacman/util.py +++ b/test/pacman/util.py @@ -151,7 +151,7 @@ def getmd5sum(filename): def mkmd5sum(data): checksum = hashlib.md5() - checksum.update("%s\n" % data) + checksum.update((data+"\n").encode('utf8')) # 'utf8' req'd in 2.7 return checksum.hexdigest() -- 1.8.4
On 13/10/13 02:44, Jeremy Heiner wrote:
2to3 reported that StringIO moved into the io module in Python 3 and suggested fixing the imports accordingly. But that is not a complete solution because of the more rigid separation between byte and char in Python 3. So in addition to fixing the imports, BytesIO are used, and the chars are encoded to bytes as needed.
There was one hiccup in encoding in test sync600: the unicode strings which work in other tests for some reason cause problems here. This hiccup is only in 2.7, so a try block is used to fall back to use the unencoded string on that runtime only.
Using "for some reason" in the description is a clear flag for me not to apply the patch. This tends to result in an underlying issue being missed due to lack of understanding.
One more bytes/chars mismatch (which is only revealed at run time) occurs in passing data to hashlib.md5, so this patch fixes that too.
Signed-off-by: Jeremy Heiner <ScalaProtractor at gmail.com> --- test/pacman/pmdb.py | 5 +++-- test/pacman/pmpkg.py | 16 +++++++++++++--- test/pacman/util.py | 2 +- 3 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/test/pacman/pmdb.py b/test/pacman/pmdb.py index 53de91e..b4de281 100644 --- a/test/pacman/pmdb.py +++ b/test/pacman/pmdb.py @@ -19,7 +19,7 @@
import os import shutil -from StringIO import StringIO +import io import tarfile
import pmpkg @@ -250,8 +250,9 @@ def generate(self): for name, data in entry.items(): filename = os.path.join(pkg.fullname(), name) info = tarfile.TarInfo(filename) + data = data.encode('utf8') # 'utf8' req'd in 2.7 info.size = len(data) - tar.addfile(info, StringIO(data)) + tar.addfile(info, io.BytesIO(data)) tar.close() # TODO: this is a bit unnecessary considering only one test uses it serverpath = os.path.join(self.root, util.SYNCREPO, self.treename) diff --git a/test/pacman/pmpkg.py b/test/pacman/pmpkg.py index 6f7ae6e..5a5e78e 100644 --- a/test/pacman/pmpkg.py +++ b/test/pacman/pmpkg.py @@ -21,7 +21,7 @@ import tempfile import stat import shutil -from StringIO import StringIO +import io import tarfile
import util @@ -151,8 +151,9 @@ def makepkg(self, path): tar = tarfile.open(self.path, "w:gz") for name, data in archive_files: info = tarfile.TarInfo(name) + data = data.encode('utf8') # 'utf8' req'd in 2.7 info.size = len(data) - tar.addfile(info, StringIO(data)) + tar.addfile(info, io.BytesIO(data))
# Generate package file system for name in self.files: @@ -172,8 +173,17 @@ def makepkg(self, path): else: # TODO wow what a hack, adding a newline to match mkfile? filedata = name + "\n" + try: + filedata = filedata.encode('utf8') # 'utf8' req'd in 2.7 + except: + import sys + if sys.hexversion >= 0x03000000: + raise + # else use unencoded data + # which works fine on 2.7 because it isn't careful + # to distinguish bytes from unicode chars. info.size = len(filedata) - tar.addfile(info, StringIO(filedata)) + tar.addfile(info, io.BytesIO(filedata))
tar.close()
diff --git a/test/pacman/util.py b/test/pacman/util.py index ab5a6f4..4d5ba8a 100644 --- a/test/pacman/util.py +++ b/test/pacman/util.py @@ -151,7 +151,7 @@ def getmd5sum(filename):
def mkmd5sum(data): checksum = hashlib.md5() - checksum.update("%s\n" % data) + checksum.update((data+"\n").encode('utf8')) # 'utf8' req'd in 2.7 return checksum.hexdigest()
On Sat, Oct 12, 2013 at 9:16 PM, Allan McRae <allan@archlinux.org> wrote:
On 13/10/13 02:44, Jeremy Heiner wrote:
There was one hiccup in encoding in test sync600: the unicode strings which work in other tests for some reason cause problems here. This hiccup is only in 2.7, so a try block is used to fall back to use the unencoded string on that runtime only.
Using "for some reason" in the description is a clear flag for me not to apply the patch. This tends to result in an underlying issue being missed due to lack of understanding.
Hi, Allan! Yeah, I was not happy at all about having to put that exception handler in. I tried a crazy number of other workarounds, and in doing so I got quite a good understanding. But describing it adequately will take a lot of typing. Like several pages. It is absolutely right of you to ask, and I'm happy and able to provide that, but I doubt I can get to it before tomorrow night. The short answer is that Unicode support in Python 2 is fundamentally broken. Fixing that is why Python 3 got a major version bump and they had to give up on backwards compatibility. Sorry I don't have more time right now to go into all the gory details... and I hope the other readers won't be too bored by my post when I do. Thanks, Jeremy
On 13 October 2013 13:14, Jeremy Heiner <scalaprotractor@gmail.com> wrote:
On Sat, Oct 12, 2013 at 9:16 PM, Allan McRae <allan@archlinux.org> wrote:
On 13/10/13 02:44, Jeremy Heiner wrote:
There was one hiccup in encoding in test sync600: the unicode strings which work in other tests for some reason cause problems here. This hiccup is only in 2.7, so a try block is used to fall back to use the unencoded string on that runtime only.
Using "for some reason" in the description is a clear flag for me not to apply the patch. This tends to result in an underlying issue being missed due to lack of understanding.
Hi, Allan! Yeah, I was not happy at all about having to put that exception handler in. I tried a crazy number of other workarounds, and in doing so I got quite a good understanding. But describing it adequately will take a lot of typing. Like several pages. It is absolutely right of you to ask, and I'm happy and able to provide that, but I doubt I can get to it before tomorrow night. The short answer is that Unicode support in Python 2 is fundamentally broken. Fixing that is why Python 3 got a major version bump and they had to give up on backwards compatibility. Sorry I don't have more time right now to go into all the gory details... and I hope the other readers won't be too bored by my post when I do.
Looking at the “sync600” test you mentioned, it has a bunch of file names with non-ASCII characters. Perhaps you might have better luck putting a “u” prefix in front of the strings, or using “from __future__ import unicode_literals”. Be aware that the u"" syntax was only added back in Python 3.3.
On 13/10/13 13:14, Martin Panter wrote:
On 13 October 2013 13:14, Jeremy Heiner <scalaprotractor@gmail.com> wrote:
On Sat, Oct 12, 2013 at 9:16 PM, Allan McRae <allan@archlinux.org> wrote:
On 13/10/13 02:44, Jeremy Heiner wrote:
There was one hiccup in encoding in test sync600: the unicode strings which work in other tests for some reason cause problems here. This hiccup is only in 2.7, so a try block is used to fall back to use the unencoded string on that runtime only.
Using "for some reason" in the description is a clear flag for me not to apply the patch. This tends to result in an underlying issue being missed due to lack of understanding.
Hi, Allan! Yeah, I was not happy at all about having to put that exception handler in. I tried a crazy number of other workarounds, and in doing so I got quite a good understanding. But describing it adequately will take a lot of typing. Like several pages. It is absolutely right of you to ask, and I'm happy and able to provide that, but I doubt I can get to it before tomorrow night. The short answer is that Unicode support in Python 2 is fundamentally broken. Fixing that is why Python 3 got a major version bump and they had to give up on backwards compatibility. Sorry I don't have more time right now to go into all the gory details... and I hope the other readers won't be too bored by my post when I do.
Looking at the “sync600” test you mentioned, it has a bunch of file names with non-ASCII characters. Perhaps you might have better luck putting a “u” prefix in front of the strings, or using “from __future__ import unicode_literals”. Be aware that the u"" syntax was only added back in Python 3.3.
I get the feeling that this should be dealt with in sync600 rather than what this patch does. Comments? Allan
On 10/13/13 at 05:11pm, Allan McRae wrote:
On 13/10/13 13:14, Martin Panter wrote:
On 13 October 2013 13:14, Jeremy Heiner <scalaprotractor@gmail.com> wrote:
On Sat, Oct 12, 2013 at 9:16 PM, Allan McRae <allan@archlinux.org> wrote:
On 13/10/13 02:44, Jeremy Heiner wrote:
There was one hiccup in encoding in test sync600: the unicode strings which work in other tests for some reason cause problems here. This hiccup is only in 2.7, so a try block is used to fall back to use the unencoded string on that runtime only.
Using "for some reason" in the description is a clear flag for me not to apply the patch. This tends to result in an underlying issue being missed due to lack of understanding.
Hi, Allan! Yeah, I was not happy at all about having to put that exception handler in. I tried a crazy number of other workarounds, and in doing so I got quite a good understanding. But describing it adequately will take a lot of typing. Like several pages. It is absolutely right of you to ask, and I'm happy and able to provide that, but I doubt I can get to it before tomorrow night. The short answer is that Unicode support in Python 2 is fundamentally broken. Fixing that is why Python 3 got a major version bump and they had to give up on backwards compatibility. Sorry I don't have more time right now to go into all the gory details... and I hope the other readers won't be too bored by my post when I do.
Looking at the “sync600” test you mentioned, it has a bunch of file names with non-ASCII characters. Perhaps you might have better luck putting a “u” prefix in front of the strings, or using “from __future__ import unicode_literals”. Be aware that the u"" syntax was only added back in Python 3.3.
I get the feeling that this should be dealt with in sync600 rather than what this patch does.
Comments?
Allan
This is the reason I never submitted my own patchset. I don't think there is a good way to do this. There doesn't appear to be a way to use either a unicode or bytes literal in the test that is compatible with both python2 and python3 unless we also drop support for versions of python3 < 3.3, which are still supported. The only solution I found was to test for the python version in the test suite. But, given that our build process is tied to python2 anyway until asciidoc supports python3 it didn't seem worth it to make the transition until we could drop python2 entirely. apg
On 13/10/13 22:15, Andrew Gregory wrote:
On 10/13/13 at 05:11pm, Allan McRae wrote:
On 13/10/13 13:14, Martin Panter wrote:
On 13 October 2013 13:14, Jeremy Heiner <scalaprotractor@gmail.com> wrote:
On Sat, Oct 12, 2013 at 9:16 PM, Allan McRae <allan@archlinux.org> wrote:
On 13/10/13 02:44, Jeremy Heiner wrote:
There was one hiccup in encoding in test sync600: the unicode strings which work in other tests for some reason cause problems here. This hiccup is only in 2.7, so a try block is used to fall back to use the unencoded string on that runtime only.
Using "for some reason" in the description is a clear flag for me not to apply the patch. This tends to result in an underlying issue being missed due to lack of understanding.
Hi, Allan! Yeah, I was not happy at all about having to put that exception handler in. I tried a crazy number of other workarounds, and in doing so I got quite a good understanding. But describing it adequately will take a lot of typing. Like several pages. It is absolutely right of you to ask, and I'm happy and able to provide that, but I doubt I can get to it before tomorrow night. The short answer is that Unicode support in Python 2 is fundamentally broken. Fixing that is why Python 3 got a major version bump and they had to give up on backwards compatibility. Sorry I don't have more time right now to go into all the gory details... and I hope the other readers won't be too bored by my post when I do.
Looking at the “sync600” test you mentioned, it has a bunch of file names with non-ASCII characters. Perhaps you might have better luck putting a “u” prefix in front of the strings, or using “from __future__ import unicode_literals”. Be aware that the u"" syntax was only added back in Python 3.3.
I get the feeling that this should be dealt with in sync600 rather than what this patch does.
Comments?
Allan
This is the reason I never submitted my own patchset. I don't think there is a good way to do this. There doesn't appear to be a way to use either a unicode or bytes literal in the test that is compatible with both python2 and python3 unless we also drop support for versions of python3 < 3.3, which are still supported. The only solution I found was to test for the python version in the test suite. But, given that our build process is tied to python2 anyway until asciidoc supports python3 it didn't seem worth it to make the transition until we could drop python2 entirely.
Just a note. Our build process for git is tied to asciidoc, but not for release tarballs. I am going to merge all these patches apart from this one and the final patch. If a consensus can be found on how to deal with this issue, I will pull it in - I am not familiar enough with python issues to make the decision myself. Allan
On Sun, Oct 13, 2013 at 7:55 PM, Allan McRae <allan@archlinux.org> wrote:
I am going to merge all these patches apart from this one and the final patch. If a consensus can be found on how to deal with this issue, I will pull it in - I am not familiar enough with python issues to make the decision myself.
Thanks, Allan. I'm gratified that I can help make (some small) improvements. Sorry I got delayed, but I said I would explain how the Python 2 string gotchas impact the pacman testing framework. I think I found a way to shorten this from what I had anticipated, so hopefully it won't be completely boring... There are two pmtests with non-7bit-ascii chars: remove071 and sync600. remove071 creates one pmpkg (p2) and adds it to the "local" pmdb. sync600 copy-n-pastes that same p2 pmpkg setup, but also creates and adds sp2 to the "sync" pmdb. The framework does very different things for the pmdbs: "local" stuff get written to the filesystem (simulating in Python code what pacman would do to install), while "sync" stuff get written to a tarfile (for later processing by the pacman binary being tested). That is the key difference and stumbling block (and also why this can't be dealt with in sync600). Python's filesystem write API gracefully handles strings of all sorts, automatically converting char-to-byte as needed, so the "local" pmpkg p2 (in both pmtests) works great, but... The tarfile.addfile API requires a fileobject, so the caller of that API is responsible for handling the low-level char-to-byte conversion. Python 2.7's StringIO meets that need. But in 3.x there aren't just fileobjects, there's RawIOBase (the parent class for BytesIO) which reads and writes bytes, and TextIOBase (the parent class for StringIO) which reads and writes chars. tarfile.addfile writes bytes, so in 3.x it fails when it tries to read bytes from a TextIOBase. So how do we feed tarfile.addfile what it wants without special-casing for the Python runtime version? Rather than typing up a long explanation of why there is no way to meet that goal I've attached a Python script that tries all the options I could think of and produces a nice printout of the reason for failure in each case. The last line of the printout lists the successful options - those that work for that particular Python runtime. Running it on 2.7 and 3.3 shows no single option is successful for both. The attached script covers what Martin suggested (assuming I haven't misunderstood what he meant). And if anyone can think of an option that I didn't please post a reply - I love learning new things. Jeremy
On 15 October 2013 02:01, Jeremy Heiner <scalaprotractor@gmail.com> wrote:
On Sun, Oct 13, 2013 at 7:55 PM, Allan McRae <allan@archlinux.org> wrote:
I am going to merge all these patches apart from this one and the final patch. If a consensus can be found on how to deal with this issue, I will pull it in - I am not familiar enough with python issues to make the decision myself.
Thanks, Allan. I'm gratified that I can help make (some small) improvements.
Sorry I got delayed, but I said I would explain how the Python 2 string gotchas impact the pacman testing framework. I think I found a way to shorten this from what I had anticipated, so hopefully it won't be completely boring...
There are two pmtests with non-7bit-ascii chars: remove071 and sync600. remove071 creates one pmpkg (p2) and adds it to the "local" pmdb. sync600 copy-n-pastes that same p2 pmpkg setup, but also creates and adds sp2 to the "sync" pmdb.
The framework does very different things for the pmdbs: "local" stuff get written to the filesystem (simulating in Python code what pacman would do to install), while "sync" stuff get written to a tarfile (for later processing by the pacman binary being tested). That is the key difference and stumbling block (and also why this can't be dealt with in sync600).
Python's filesystem write API gracefully handles strings of all sorts, automatically converting char-to-byte as needed, so the "local" pmpkg p2 (in both pmtests) works great, but...
The tarfile.addfile API requires a fileobject, so the caller of that API is responsible for handling the low-level char-to-byte conversion. Python 2.7's StringIO meets that need. But in 3.x there aren't just fileobjects, there's RawIOBase (the parent class for BytesIO) which reads and writes bytes, and TextIOBase (the parent class for StringIO) which reads and writes chars. tarfile.addfile writes bytes, so in 3.x it fails when it tries to read bytes from a TextIOBase.
So how do we feed tarfile.addfile what it wants without special-casing for the Python runtime version? Rather than typing up a long explanation of why there is no way to meet that goal I've attached a Python script that tries all the options I could think of and produces a nice printout of the reason for failure in each case. The last line of the printout lists the successful options - those that work for that particular Python runtime. Running it on 2.7 and 3.3 shows no single option is successful for both.
The attached script covers what Martin suggested (assuming I haven't misunderstood what he meant). And if anyone can think of an option that I didn't please post a reply - I love learning new things.
Here are two suggestions: 1. If you put the “u” prefix on the Chinese string, it becomes a Unicode string in Python 2, and encode("utf-8") then works for 2.7 and 3.3+. You can also have the “u” prefix on the other two ASCII strings but that is optional: # . . . for entry in ["ascii", u"错误", u"7bit"]: # . . . 2. Put the following __future__ line right at the top of the file, and remove all the “u” prefixes on the strings. This effectively makes them all Unicode strings in Python 2 and 3. The encode("utf-8") call should work for 2.7, and since the “u” prefix can be removed, it should also work for Python 3.2 and earlier. # coding=utf8 from __future__ import unicode_literals import io import os # . . . for entry in ["ascii", "错误", "7bit"]: # . . . I think the second option is the best option since it uses proper Python 3 syntax and should allow compatibility with Python 3.2. I am going away from the Internet for a week, but if you are still having trouble coming up with a good solution after that I might be motivated to actually run the test suite myself and come up with a patch :P
On Mon, Oct 14, 2013 at 4:48 PM, Martin Panter <vadmium+patch@gmail.com> wrote:
1. If you put the “u” prefix on the Chinese string,
Yes, but then it would be treated exactly the same as the 3rd entry. The point of the one that says "error" (so I'm told, I can't read CJK) is to show that in 2.7 even string literals with non-ascii chars behave differently from instances of the unicode class.
2. Put the following __future__ line right at the top of the file,
That ... is ... awesome! I swear I tried that out on an early version of my little script and for some reason didn't see the effect and abandoned it. I even read through the PEP and a few of the top google hits, but I misunderstood it to mean that the effect was limited to the "u" and "b" prefixed strings. Hindsight being 20/20 I can't remember how I could possibly have come to that conclusion. Thank you for sending me back to try it again. I'll try this fix out in the full pactest and get a new patch ready. Probably not tonight, but soon. I'll just resubmit this one patch - the final (8/8) patch could probably benefit from a bit more time for reflection. Thanks, Martin, and enjoy your internet vacation! Jeremy
On Mon, Oct 14, 2013 at 6:38 PM, Jeremy Heiner <scalaprotractor@gmail.com> wrote:
Probably not tonight, but soon.
Status update: I've only been able to find an hour since then to work on this; unfortunately did not just work and I haven't had time yet to figure out what I'm doing wrong.
On 20 October 2013 12:26, Jeremy Heiner <scalaprotractor@gmail.com> wrote:
On Mon, Oct 14, 2013 at 6:38 PM, Jeremy Heiner <scalaprotractor@gmail.com> wrote:
Probably not tonight, but soon.
Status update: I've only been able to find an hour since then to work on this; unfortunately did not just work and I haven't had time yet to figure out what I'm doing wrong.
Hi Jeremy, I just discovered another (but related) issue under Python 3 that you may not be aware of. There are places in the code, at least writedata() in util.py, that write to a text file, but do not specify an encoding. If you run the tests with LC_ALL=C, some of them fail in Python 3 (but succeed in Python 2) because they are writing non-ASCII characters. The simplest solution might be to use codecs.open(encoding='utf8'), which is available in Python 2 and 3, and should continue to write the existing ASCII-only byte strings in Python 2.
On Sun, Oct 20, 2013 at 8:56 PM, Martin Panter <vadmium+patch@gmail.com> wrote:
Hi Jeremy,
I just discovered another (but related) issue under Python 3 that you may not be aware of. There are places in the code, at least writedata() in util.py, that write to a text file, but do not specify an encoding. If you run the tests with LC_ALL=C, some of them fail in Python 3 (but succeed in Python 2) because they are writing non-ASCII characters.
The simplest solution might be to use codecs.open(encoding='utf8'), which is available in Python 2 and 3, and should continue to write the existing ASCII-only byte strings in Python 2.
Hi Martin, Sorry for the delayed response - I got swamped by another project. I thought about making the change you suggest, but decided against it because this feels like something that should be handled outside of the .py code. 99% of the time 'make' will be running the tests, so it seems simpler to tweak the invocation of Python rather than clutter up the framework. Perhaps we could add a check at startup (right next to the recently added "Python version is at least version 2.7") that will refuse to run any tests unless the locale is set appropriately? That seems less intrusive. In a similar vein, note that I left comments saying "required by 2.7" in all the places where specifying the encoding could not be avoided, but can (and should) be cleaned out once the jump is made to Python3. Anyway, I've got a little free time again, but I want to put aside the Python3 stuff for now and get back to what I was working on before I got distracted: unit tests for -Qk and -Qkk. After that I'll see if I can figure out why the "from __future__ import" didn't work. Jeremy
Reported by 2to3. Python 3 throws out the old range, renames the old xrange to be the new range, leaving no xrange. A shim could be used, but using the less efficient version does not have a noticeable impact on the run time. This observed (lack of an) effect is as described in the Python 2 docs for xrange. The largest range created is only 1000 elements big, and the memory cost of those ranges is negligible when compared to that of all the pmpkg instances created. Signed-off-by: Jeremy Heiner <ScalaProtractor at gmail.com> --- test/pacman/tests/smoke001.py | 4 ++-- test/pacman/tests/smoke003.py | 4 ++-- test/pacman/tests/xfercommand001.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/pacman/tests/smoke001.py b/test/pacman/tests/smoke001.py index 16576b7..ccc9db4 100644 --- a/test/pacman/tests/smoke001.py +++ b/test/pacman/tests/smoke001.py @@ -4,7 +4,7 @@ self.addpkg2db("local", p) -for i in xrange(1000): +for i in range(1000): p = pmpkg("pkg%03d" % i) p.depends = ["pkg%03d" % (i+1)] p.files = ["usr/share/pkg%03d" % i] @@ -14,7 +14,7 @@ self.args = "-U %s" % " ".join(pkglist) self.addrule("PACMAN_RETCODE=0") -#for i in xrange(1000): +#for i in range(1000): # self.addrule("PKG_EXIST=pkg%03d" %i) # picked 3 random packages to test for, since the loop is too much to handle self.addrule("PKG_EXIST=pkg050") diff --git a/test/pacman/tests/smoke003.py b/test/pacman/tests/smoke003.py index c2460fb..74083c7 100644 --- a/test/pacman/tests/smoke003.py +++ b/test/pacman/tests/smoke003.py @@ -1,11 +1,11 @@ self.description = "Remove a thousand packages in a single transaction" -for i in xrange(1000): +for i in range(1000): p = pmpkg("pkg%03dname" % i) p.files = ["usr/share/pkg%03d/file" % i] self.addpkg2db("local", p) -pkglist = ["pkg%03dname" % i for i in xrange(100, 1000)] +pkglist = ["pkg%03dname" % i for i in range(100, 1000)] self.args = "-R %s" % " ".join(pkglist) self.addrule("PACMAN_RETCODE=0") diff --git a/test/pacman/tests/xfercommand001.py b/test/pacman/tests/xfercommand001.py index a645cf7..0d244dc 100644 --- a/test/pacman/tests/xfercommand001.py +++ b/test/pacman/tests/xfercommand001.py @@ -7,7 +7,7 @@ numpkgs = 10 pkgnames = [] -for i in xrange(numpkgs): +for i in range(numpkgs): name = "pkg_%s" % i pkgnames.append(name) p = pmpkg(name) -- 1.8.4
Reported by 2to3: optional in Python 2, but required in 3. Signed-off-by: Jeremy Heiner <ScalaProtractor@gmail.com> --- test/pacman/tests/depconflict100.py | 2 +- test/pacman/tests/depconflict120.py | 2 +- test/pacman/tests/fileconflict001.py | 2 +- test/pacman/tests/fileconflict002.py | 2 +- test/pacman/tests/remove052.py | 2 +- test/pacman/tests/sync030.py | 2 +- test/pacman/tests/sync031.py | 2 +- test/pacman/tests/sync040.py | 2 +- test/pacman/tests/sync041.py | 2 +- test/pacman/tests/sync405.py | 2 +- test/pacman/tests/sync406.py | 2 +- test/pacman/tests/sync891.py | 2 +- test/pacman/tests/sync892.py | 2 +- test/pacman/tests/sync893.py | 2 +- test/pacman/tests/sync898.py | 2 +- test/pacman/tests/sync990.py | 2 +- test/pacman/tests/sync992.py | 2 +- test/pacman/tests/upgrade005.py | 2 +- test/pacman/tests/upgrade013.py | 2 +- test/pacman/tests/upgrade014.py | 2 +- test/pacman/tests/upgrade030.py | 2 +- test/pacman/tests/upgrade031.py | 2 +- test/pacman/tests/upgrade032.py | 2 +- test/pacman/tests/upgrade040.py | 2 +- test/pacman/tests/upgrade041.py | 2 +- test/pacman/tests/upgrade042.py | 2 +- test/pacman/tests/upgrade043.py | 2 +- test/pacman/tests/upgrade046.py | 2 +- test/pacman/tests/upgrade050.py | 2 +- test/pacman/tests/upgrade059.py | 2 +- test/pacman/tests/upgrade060.py | 2 +- test/pacman/tests/upgrade061.py | 2 +- test/pacman/tests/upgrade073.py | 2 +- test/pacman/tests/upgrade090.py | 2 +- 34 files changed, 34 insertions(+), 34 deletions(-) diff --git a/test/pacman/tests/depconflict100.py b/test/pacman/tests/depconflict100.py index 948017d..72cbec6 100644 --- a/test/pacman/tests/depconflict100.py +++ b/test/pacman/tests/depconflict100.py @@ -7,7 +7,7 @@ sp2 = pmpkg("pkg2", "1.0-2") self.addpkg2db("sync", sp2) -self.args = "-S %s" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp2)]) self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_EXIST=pkg1") diff --git a/test/pacman/tests/depconflict120.py b/test/pacman/tests/depconflict120.py index a9f3f6b..8e9ab06 100644 --- a/test/pacman/tests/depconflict120.py +++ b/test/pacman/tests/depconflict120.py @@ -11,7 +11,7 @@ lp.provides = ["imaginary"] self.addpkg2db("local", lp) -self.args = "-S %s" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp2)]) self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_EXIST=pkg1") diff --git a/test/pacman/tests/fileconflict001.py b/test/pacman/tests/fileconflict001.py index b1ad5e1..4777f93 100644 --- a/test/pacman/tests/fileconflict001.py +++ b/test/pacman/tests/fileconflict001.py @@ -18,7 +18,7 @@ "dir/symdir/file"] self.addpkg(p2) -self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)]) self.addrule("PACMAN_RETCODE=1") self.addrule("!PKG_EXIST=pkg1") diff --git a/test/pacman/tests/fileconflict002.py b/test/pacman/tests/fileconflict002.py index 1e6113c..17ca618 100644 --- a/test/pacman/tests/fileconflict002.py +++ b/test/pacman/tests/fileconflict002.py @@ -13,7 +13,7 @@ "dir/symdir/file"] self.addpkg(p2) -self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)]) self.addrule("PACMAN_RETCODE=1") self.addrule("!PKG_EXIST=pkg1") diff --git a/test/pacman/tests/remove052.py b/test/pacman/tests/remove052.py index df1e0db..4c444e4 100644 --- a/test/pacman/tests/remove052.py +++ b/test/pacman/tests/remove052.py @@ -13,7 +13,7 @@ lp3.reason = 1 self.addpkg2db("local", lp3) -self.args = "-Rs %s" % " ".join([p.name for p in lp1, lp3]) +self.args = "-Rs %s" % " ".join([p.name for p in (lp1, lp3)]) self.addrule("PACMAN_RETCODE=0") self.addrule("!PKG_EXIST=pkg1") diff --git a/test/pacman/tests/sync030.py b/test/pacman/tests/sync030.py index 1fd9750..b904ddb 100644 --- a/test/pacman/tests/sync030.py +++ b/test/pacman/tests/sync030.py @@ -10,7 +10,7 @@ for p in p1, p2: self.addpkg2db("sync", p) -self.args = "-S --asdeps %s" % " ".join([p.name for p in p1, p2]) +self.args = "-S --asdeps %s" % " ".join([p.name for p in (p1, p2)]) self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_VERSION=pkg1|1.0-2") diff --git a/test/pacman/tests/sync031.py b/test/pacman/tests/sync031.py index 4aa2ee3..7c5556e 100644 --- a/test/pacman/tests/sync031.py +++ b/test/pacman/tests/sync031.py @@ -10,7 +10,7 @@ for p in p1, p2: self.addpkg2db("sync", p) -self.args = "-S --asexplicit %s" % " ".join([p.name for p in p1, p2]) +self.args = "-S --asexplicit %s" % " ".join([p.name for p in (p1, p2)]) self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_VERSION=pkg1|1.0-2") diff --git a/test/pacman/tests/sync040.py b/test/pacman/tests/sync040.py index e5641fe..fa0b82d 100644 --- a/test/pacman/tests/sync040.py +++ b/test/pacman/tests/sync040.py @@ -8,7 +8,7 @@ for p in sp1, sp2: self.addpkg2db("sync", p); -self.args = "-S %s" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp2)]) self.addrule("PACMAN_RETCODE=1") for p in sp1, sp2: diff --git a/test/pacman/tests/sync041.py b/test/pacman/tests/sync041.py index 328728e..a90bb1a 100644 --- a/test/pacman/tests/sync041.py +++ b/test/pacman/tests/sync041.py @@ -9,7 +9,7 @@ for p in sp1, sp2: self.addpkg2db("sync", p); -self.args = "-S %s" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp2)]) self.addrule("PACMAN_RETCODE=1") self.addrule("!PKG_EXIST=pkg1") diff --git a/test/pacman/tests/sync405.py b/test/pacman/tests/sync405.py index 941a1af..602b1d3 100644 --- a/test/pacman/tests/sync405.py +++ b/test/pacman/tests/sync405.py @@ -15,7 +15,7 @@ lp.conflicts = ["phonon"] self.addpkg2db("local", lp) -self.args = "-S %s" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp2)]) self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_EXIST=kdelibs") diff --git a/test/pacman/tests/sync406.py b/test/pacman/tests/sync406.py index c15862f..516f89a 100644 --- a/test/pacman/tests/sync406.py +++ b/test/pacman/tests/sync406.py @@ -19,7 +19,7 @@ lp.conflicts = ["phonon"] self.addpkg2db("local", lp) -self.args = "-S %s" % " ".join([p.name for p in sp1, sp4]) +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp4)]) self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_EXIST=kdelibs") diff --git a/test/pacman/tests/sync891.py b/test/pacman/tests/sync891.py index 9b99e94..50f43fa 100644 --- a/test/pacman/tests/sync891.py +++ b/test/pacman/tests/sync891.py @@ -14,7 +14,7 @@ for p in lp1, lp2: self.addpkg2db("local", p) -self.args = "-S %s" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp2)]) self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_EXIST=pkg1") diff --git a/test/pacman/tests/sync892.py b/test/pacman/tests/sync892.py index dfd889e..d4171fe 100644 --- a/test/pacman/tests/sync892.py +++ b/test/pacman/tests/sync892.py @@ -16,7 +16,7 @@ for p in lp1, lp2: self.addpkg2db("local", p) -self.args = "-S %s --ask=4" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s --ask=4" % " ".join([p.name for p in (sp1, sp2)]) self.addrule("PACMAN_RETCODE=0") self.addrule("!PKG_EXIST=pkg1") diff --git a/test/pacman/tests/sync893.py b/test/pacman/tests/sync893.py index e96bb7b..ee0bdab 100644 --- a/test/pacman/tests/sync893.py +++ b/test/pacman/tests/sync893.py @@ -13,7 +13,7 @@ lp2 = pmpkg("pkg2") self.addpkg2db("local", lp2) -self.args = "-S %s --ask=4" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s --ask=4" % " ".join([p.name for p in (sp1, sp2)]) self.addrule("PACMAN_RETCODE=1") self.addrule("PKG_EXIST=pkg1") diff --git a/test/pacman/tests/sync898.py b/test/pacman/tests/sync898.py index 8fd59f1..dfedd6f 100644 --- a/test/pacman/tests/sync898.py +++ b/test/pacman/tests/sync898.py @@ -11,7 +11,7 @@ lp1 = pmpkg("pkg1") self.addpkg2db("local", lp1) -self.args = "-S %s" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp2)]) self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_VERSION=pkg1|1.0-2") diff --git a/test/pacman/tests/sync990.py b/test/pacman/tests/sync990.py index 6ac5a1f..38346b9 100644 --- a/test/pacman/tests/sync990.py +++ b/test/pacman/tests/sync990.py @@ -11,7 +11,7 @@ for p in sp1, sp2, sp3: self.addpkg2db("sync", p) -self.args = "-S %s" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp2)]) self.addrule("PACMAN_RETCODE=1") self.addrule("!PKG_EXIST=pkg1") diff --git a/test/pacman/tests/sync992.py b/test/pacman/tests/sync992.py index 63faaab..3b53893 100644 --- a/test/pacman/tests/sync992.py +++ b/test/pacman/tests/sync992.py @@ -15,7 +15,7 @@ lp1 = pmpkg("pkg2", "0.1-1") self.addpkg2db("local", lp1) -self.args = "-S %s --ask=4" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s --ask=4" % " ".join([p.name for p in (sp1, sp2)]) self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_EXIST=pkg1") diff --git a/test/pacman/tests/upgrade005.py b/test/pacman/tests/upgrade005.py index 0f8c13e..e0f77a6 100644 --- a/test/pacman/tests/upgrade005.py +++ b/test/pacman/tests/upgrade005.py @@ -14,7 +14,7 @@ for p in p1, p2, p3: self.addpkg(p) -self.args = "-U %s" % " ".join([p.filename() for p in p1, p2, p3]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2, p3)]) self.addrule("PACMAN_RETCODE=0") for p in p1, p2, p3: diff --git a/test/pacman/tests/upgrade013.py b/test/pacman/tests/upgrade013.py index 5a32759..4497f19 100644 --- a/test/pacman/tests/upgrade013.py +++ b/test/pacman/tests/upgrade013.py @@ -13,7 +13,7 @@ for p in p1, p2: self.addpkg(p) -self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)]) self.addrule("PACMAN_RETCODE=1") self.addrule("!PKG_EXIST=dummy") diff --git a/test/pacman/tests/upgrade014.py b/test/pacman/tests/upgrade014.py index 93c2fe2..2ef759d 100644 --- a/test/pacman/tests/upgrade014.py +++ b/test/pacman/tests/upgrade014.py @@ -13,7 +13,7 @@ for p in p1, p2: self.addpkg(p) -self.args = "-U --force %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U --force %s" % " ".join([p.filename() for p in (p1, p2)]) self.addrule("PACMAN_RETCODE=0") for p in p1, p2: diff --git a/test/pacman/tests/upgrade030.py b/test/pacman/tests/upgrade030.py index 8a6c473..ff09f72 100644 --- a/test/pacman/tests/upgrade030.py +++ b/test/pacman/tests/upgrade030.py @@ -14,7 +14,7 @@ for p in p1, p2: self.addpkg(p) -self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)]) self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_REASON=pkg1|0") diff --git a/test/pacman/tests/upgrade031.py b/test/pacman/tests/upgrade031.py index 856de98..a76a3d8 100644 --- a/test/pacman/tests/upgrade031.py +++ b/test/pacman/tests/upgrade031.py @@ -10,7 +10,7 @@ for p in p1, p2: self.addpkg(p) -self.args = "-U --asdeps %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U --asdeps %s" % " ".join([p.filename() for p in (p1, p2)]) self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_VERSION=pkg1|1.0-2") diff --git a/test/pacman/tests/upgrade032.py b/test/pacman/tests/upgrade032.py index 85e048e..6348a0f 100644 --- a/test/pacman/tests/upgrade032.py +++ b/test/pacman/tests/upgrade032.py @@ -10,7 +10,7 @@ for p in p1, p2: self.addpkg(p) -self.args = "-U --asexplicit %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U --asexplicit %s" % " ".join([p.filename() for p in (p1, p2)]) self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_VERSION=pkg1|1.0-2") diff --git a/test/pacman/tests/upgrade040.py b/test/pacman/tests/upgrade040.py index e17c717..a445743 100644 --- a/test/pacman/tests/upgrade040.py +++ b/test/pacman/tests/upgrade040.py @@ -20,7 +20,7 @@ for p in p1, p2: self.addpkg(p) -self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)]) self.addrule("PACMAN_RETCODE=0") for p in p1, p2: diff --git a/test/pacman/tests/upgrade041.py b/test/pacman/tests/upgrade041.py index 20da4f1..349d0f8 100644 --- a/test/pacman/tests/upgrade041.py +++ b/test/pacman/tests/upgrade041.py @@ -20,7 +20,7 @@ for p in p1, p2: self.addpkg(p) -self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)]) self.addrule("PACMAN_RETCODE=0") for p in p1, p2: diff --git a/test/pacman/tests/upgrade042.py b/test/pacman/tests/upgrade042.py index 4475499..df22393 100644 --- a/test/pacman/tests/upgrade042.py +++ b/test/pacman/tests/upgrade042.py @@ -17,7 +17,7 @@ p2.depends = [ "bash" ] self.addpkg(p2) -self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)]) self.filesystem = ["etc/profile"] diff --git a/test/pacman/tests/upgrade043.py b/test/pacman/tests/upgrade043.py index f531cb8..62a7bd0 100644 --- a/test/pacman/tests/upgrade043.py +++ b/test/pacman/tests/upgrade043.py @@ -17,7 +17,7 @@ p2.backup = ["etc/profile"] self.addpkg(p2) -self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)]) self.filesystem = ["etc/profile"] diff --git a/test/pacman/tests/upgrade046.py b/test/pacman/tests/upgrade046.py index d9ac66b..0b59ca6 100644 --- a/test/pacman/tests/upgrade046.py +++ b/test/pacman/tests/upgrade046.py @@ -20,7 +20,7 @@ for p in p1, p2: self.addpkg(p) -self.args = "-U --force %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U --force %s" % " ".join([p.filename() for p in (p1, p2)]) self.addrule("PACMAN_RETCODE=0") for p in p1, p2: diff --git a/test/pacman/tests/upgrade050.py b/test/pacman/tests/upgrade050.py index f05b0b6..bdda582 100644 --- a/test/pacman/tests/upgrade050.py +++ b/test/pacman/tests/upgrade050.py @@ -8,7 +8,7 @@ p2 = pmpkg("pkg2") self.addpkg(p2) -self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)]) self.addrule("PACMAN_RETCODE=1") self.addrule("!PKG_EXIST=pkg1") diff --git a/test/pacman/tests/upgrade059.py b/test/pacman/tests/upgrade059.py index 9cd9f1f..26a5810 100644 --- a/test/pacman/tests/upgrade059.py +++ b/test/pacman/tests/upgrade059.py @@ -18,7 +18,7 @@ p3 = pmpkg("pkg3", "1.0-2") self.addpkg(p3) -self.args = "-U %s" % " ".join([p.filename() for p in p2, p3]) +self.args = "-U %s" % " ".join([p.filename() for p in (p2, p3)]) self.addrule("PACMAN_RETCODE=1") self.addrule("PKG_EXIST=pkg1") diff --git a/test/pacman/tests/upgrade060.py b/test/pacman/tests/upgrade060.py index 7a28f3e..510562c 100644 --- a/test/pacman/tests/upgrade060.py +++ b/test/pacman/tests/upgrade060.py @@ -14,7 +14,7 @@ p2 = pmpkg("pkg2", "1.1-1") self.addpkg(p2) -self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)]) self.addrule("PACMAN_RETCODE=1") self.addrule("PKG_VERSION=pkg1|1.0-1") diff --git a/test/pacman/tests/upgrade061.py b/test/pacman/tests/upgrade061.py index 310e504..fd20c8b 100644 --- a/test/pacman/tests/upgrade061.py +++ b/test/pacman/tests/upgrade061.py @@ -15,7 +15,7 @@ p2 = pmpkg("pkg2", "1.0-2") self.addpkg(p2) -self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)]) self.addrule("PACMAN_RETCODE=1") self.addrule("PKG_VERSION=pkg1|1.0-1") diff --git a/test/pacman/tests/upgrade073.py b/test/pacman/tests/upgrade073.py index 752a233..7455ec1 100644 --- a/test/pacman/tests/upgrade073.py +++ b/test/pacman/tests/upgrade073.py @@ -15,7 +15,7 @@ for p in p1, p2, p3: self.addpkg(p) -self.args = "-U %s" % " ".join([p.filename() for p in p1, p2, p3]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2, p3)]) self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_VERSION=dummy|1.0-2") diff --git a/test/pacman/tests/upgrade090.py b/test/pacman/tests/upgrade090.py index cdd4cac..9eb8894 100644 --- a/test/pacman/tests/upgrade090.py +++ b/test/pacman/tests/upgrade090.py @@ -16,7 +16,7 @@ sp.files = ["bin/dep"] self.addpkg2db("sync", sp) -self.args = "-U %s --ask=16" % " ".join([p.filename() for p in p1, p2, p3]) +self.args = "-U %s --ask=16" % " ".join([p.filename() for p in (p1, p2, p3)]) self.addrule("PACMAN_RETCODE=0") for p in p1, p2, sp: -- 1.8.4
On Sat, Oct 12, 2013 at 12:44:36PM -0400, Jeremy Heiner wrote:
Reported by 2to3: optional in Python 2, but required in 3.
I believe the actual correct way to do string formatting here is to use something like 'str'.format(something) instead of 'str' % something. This is available in python 2.6, 2.7, and 3.3 at least. http://www.python.org/dev/peps/pep-3101/ (note the 'both systems can co-exist until it comes time to deprecate the older system.' at the end)
Signed-off-by: Jeremy Heiner <ScalaProtractor@gmail.com> --- test/pacman/tests/depconflict100.py | 2 +- test/pacman/tests/depconflict120.py | 2 +- test/pacman/tests/fileconflict001.py | 2 +- test/pacman/tests/fileconflict002.py | 2 +- test/pacman/tests/remove052.py | 2 +- test/pacman/tests/sync030.py | 2 +- test/pacman/tests/sync031.py | 2 +- test/pacman/tests/sync040.py | 2 +- test/pacman/tests/sync041.py | 2 +- test/pacman/tests/sync405.py | 2 +- test/pacman/tests/sync406.py | 2 +- test/pacman/tests/sync891.py | 2 +- test/pacman/tests/sync892.py | 2 +- test/pacman/tests/sync893.py | 2 +- test/pacman/tests/sync898.py | 2 +- test/pacman/tests/sync990.py | 2 +- test/pacman/tests/sync992.py | 2 +- test/pacman/tests/upgrade005.py | 2 +- test/pacman/tests/upgrade013.py | 2 +- test/pacman/tests/upgrade014.py | 2 +- test/pacman/tests/upgrade030.py | 2 +- test/pacman/tests/upgrade031.py | 2 +- test/pacman/tests/upgrade032.py | 2 +- test/pacman/tests/upgrade040.py | 2 +- test/pacman/tests/upgrade041.py | 2 +- test/pacman/tests/upgrade042.py | 2 +- test/pacman/tests/upgrade043.py | 2 +- test/pacman/tests/upgrade046.py | 2 +- test/pacman/tests/upgrade050.py | 2 +- test/pacman/tests/upgrade059.py | 2 +- test/pacman/tests/upgrade060.py | 2 +- test/pacman/tests/upgrade061.py | 2 +- test/pacman/tests/upgrade073.py | 2 +- test/pacman/tests/upgrade090.py | 2 +- 34 files changed, 34 insertions(+), 34 deletions(-)
diff --git a/test/pacman/tests/depconflict100.py b/test/pacman/tests/depconflict100.py index 948017d..72cbec6 100644 --- a/test/pacman/tests/depconflict100.py +++ b/test/pacman/tests/depconflict100.py @@ -7,7 +7,7 @@ sp2 = pmpkg("pkg2", "1.0-2") self.addpkg2db("sync", sp2)
-self.args = "-S %s" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp2)])
So, for example: self.args = "-S {}".format(" ".join[p.name for p in (sp1, sp2)])
self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_EXIST=pkg1") diff --git a/test/pacman/tests/depconflict120.py b/test/pacman/tests/depconflict120.py index a9f3f6b..8e9ab06 100644 --- a/test/pacman/tests/depconflict120.py +++ b/test/pacman/tests/depconflict120.py @@ -11,7 +11,7 @@ lp.provides = ["imaginary"] self.addpkg2db("local", lp)
-self.args = "-S %s" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp2)])
self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_EXIST=pkg1") diff --git a/test/pacman/tests/fileconflict001.py b/test/pacman/tests/fileconflict001.py index b1ad5e1..4777f93 100644 --- a/test/pacman/tests/fileconflict001.py +++ b/test/pacman/tests/fileconflict001.py @@ -18,7 +18,7 @@ "dir/symdir/file"] self.addpkg(p2)
-self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)])
self.addrule("PACMAN_RETCODE=1") self.addrule("!PKG_EXIST=pkg1") diff --git a/test/pacman/tests/fileconflict002.py b/test/pacman/tests/fileconflict002.py index 1e6113c..17ca618 100644 --- a/test/pacman/tests/fileconflict002.py +++ b/test/pacman/tests/fileconflict002.py @@ -13,7 +13,7 @@ "dir/symdir/file"] self.addpkg(p2)
-self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)])
self.addrule("PACMAN_RETCODE=1") self.addrule("!PKG_EXIST=pkg1") diff --git a/test/pacman/tests/remove052.py b/test/pacman/tests/remove052.py index df1e0db..4c444e4 100644 --- a/test/pacman/tests/remove052.py +++ b/test/pacman/tests/remove052.py @@ -13,7 +13,7 @@ lp3.reason = 1 self.addpkg2db("local", lp3)
-self.args = "-Rs %s" % " ".join([p.name for p in lp1, lp3]) +self.args = "-Rs %s" % " ".join([p.name for p in (lp1, lp3)])
self.addrule("PACMAN_RETCODE=0") self.addrule("!PKG_EXIST=pkg1") diff --git a/test/pacman/tests/sync030.py b/test/pacman/tests/sync030.py index 1fd9750..b904ddb 100644 --- a/test/pacman/tests/sync030.py +++ b/test/pacman/tests/sync030.py @@ -10,7 +10,7 @@ for p in p1, p2: self.addpkg2db("sync", p)
-self.args = "-S --asdeps %s" % " ".join([p.name for p in p1, p2]) +self.args = "-S --asdeps %s" % " ".join([p.name for p in (p1, p2)])
self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_VERSION=pkg1|1.0-2") diff --git a/test/pacman/tests/sync031.py b/test/pacman/tests/sync031.py index 4aa2ee3..7c5556e 100644 --- a/test/pacman/tests/sync031.py +++ b/test/pacman/tests/sync031.py @@ -10,7 +10,7 @@ for p in p1, p2: self.addpkg2db("sync", p)
-self.args = "-S --asexplicit %s" % " ".join([p.name for p in p1, p2]) +self.args = "-S --asexplicit %s" % " ".join([p.name for p in (p1, p2)])
self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_VERSION=pkg1|1.0-2") diff --git a/test/pacman/tests/sync040.py b/test/pacman/tests/sync040.py index e5641fe..fa0b82d 100644 --- a/test/pacman/tests/sync040.py +++ b/test/pacman/tests/sync040.py @@ -8,7 +8,7 @@ for p in sp1, sp2: self.addpkg2db("sync", p);
-self.args = "-S %s" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp2)])
self.addrule("PACMAN_RETCODE=1") for p in sp1, sp2: diff --git a/test/pacman/tests/sync041.py b/test/pacman/tests/sync041.py index 328728e..a90bb1a 100644 --- a/test/pacman/tests/sync041.py +++ b/test/pacman/tests/sync041.py @@ -9,7 +9,7 @@ for p in sp1, sp2: self.addpkg2db("sync", p);
-self.args = "-S %s" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp2)])
self.addrule("PACMAN_RETCODE=1") self.addrule("!PKG_EXIST=pkg1") diff --git a/test/pacman/tests/sync405.py b/test/pacman/tests/sync405.py index 941a1af..602b1d3 100644 --- a/test/pacman/tests/sync405.py +++ b/test/pacman/tests/sync405.py @@ -15,7 +15,7 @@ lp.conflicts = ["phonon"] self.addpkg2db("local", lp)
-self.args = "-S %s" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp2)])
self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_EXIST=kdelibs") diff --git a/test/pacman/tests/sync406.py b/test/pacman/tests/sync406.py index c15862f..516f89a 100644 --- a/test/pacman/tests/sync406.py +++ b/test/pacman/tests/sync406.py @@ -19,7 +19,7 @@ lp.conflicts = ["phonon"] self.addpkg2db("local", lp)
-self.args = "-S %s" % " ".join([p.name for p in sp1, sp4]) +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp4)])
self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_EXIST=kdelibs") diff --git a/test/pacman/tests/sync891.py b/test/pacman/tests/sync891.py index 9b99e94..50f43fa 100644 --- a/test/pacman/tests/sync891.py +++ b/test/pacman/tests/sync891.py @@ -14,7 +14,7 @@ for p in lp1, lp2: self.addpkg2db("local", p)
-self.args = "-S %s" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp2)])
self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_EXIST=pkg1") diff --git a/test/pacman/tests/sync892.py b/test/pacman/tests/sync892.py index dfd889e..d4171fe 100644 --- a/test/pacman/tests/sync892.py +++ b/test/pacman/tests/sync892.py @@ -16,7 +16,7 @@ for p in lp1, lp2: self.addpkg2db("local", p)
-self.args = "-S %s --ask=4" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s --ask=4" % " ".join([p.name for p in (sp1, sp2)])
self.addrule("PACMAN_RETCODE=0") self.addrule("!PKG_EXIST=pkg1") diff --git a/test/pacman/tests/sync893.py b/test/pacman/tests/sync893.py index e96bb7b..ee0bdab 100644 --- a/test/pacman/tests/sync893.py +++ b/test/pacman/tests/sync893.py @@ -13,7 +13,7 @@ lp2 = pmpkg("pkg2") self.addpkg2db("local", lp2)
-self.args = "-S %s --ask=4" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s --ask=4" % " ".join([p.name for p in (sp1, sp2)])
self.addrule("PACMAN_RETCODE=1") self.addrule("PKG_EXIST=pkg1") diff --git a/test/pacman/tests/sync898.py b/test/pacman/tests/sync898.py index 8fd59f1..dfedd6f 100644 --- a/test/pacman/tests/sync898.py +++ b/test/pacman/tests/sync898.py @@ -11,7 +11,7 @@ lp1 = pmpkg("pkg1") self.addpkg2db("local", lp1)
-self.args = "-S %s" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp2)])
self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_VERSION=pkg1|1.0-2") diff --git a/test/pacman/tests/sync990.py b/test/pacman/tests/sync990.py index 6ac5a1f..38346b9 100644 --- a/test/pacman/tests/sync990.py +++ b/test/pacman/tests/sync990.py @@ -11,7 +11,7 @@ for p in sp1, sp2, sp3: self.addpkg2db("sync", p)
-self.args = "-S %s" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp2)])
self.addrule("PACMAN_RETCODE=1") self.addrule("!PKG_EXIST=pkg1") diff --git a/test/pacman/tests/sync992.py b/test/pacman/tests/sync992.py index 63faaab..3b53893 100644 --- a/test/pacman/tests/sync992.py +++ b/test/pacman/tests/sync992.py @@ -15,7 +15,7 @@ lp1 = pmpkg("pkg2", "0.1-1") self.addpkg2db("local", lp1)
-self.args = "-S %s --ask=4" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s --ask=4" % " ".join([p.name for p in (sp1, sp2)])
self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_EXIST=pkg1") diff --git a/test/pacman/tests/upgrade005.py b/test/pacman/tests/upgrade005.py index 0f8c13e..e0f77a6 100644 --- a/test/pacman/tests/upgrade005.py +++ b/test/pacman/tests/upgrade005.py @@ -14,7 +14,7 @@ for p in p1, p2, p3: self.addpkg(p)
-self.args = "-U %s" % " ".join([p.filename() for p in p1, p2, p3]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2, p3)])
self.addrule("PACMAN_RETCODE=0") for p in p1, p2, p3: diff --git a/test/pacman/tests/upgrade013.py b/test/pacman/tests/upgrade013.py index 5a32759..4497f19 100644 --- a/test/pacman/tests/upgrade013.py +++ b/test/pacman/tests/upgrade013.py @@ -13,7 +13,7 @@ for p in p1, p2: self.addpkg(p)
-self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)])
self.addrule("PACMAN_RETCODE=1") self.addrule("!PKG_EXIST=dummy") diff --git a/test/pacman/tests/upgrade014.py b/test/pacman/tests/upgrade014.py index 93c2fe2..2ef759d 100644 --- a/test/pacman/tests/upgrade014.py +++ b/test/pacman/tests/upgrade014.py @@ -13,7 +13,7 @@ for p in p1, p2: self.addpkg(p)
-self.args = "-U --force %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U --force %s" % " ".join([p.filename() for p in (p1, p2)])
self.addrule("PACMAN_RETCODE=0") for p in p1, p2: diff --git a/test/pacman/tests/upgrade030.py b/test/pacman/tests/upgrade030.py index 8a6c473..ff09f72 100644 --- a/test/pacman/tests/upgrade030.py +++ b/test/pacman/tests/upgrade030.py @@ -14,7 +14,7 @@ for p in p1, p2: self.addpkg(p)
-self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)])
self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_REASON=pkg1|0") diff --git a/test/pacman/tests/upgrade031.py b/test/pacman/tests/upgrade031.py index 856de98..a76a3d8 100644 --- a/test/pacman/tests/upgrade031.py +++ b/test/pacman/tests/upgrade031.py @@ -10,7 +10,7 @@ for p in p1, p2: self.addpkg(p)
-self.args = "-U --asdeps %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U --asdeps %s" % " ".join([p.filename() for p in (p1, p2)])
self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_VERSION=pkg1|1.0-2") diff --git a/test/pacman/tests/upgrade032.py b/test/pacman/tests/upgrade032.py index 85e048e..6348a0f 100644 --- a/test/pacman/tests/upgrade032.py +++ b/test/pacman/tests/upgrade032.py @@ -10,7 +10,7 @@ for p in p1, p2: self.addpkg(p)
-self.args = "-U --asexplicit %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U --asexplicit %s" % " ".join([p.filename() for p in (p1, p2)])
self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_VERSION=pkg1|1.0-2") diff --git a/test/pacman/tests/upgrade040.py b/test/pacman/tests/upgrade040.py index e17c717..a445743 100644 --- a/test/pacman/tests/upgrade040.py +++ b/test/pacman/tests/upgrade040.py @@ -20,7 +20,7 @@ for p in p1, p2: self.addpkg(p)
-self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)])
self.addrule("PACMAN_RETCODE=0") for p in p1, p2: diff --git a/test/pacman/tests/upgrade041.py b/test/pacman/tests/upgrade041.py index 20da4f1..349d0f8 100644 --- a/test/pacman/tests/upgrade041.py +++ b/test/pacman/tests/upgrade041.py @@ -20,7 +20,7 @@ for p in p1, p2: self.addpkg(p)
-self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)])
self.addrule("PACMAN_RETCODE=0") for p in p1, p2: diff --git a/test/pacman/tests/upgrade042.py b/test/pacman/tests/upgrade042.py index 4475499..df22393 100644 --- a/test/pacman/tests/upgrade042.py +++ b/test/pacman/tests/upgrade042.py @@ -17,7 +17,7 @@ p2.depends = [ "bash" ] self.addpkg(p2)
-self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)])
self.filesystem = ["etc/profile"]
diff --git a/test/pacman/tests/upgrade043.py b/test/pacman/tests/upgrade043.py index f531cb8..62a7bd0 100644 --- a/test/pacman/tests/upgrade043.py +++ b/test/pacman/tests/upgrade043.py @@ -17,7 +17,7 @@ p2.backup = ["etc/profile"] self.addpkg(p2)
-self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)])
self.filesystem = ["etc/profile"]
diff --git a/test/pacman/tests/upgrade046.py b/test/pacman/tests/upgrade046.py index d9ac66b..0b59ca6 100644 --- a/test/pacman/tests/upgrade046.py +++ b/test/pacman/tests/upgrade046.py @@ -20,7 +20,7 @@ for p in p1, p2: self.addpkg(p)
-self.args = "-U --force %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U --force %s" % " ".join([p.filename() for p in (p1, p2)])
self.addrule("PACMAN_RETCODE=0") for p in p1, p2: diff --git a/test/pacman/tests/upgrade050.py b/test/pacman/tests/upgrade050.py index f05b0b6..bdda582 100644 --- a/test/pacman/tests/upgrade050.py +++ b/test/pacman/tests/upgrade050.py @@ -8,7 +8,7 @@ p2 = pmpkg("pkg2") self.addpkg(p2)
-self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)])
self.addrule("PACMAN_RETCODE=1") self.addrule("!PKG_EXIST=pkg1") diff --git a/test/pacman/tests/upgrade059.py b/test/pacman/tests/upgrade059.py index 9cd9f1f..26a5810 100644 --- a/test/pacman/tests/upgrade059.py +++ b/test/pacman/tests/upgrade059.py @@ -18,7 +18,7 @@ p3 = pmpkg("pkg3", "1.0-2") self.addpkg(p3)
-self.args = "-U %s" % " ".join([p.filename() for p in p2, p3]) +self.args = "-U %s" % " ".join([p.filename() for p in (p2, p3)])
self.addrule("PACMAN_RETCODE=1") self.addrule("PKG_EXIST=pkg1") diff --git a/test/pacman/tests/upgrade060.py b/test/pacman/tests/upgrade060.py index 7a28f3e..510562c 100644 --- a/test/pacman/tests/upgrade060.py +++ b/test/pacman/tests/upgrade060.py @@ -14,7 +14,7 @@ p2 = pmpkg("pkg2", "1.1-1") self.addpkg(p2)
-self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)])
self.addrule("PACMAN_RETCODE=1") self.addrule("PKG_VERSION=pkg1|1.0-1") diff --git a/test/pacman/tests/upgrade061.py b/test/pacman/tests/upgrade061.py index 310e504..fd20c8b 100644 --- a/test/pacman/tests/upgrade061.py +++ b/test/pacman/tests/upgrade061.py @@ -15,7 +15,7 @@ p2 = pmpkg("pkg2", "1.0-2") self.addpkg(p2)
-self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)])
self.addrule("PACMAN_RETCODE=1") self.addrule("PKG_VERSION=pkg1|1.0-1") diff --git a/test/pacman/tests/upgrade073.py b/test/pacman/tests/upgrade073.py index 752a233..7455ec1 100644 --- a/test/pacman/tests/upgrade073.py +++ b/test/pacman/tests/upgrade073.py @@ -15,7 +15,7 @@ for p in p1, p2, p3: self.addpkg(p)
-self.args = "-U %s" % " ".join([p.filename() for p in p1, p2, p3]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2, p3)])
self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_VERSION=dummy|1.0-2") diff --git a/test/pacman/tests/upgrade090.py b/test/pacman/tests/upgrade090.py index cdd4cac..9eb8894 100644 --- a/test/pacman/tests/upgrade090.py +++ b/test/pacman/tests/upgrade090.py @@ -16,7 +16,7 @@ sp.files = ["bin/dep"] self.addpkg2db("sync", sp)
-self.args = "-U %s --ask=16" % " ".join([p.filename() for p in p1, p2, p3]) +self.args = "-U %s --ask=16" % " ".join([p.filename() for p in (p1, p2, p3)])
self.addrule("PACMAN_RETCODE=0") for p in p1, p2, sp: -- 1.8.4
-- William Giokas | KaiSforza | http://kaictl.net/ GnuPG Key: 0x73CD09CF Fingerprint: F73F 50EF BBE2 9846 8306 E6B8 6902 06D8 73CD 09CF
On Sat, Oct 12, 2013 at 03:24:08PM -0500, William Giokas wrote:
On Sat, Oct 12, 2013 at 12:44:36PM -0400, Jeremy Heiner wrote:
Reported by 2to3: optional in Python 2, but required in 3.
I believe the actual correct way to do string formatting here is to use something like 'str'.format(something) instead of 'str' % something.
This is available in python 2.6, 2.7, and 3.3 at least.
http://www.python.org/dev/peps/pep-3101/ (note the 'both systems can co-exist until it comes time to deprecate the older system.' at the end)
Actually, there's a lot of places where this could to be changed. I'll submit a patch separately for this either way.
Signed-off-by: Jeremy Heiner <ScalaProtractor@gmail.com> --- test/pacman/tests/depconflict100.py | 2 +- test/pacman/tests/depconflict120.py | 2 +- test/pacman/tests/fileconflict001.py | 2 +- test/pacman/tests/fileconflict002.py | 2 +- test/pacman/tests/remove052.py | 2 +- test/pacman/tests/sync030.py | 2 +- test/pacman/tests/sync031.py | 2 +- test/pacman/tests/sync040.py | 2 +- test/pacman/tests/sync041.py | 2 +- test/pacman/tests/sync405.py | 2 +- test/pacman/tests/sync406.py | 2 +- test/pacman/tests/sync891.py | 2 +- test/pacman/tests/sync892.py | 2 +- test/pacman/tests/sync893.py | 2 +- test/pacman/tests/sync898.py | 2 +- test/pacman/tests/sync990.py | 2 +- test/pacman/tests/sync992.py | 2 +- test/pacman/tests/upgrade005.py | 2 +- test/pacman/tests/upgrade013.py | 2 +- test/pacman/tests/upgrade014.py | 2 +- test/pacman/tests/upgrade030.py | 2 +- test/pacman/tests/upgrade031.py | 2 +- test/pacman/tests/upgrade032.py | 2 +- test/pacman/tests/upgrade040.py | 2 +- test/pacman/tests/upgrade041.py | 2 +- test/pacman/tests/upgrade042.py | 2 +- test/pacman/tests/upgrade043.py | 2 +- test/pacman/tests/upgrade046.py | 2 +- test/pacman/tests/upgrade050.py | 2 +- test/pacman/tests/upgrade059.py | 2 +- test/pacman/tests/upgrade060.py | 2 +- test/pacman/tests/upgrade061.py | 2 +- test/pacman/tests/upgrade073.py | 2 +- test/pacman/tests/upgrade090.py | 2 +- 34 files changed, 34 insertions(+), 34 deletions(-)
diff --git a/test/pacman/tests/depconflict100.py b/test/pacman/tests/depconflict100.py index 948017d..72cbec6 100644 --- a/test/pacman/tests/depconflict100.py +++ b/test/pacman/tests/depconflict100.py @@ -7,7 +7,7 @@ sp2 = pmpkg("pkg2", "1.0-2") self.addpkg2db("sync", sp2)
-self.args = "-S %s" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp2)])
So, for example: self.args = "-S {}".format(" ".join[p.name for p in (sp1, sp2)])
self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_EXIST=pkg1") diff --git a/test/pacman/tests/depconflict120.py b/test/pacman/tests/depconflict120.py index a9f3f6b..8e9ab06 100644 --- a/test/pacman/tests/depconflict120.py +++ b/test/pacman/tests/depconflict120.py @@ -11,7 +11,7 @@ lp.provides = ["imaginary"] self.addpkg2db("local", lp)
-self.args = "-S %s" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp2)])
self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_EXIST=pkg1") diff --git a/test/pacman/tests/fileconflict001.py b/test/pacman/tests/fileconflict001.py index b1ad5e1..4777f93 100644 --- a/test/pacman/tests/fileconflict001.py +++ b/test/pacman/tests/fileconflict001.py @@ -18,7 +18,7 @@ "dir/symdir/file"] self.addpkg(p2)
-self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)])
self.addrule("PACMAN_RETCODE=1") self.addrule("!PKG_EXIST=pkg1") diff --git a/test/pacman/tests/fileconflict002.py b/test/pacman/tests/fileconflict002.py index 1e6113c..17ca618 100644 --- a/test/pacman/tests/fileconflict002.py +++ b/test/pacman/tests/fileconflict002.py @@ -13,7 +13,7 @@ "dir/symdir/file"] self.addpkg(p2)
-self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)])
self.addrule("PACMAN_RETCODE=1") self.addrule("!PKG_EXIST=pkg1") diff --git a/test/pacman/tests/remove052.py b/test/pacman/tests/remove052.py index df1e0db..4c444e4 100644 --- a/test/pacman/tests/remove052.py +++ b/test/pacman/tests/remove052.py @@ -13,7 +13,7 @@ lp3.reason = 1 self.addpkg2db("local", lp3)
-self.args = "-Rs %s" % " ".join([p.name for p in lp1, lp3]) +self.args = "-Rs %s" % " ".join([p.name for p in (lp1, lp3)])
self.addrule("PACMAN_RETCODE=0") self.addrule("!PKG_EXIST=pkg1") diff --git a/test/pacman/tests/sync030.py b/test/pacman/tests/sync030.py index 1fd9750..b904ddb 100644 --- a/test/pacman/tests/sync030.py +++ b/test/pacman/tests/sync030.py @@ -10,7 +10,7 @@ for p in p1, p2: self.addpkg2db("sync", p)
-self.args = "-S --asdeps %s" % " ".join([p.name for p in p1, p2]) +self.args = "-S --asdeps %s" % " ".join([p.name for p in (p1, p2)])
self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_VERSION=pkg1|1.0-2") diff --git a/test/pacman/tests/sync031.py b/test/pacman/tests/sync031.py index 4aa2ee3..7c5556e 100644 --- a/test/pacman/tests/sync031.py +++ b/test/pacman/tests/sync031.py @@ -10,7 +10,7 @@ for p in p1, p2: self.addpkg2db("sync", p)
-self.args = "-S --asexplicit %s" % " ".join([p.name for p in p1, p2]) +self.args = "-S --asexplicit %s" % " ".join([p.name for p in (p1, p2)])
self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_VERSION=pkg1|1.0-2") diff --git a/test/pacman/tests/sync040.py b/test/pacman/tests/sync040.py index e5641fe..fa0b82d 100644 --- a/test/pacman/tests/sync040.py +++ b/test/pacman/tests/sync040.py @@ -8,7 +8,7 @@ for p in sp1, sp2: self.addpkg2db("sync", p);
-self.args = "-S %s" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp2)])
self.addrule("PACMAN_RETCODE=1") for p in sp1, sp2: diff --git a/test/pacman/tests/sync041.py b/test/pacman/tests/sync041.py index 328728e..a90bb1a 100644 --- a/test/pacman/tests/sync041.py +++ b/test/pacman/tests/sync041.py @@ -9,7 +9,7 @@ for p in sp1, sp2: self.addpkg2db("sync", p);
-self.args = "-S %s" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp2)])
self.addrule("PACMAN_RETCODE=1") self.addrule("!PKG_EXIST=pkg1") diff --git a/test/pacman/tests/sync405.py b/test/pacman/tests/sync405.py index 941a1af..602b1d3 100644 --- a/test/pacman/tests/sync405.py +++ b/test/pacman/tests/sync405.py @@ -15,7 +15,7 @@ lp.conflicts = ["phonon"] self.addpkg2db("local", lp)
-self.args = "-S %s" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp2)])
self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_EXIST=kdelibs") diff --git a/test/pacman/tests/sync406.py b/test/pacman/tests/sync406.py index c15862f..516f89a 100644 --- a/test/pacman/tests/sync406.py +++ b/test/pacman/tests/sync406.py @@ -19,7 +19,7 @@ lp.conflicts = ["phonon"] self.addpkg2db("local", lp)
-self.args = "-S %s" % " ".join([p.name for p in sp1, sp4]) +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp4)])
self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_EXIST=kdelibs") diff --git a/test/pacman/tests/sync891.py b/test/pacman/tests/sync891.py index 9b99e94..50f43fa 100644 --- a/test/pacman/tests/sync891.py +++ b/test/pacman/tests/sync891.py @@ -14,7 +14,7 @@ for p in lp1, lp2: self.addpkg2db("local", p)
-self.args = "-S %s" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp2)])
self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_EXIST=pkg1") diff --git a/test/pacman/tests/sync892.py b/test/pacman/tests/sync892.py index dfd889e..d4171fe 100644 --- a/test/pacman/tests/sync892.py +++ b/test/pacman/tests/sync892.py @@ -16,7 +16,7 @@ for p in lp1, lp2: self.addpkg2db("local", p)
-self.args = "-S %s --ask=4" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s --ask=4" % " ".join([p.name for p in (sp1, sp2)])
self.addrule("PACMAN_RETCODE=0") self.addrule("!PKG_EXIST=pkg1") diff --git a/test/pacman/tests/sync893.py b/test/pacman/tests/sync893.py index e96bb7b..ee0bdab 100644 --- a/test/pacman/tests/sync893.py +++ b/test/pacman/tests/sync893.py @@ -13,7 +13,7 @@ lp2 = pmpkg("pkg2") self.addpkg2db("local", lp2)
-self.args = "-S %s --ask=4" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s --ask=4" % " ".join([p.name for p in (sp1, sp2)])
self.addrule("PACMAN_RETCODE=1") self.addrule("PKG_EXIST=pkg1") diff --git a/test/pacman/tests/sync898.py b/test/pacman/tests/sync898.py index 8fd59f1..dfedd6f 100644 --- a/test/pacman/tests/sync898.py +++ b/test/pacman/tests/sync898.py @@ -11,7 +11,7 @@ lp1 = pmpkg("pkg1") self.addpkg2db("local", lp1)
-self.args = "-S %s" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp2)])
self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_VERSION=pkg1|1.0-2") diff --git a/test/pacman/tests/sync990.py b/test/pacman/tests/sync990.py index 6ac5a1f..38346b9 100644 --- a/test/pacman/tests/sync990.py +++ b/test/pacman/tests/sync990.py @@ -11,7 +11,7 @@ for p in sp1, sp2, sp3: self.addpkg2db("sync", p)
-self.args = "-S %s" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp2)])
self.addrule("PACMAN_RETCODE=1") self.addrule("!PKG_EXIST=pkg1") diff --git a/test/pacman/tests/sync992.py b/test/pacman/tests/sync992.py index 63faaab..3b53893 100644 --- a/test/pacman/tests/sync992.py +++ b/test/pacman/tests/sync992.py @@ -15,7 +15,7 @@ lp1 = pmpkg("pkg2", "0.1-1") self.addpkg2db("local", lp1)
-self.args = "-S %s --ask=4" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s --ask=4" % " ".join([p.name for p in (sp1, sp2)])
self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_EXIST=pkg1") diff --git a/test/pacman/tests/upgrade005.py b/test/pacman/tests/upgrade005.py index 0f8c13e..e0f77a6 100644 --- a/test/pacman/tests/upgrade005.py +++ b/test/pacman/tests/upgrade005.py @@ -14,7 +14,7 @@ for p in p1, p2, p3: self.addpkg(p)
-self.args = "-U %s" % " ".join([p.filename() for p in p1, p2, p3]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2, p3)])
self.addrule("PACMAN_RETCODE=0") for p in p1, p2, p3: diff --git a/test/pacman/tests/upgrade013.py b/test/pacman/tests/upgrade013.py index 5a32759..4497f19 100644 --- a/test/pacman/tests/upgrade013.py +++ b/test/pacman/tests/upgrade013.py @@ -13,7 +13,7 @@ for p in p1, p2: self.addpkg(p)
-self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)])
self.addrule("PACMAN_RETCODE=1") self.addrule("!PKG_EXIST=dummy") diff --git a/test/pacman/tests/upgrade014.py b/test/pacman/tests/upgrade014.py index 93c2fe2..2ef759d 100644 --- a/test/pacman/tests/upgrade014.py +++ b/test/pacman/tests/upgrade014.py @@ -13,7 +13,7 @@ for p in p1, p2: self.addpkg(p)
-self.args = "-U --force %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U --force %s" % " ".join([p.filename() for p in (p1, p2)])
self.addrule("PACMAN_RETCODE=0") for p in p1, p2: diff --git a/test/pacman/tests/upgrade030.py b/test/pacman/tests/upgrade030.py index 8a6c473..ff09f72 100644 --- a/test/pacman/tests/upgrade030.py +++ b/test/pacman/tests/upgrade030.py @@ -14,7 +14,7 @@ for p in p1, p2: self.addpkg(p)
-self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)])
self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_REASON=pkg1|0") diff --git a/test/pacman/tests/upgrade031.py b/test/pacman/tests/upgrade031.py index 856de98..a76a3d8 100644 --- a/test/pacman/tests/upgrade031.py +++ b/test/pacman/tests/upgrade031.py @@ -10,7 +10,7 @@ for p in p1, p2: self.addpkg(p)
-self.args = "-U --asdeps %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U --asdeps %s" % " ".join([p.filename() for p in (p1, p2)])
self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_VERSION=pkg1|1.0-2") diff --git a/test/pacman/tests/upgrade032.py b/test/pacman/tests/upgrade032.py index 85e048e..6348a0f 100644 --- a/test/pacman/tests/upgrade032.py +++ b/test/pacman/tests/upgrade032.py @@ -10,7 +10,7 @@ for p in p1, p2: self.addpkg(p)
-self.args = "-U --asexplicit %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U --asexplicit %s" % " ".join([p.filename() for p in (p1, p2)])
self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_VERSION=pkg1|1.0-2") diff --git a/test/pacman/tests/upgrade040.py b/test/pacman/tests/upgrade040.py index e17c717..a445743 100644 --- a/test/pacman/tests/upgrade040.py +++ b/test/pacman/tests/upgrade040.py @@ -20,7 +20,7 @@ for p in p1, p2: self.addpkg(p)
-self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)])
self.addrule("PACMAN_RETCODE=0") for p in p1, p2: diff --git a/test/pacman/tests/upgrade041.py b/test/pacman/tests/upgrade041.py index 20da4f1..349d0f8 100644 --- a/test/pacman/tests/upgrade041.py +++ b/test/pacman/tests/upgrade041.py @@ -20,7 +20,7 @@ for p in p1, p2: self.addpkg(p)
-self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)])
self.addrule("PACMAN_RETCODE=0") for p in p1, p2: diff --git a/test/pacman/tests/upgrade042.py b/test/pacman/tests/upgrade042.py index 4475499..df22393 100644 --- a/test/pacman/tests/upgrade042.py +++ b/test/pacman/tests/upgrade042.py @@ -17,7 +17,7 @@ p2.depends = [ "bash" ] self.addpkg(p2)
-self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)])
self.filesystem = ["etc/profile"]
diff --git a/test/pacman/tests/upgrade043.py b/test/pacman/tests/upgrade043.py index f531cb8..62a7bd0 100644 --- a/test/pacman/tests/upgrade043.py +++ b/test/pacman/tests/upgrade043.py @@ -17,7 +17,7 @@ p2.backup = ["etc/profile"] self.addpkg(p2)
-self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)])
self.filesystem = ["etc/profile"]
diff --git a/test/pacman/tests/upgrade046.py b/test/pacman/tests/upgrade046.py index d9ac66b..0b59ca6 100644 --- a/test/pacman/tests/upgrade046.py +++ b/test/pacman/tests/upgrade046.py @@ -20,7 +20,7 @@ for p in p1, p2: self.addpkg(p)
-self.args = "-U --force %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U --force %s" % " ".join([p.filename() for p in (p1, p2)])
self.addrule("PACMAN_RETCODE=0") for p in p1, p2: diff --git a/test/pacman/tests/upgrade050.py b/test/pacman/tests/upgrade050.py index f05b0b6..bdda582 100644 --- a/test/pacman/tests/upgrade050.py +++ b/test/pacman/tests/upgrade050.py @@ -8,7 +8,7 @@ p2 = pmpkg("pkg2") self.addpkg(p2)
-self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)])
self.addrule("PACMAN_RETCODE=1") self.addrule("!PKG_EXIST=pkg1") diff --git a/test/pacman/tests/upgrade059.py b/test/pacman/tests/upgrade059.py index 9cd9f1f..26a5810 100644 --- a/test/pacman/tests/upgrade059.py +++ b/test/pacman/tests/upgrade059.py @@ -18,7 +18,7 @@ p3 = pmpkg("pkg3", "1.0-2") self.addpkg(p3)
-self.args = "-U %s" % " ".join([p.filename() for p in p2, p3]) +self.args = "-U %s" % " ".join([p.filename() for p in (p2, p3)])
self.addrule("PACMAN_RETCODE=1") self.addrule("PKG_EXIST=pkg1") diff --git a/test/pacman/tests/upgrade060.py b/test/pacman/tests/upgrade060.py index 7a28f3e..510562c 100644 --- a/test/pacman/tests/upgrade060.py +++ b/test/pacman/tests/upgrade060.py @@ -14,7 +14,7 @@ p2 = pmpkg("pkg2", "1.1-1") self.addpkg(p2)
-self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)])
self.addrule("PACMAN_RETCODE=1") self.addrule("PKG_VERSION=pkg1|1.0-1") diff --git a/test/pacman/tests/upgrade061.py b/test/pacman/tests/upgrade061.py index 310e504..fd20c8b 100644 --- a/test/pacman/tests/upgrade061.py +++ b/test/pacman/tests/upgrade061.py @@ -15,7 +15,7 @@ p2 = pmpkg("pkg2", "1.0-2") self.addpkg(p2)
-self.args = "-U %s" % " ".join([p.filename() for p in p1, p2]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2)])
self.addrule("PACMAN_RETCODE=1") self.addrule("PKG_VERSION=pkg1|1.0-1") diff --git a/test/pacman/tests/upgrade073.py b/test/pacman/tests/upgrade073.py index 752a233..7455ec1 100644 --- a/test/pacman/tests/upgrade073.py +++ b/test/pacman/tests/upgrade073.py @@ -15,7 +15,7 @@ for p in p1, p2, p3: self.addpkg(p)
-self.args = "-U %s" % " ".join([p.filename() for p in p1, p2, p3]) +self.args = "-U %s" % " ".join([p.filename() for p in (p1, p2, p3)])
self.addrule("PACMAN_RETCODE=0") self.addrule("PKG_VERSION=dummy|1.0-2") diff --git a/test/pacman/tests/upgrade090.py b/test/pacman/tests/upgrade090.py index cdd4cac..9eb8894 100644 --- a/test/pacman/tests/upgrade090.py +++ b/test/pacman/tests/upgrade090.py @@ -16,7 +16,7 @@ sp.files = ["bin/dep"] self.addpkg2db("sync", sp)
-self.args = "-U %s --ask=16" % " ".join([p.filename() for p in p1, p2, p3]) +self.args = "-U %s --ask=16" % " ".join([p.filename() for p in (p1, p2, p3)])
self.addrule("PACMAN_RETCODE=0") for p in p1, p2, sp: -- 1.8.4
-- William Giokas | KaiSforza | http://kaictl.net/ GnuPG Key: 0x73CD09CF Fingerprint: F73F 50EF BBE2 9846 8306 E6B8 6902 06D8 73CD 09CF
-- William Giokas | KaiSforza | http://kaictl.net/ GnuPG Key: 0x73CD09CF Fingerprint: F73F 50EF BBE2 9846 8306 E6B8 6902 06D8 73CD 09CF
On 13 October 2013 07:24, William Giokas <1007380@gmail.com> wrote:
I believe the actual correct way to do string formatting here is to use something like 'str'.format(something) instead of 'str' % something.
This is available in python 2.6, 2.7, and 3.3 at least.
http://www.python.org/dev/peps/pep-3101/ (note the 'both systems can co-exist until it comes time to deprecate the older system.' at the end)
diff --git a/test/pacman/tests/depconflict100.py b/test/pacman/tests/depconflict100.py index 948017d..72cbec6 100644 --- a/test/pacman/tests/depconflict100.py +++ b/test/pacman/tests/depconflict100.py @@ -7,7 +7,7 @@ sp2 = pmpkg("pkg2", "1.0-2") self.addpkg2db("sync", sp2)
-self.args = "-S %s" % " ".join([p.name for p in sp1, sp2]) +self.args = "-S %s" % " ".join([p.name for p in (sp1, sp2)]) So, for example: self.args = "-S {}".format(" ".join[p.name for p in (sp1, sp2)])
Jeremy’s patch looks fine for the purpose of Python 3 porting. But if you want to clean these lines up further, can I suggest also dropping the list comprehension for a generator expression? Note no square brackets: " ".join(p.name for p in (sp1, sp2)) -Martin
On Sat, Oct 12, 2013 at 6:26 PM, Martin Panter <vadmium+patch@gmail.com> wrote:
Jeremy’s patch looks fine for the purpose of Python 3 porting.
Just FYI: this patch was actually authored by 2to3. That's why it's the last one - earlier edits were also 2to3 suggestions, but they were fewer in number, so I would do them by hand (sometimes picking a better solution than 2to3 offered) in clumps, then git commit, then rerun 2to3. Eventually just these parentheses-fixes were left, so I let 2to3 apply this patch. So it was a combination of laziness and not wanting to tackle too much in a single commit. Jeremy
Also fix the "#!" lines in the test framework files to use whatever runtime is found (the pactest main will bail if it is too old). Signed-off-by: Jeremy Heiner <ScalaProtractor at gmail.com> --- configure.ac | 2 +- test/pacman/pactest.py | 2 +- test/pacman/pmdb.py | 3 +-- test/pacman/pmenv.py | 3 +-- test/pacman/pmfile.py | 3 +-- test/pacman/pmpkg.py | 3 +-- test/pacman/pmrule.py | 3 +-- test/pacman/pmtest.py | 3 +-- test/pacman/util.py | 3 +-- 9 files changed, 9 insertions(+), 16 deletions(-) diff --git a/configure.ac b/configure.ac index cfcc8d1..93f04bc 100644 --- a/configure.ac +++ b/configure.ac @@ -169,7 +169,7 @@ AC_SYS_LARGEFILE AC_PROG_AWK AC_PROG_CC_C99 AC_PROG_INSTALL -AC_CHECK_PROGS([PYTHON], [python2.7 python2 python], [false]) +AC_CHECK_PROGS([PYTHON], [python3 python2.7 python2 python], [false]) AC_PATH_PROGS([BASH_SHELL], [bash bash4], [false]) # check for perl 5.10.1 (needed by makepkg-template) diff --git a/test/pacman/pactest.py b/test/pacman/pactest.py index e21cde7..1e46803 100755 --- a/test/pacman/pactest.py +++ b/test/pacman/pactest.py @@ -1,4 +1,4 @@ -#! /usr/bin/python2 +#! /usr/bin/python # # pactest : run automated testing on the pacman binary # diff --git a/test/pacman/pmdb.py b/test/pacman/pmdb.py index b4de281..a45a1d5 100644 --- a/test/pacman/pmdb.py +++ b/test/pacman/pmdb.py @@ -1,5 +1,4 @@ -#! /usr/bin/python2 -# + # Copyright (c) 2006 by Aurelien Foret <orelien@chez.com> # Copyright (c) 2006-2013 Pacman Development Team <pacman-dev@archlinux.org> # diff --git a/test/pacman/pmenv.py b/test/pacman/pmenv.py index f358285..930e61a 100644 --- a/test/pacman/pmenv.py +++ b/test/pacman/pmenv.py @@ -1,5 +1,4 @@ -#! /usr/bin/python2 -# + # Copyright (c) 2006 by Aurelien Foret <orelien@chez.com> # Copyright (c) 2006-2013 Pacman Developmet Team <pacman-dev@archlinux.org> # diff --git a/test/pacman/pmfile.py b/test/pacman/pmfile.py index 49c0274..ae4a3ec 100644 --- a/test/pacman/pmfile.py +++ b/test/pacman/pmfile.py @@ -1,5 +1,4 @@ -#! /usr/bin/python2 -# + # Copyright (c) 2006 by Aurelien Foret <orelien@chez.com> # Copyright (c) 2006-2013 Pacman Development Team <pacman-dev@archlinux.org> # diff --git a/test/pacman/pmpkg.py b/test/pacman/pmpkg.py index 5a5e78e..7b9187b 100644 --- a/test/pacman/pmpkg.py +++ b/test/pacman/pmpkg.py @@ -1,5 +1,4 @@ -#! /usr/bin/python2 -# + # Copyright (c) 2006 by Aurelien Foret <orelien@chez.com> # Copyright (c) 2006-2013 Pacman Development Team <pacman-dev@archlinux.org> # diff --git a/test/pacman/pmrule.py b/test/pacman/pmrule.py index c97a158..0ebe877 100644 --- a/test/pacman/pmrule.py +++ b/test/pacman/pmrule.py @@ -1,5 +1,4 @@ -#! /usr/bin/python2 -# + # Copyright (c) 2006 by Aurelien Foret <orelien@chez.com> # Copyright (c) 2006-2013 Pacman Development Team <pacman-dev@archlinux.org> # diff --git a/test/pacman/pmtest.py b/test/pacman/pmtest.py index a1f3645d..dfd6159 100644 --- a/test/pacman/pmtest.py +++ b/test/pacman/pmtest.py @@ -1,5 +1,4 @@ -#! /usr/bin/python2 -# + # Copyright (c) 2006 by Aurelien Foret <orelien@chez.com> # Copyright (c) 2006-2013 Pacman Development Team <pacman-dev@archlinux.org> # diff --git a/test/pacman/util.py b/test/pacman/util.py index 4d5ba8a..f573c4d 100644 --- a/test/pacman/util.py +++ b/test/pacman/util.py @@ -1,5 +1,4 @@ -#! /usr/bin/python2 -# + # Copyright (c) 2006 by Aurelien Foret <orelien@chez.com> # Copyright (c) 2006-2013 Pacman Development Team <pacman-dev@archlinux.org> # -- 1.8.4
participants (5)
-
Allan McRae
-
Andrew Gregory
-
Jeremy Heiner
-
Martin Panter
-
William Giokas