Make tests compatible with Python 3
This commit is contained in:
parent
346ec2e8e4
commit
b89e619851
|
|
@ -5,6 +5,11 @@ ostree (2018.1-1) UNRELEASED; urgency=medium
|
||||||
- d/patches: Remove, applied upstream
|
- d/patches: Remove, applied upstream
|
||||||
- d/libostree-1-1.symbols: Update
|
- d/libostree-1-1.symbols: Update
|
||||||
* Move Vcs-* to salsa.debian.org
|
* Move Vcs-* to salsa.debian.org
|
||||||
|
d/p/test-concurrency-Explicitly-use-floor-division.patch,
|
||||||
|
d/p/tests-bootloader-entries-crosscheck-Use-Python-3-friendly.patch:
|
||||||
|
Make tests compatible with Python 3
|
||||||
|
* d/control, d/p/debian/Use-Python-3-for-tests.patch:
|
||||||
|
Switch build-time tests and autopkgtests to Python 3
|
||||||
|
|
||||||
-- Simon McVittie <smcv@debian.org> Mon, 15 Jan 2018 01:19:14 +0000
|
-- Simon McVittie <smcv@debian.org> Mon, 15 Jan 2018 01:19:14 +0000
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
test-concurrency-Use-Python-3-syntax-for-octal.patch
|
||||||
|
test-concurrency-Replace-range-with-xrange.patch
|
||||||
|
test-concurrency-Explicitly-use-floor-division.patch
|
||||||
|
tests-bootloader-entries-crosscheck-Use-Python-3-friendly.patch
|
||||||
|
|
@ -0,0 +1,51 @@
|
||||||
|
From: Simon McVittie <smcv@debian.org>
|
||||||
|
Date: Wed, 17 Jan 2018 15:03:59 +0000
|
||||||
|
Subject: test-concurrency: Explicitly use floor division
|
||||||
|
|
||||||
|
Python 3 is pickier about this. Python 2.7 has Python 3-compatible
|
||||||
|
semantics for division when the division feature is imported from the
|
||||||
|
future.
|
||||||
|
|
||||||
|
Signed-off-by: Simon McVittie <smcv@debian.org>
|
||||||
|
---
|
||||||
|
tests/test-concurrency.py | 9 +++++----
|
||||||
|
1 file changed, 5 insertions(+), 4 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/tests/test-concurrency.py b/tests/test-concurrency.py
|
||||||
|
index f16f696..3a0ce10 100755
|
||||||
|
--- a/tests/test-concurrency.py
|
||||||
|
+++ b/tests/test-concurrency.py
|
||||||
|
@@ -17,6 +17,7 @@
|
||||||
|
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||||
|
# Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
+from __future__ import division
|
||||||
|
from __future__ import print_function
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
@@ -78,12 +79,12 @@ def run(n_committers, n_pruners):
|
||||||
|
pruners = set()
|
||||||
|
|
||||||
|
print('n_committers', n_committers, 'n_pruners', n_pruners, file=sys.stderr)
|
||||||
|
- n_trees = n_committers / 2
|
||||||
|
+ n_trees = n_committers // 2
|
||||||
|
for v in range(n_trees):
|
||||||
|
mktree('tree{}'.format(v))
|
||||||
|
|
||||||
|
for v in range(n_committers):
|
||||||
|
- committers.add(commit(v / 2))
|
||||||
|
+ committers.add(commit(v // 2))
|
||||||
|
for v in range(n_pruners):
|
||||||
|
pruners.add(prune())
|
||||||
|
|
||||||
|
@@ -101,8 +102,8 @@ def run(n_committers, n_pruners):
|
||||||
|
shutil.rmtree('tree{}'.format(v))
|
||||||
|
|
||||||
|
# No concurrent pruning
|
||||||
|
-run(cpu_count()/2 + 2, 0)
|
||||||
|
+run(cpu_count() // 2 + 2, 0)
|
||||||
|
print("ok no concurrent prunes")
|
||||||
|
|
||||||
|
-run(cpu_count()/2 + 4, 3)
|
||||||
|
+run(cpu_count() // 2 + 4, 3)
|
||||||
|
print("ok concurrent prunes")
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
From: Simon McVittie <smcv@debian.org>
|
||||||
|
Date: Wed, 17 Jan 2018 14:42:20 +0000
|
||||||
|
Subject: test-concurrency: Replace range with xrange
|
||||||
|
|
||||||
|
range in Python 3 does what xrange did in Python 2. This still works in
|
||||||
|
Python 2, it just uses a bit more memory.
|
||||||
|
|
||||||
|
Signed-off-by: Simon McVittie <smcv@debian.org>
|
||||||
|
---
|
||||||
|
tests/test-concurrency.py | 10 +++++-----
|
||||||
|
1 file changed, 5 insertions(+), 5 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/tests/test-concurrency.py b/tests/test-concurrency.py
|
||||||
|
index 6fade24..f16f696 100755
|
||||||
|
--- a/tests/test-concurrency.py
|
||||||
|
+++ b/tests/test-concurrency.py
|
||||||
|
@@ -34,7 +34,7 @@ def fatal(msg):
|
||||||
|
def mktree(dname, serial=0):
|
||||||
|
print('Creating tree', dname, file=sys.stderr)
|
||||||
|
os.mkdir(dname, 0o755)
|
||||||
|
- for v in xrange(20):
|
||||||
|
+ for v in range(20):
|
||||||
|
with open('{}/{}'.format(dname, v), 'w') as f:
|
||||||
|
f.write('{} {} {}\n'.format(dname, serial, v))
|
||||||
|
|
||||||
|
@@ -79,12 +79,12 @@ def run(n_committers, n_pruners):
|
||||||
|
|
||||||
|
print('n_committers', n_committers, 'n_pruners', n_pruners, file=sys.stderr)
|
||||||
|
n_trees = n_committers / 2
|
||||||
|
- for v in xrange(n_trees):
|
||||||
|
+ for v in range(n_trees):
|
||||||
|
mktree('tree{}'.format(v))
|
||||||
|
|
||||||
|
- for v in xrange(n_committers):
|
||||||
|
+ for v in range(n_committers):
|
||||||
|
committers.add(commit(v / 2))
|
||||||
|
- for v in xrange(n_pruners):
|
||||||
|
+ for v in range(n_pruners):
|
||||||
|
pruners.add(prune())
|
||||||
|
|
||||||
|
failed = False
|
||||||
|
@@ -97,7 +97,7 @@ def run(n_committers, n_pruners):
|
||||||
|
if failed:
|
||||||
|
fatal('A child process exited abnormally')
|
||||||
|
|
||||||
|
- for v in xrange(n_trees):
|
||||||
|
+ for v in range(n_trees):
|
||||||
|
shutil.rmtree('tree{}'.format(v))
|
||||||
|
|
||||||
|
# No concurrent pruning
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
From: Simon McVittie <smcv@debian.org>
|
||||||
|
Date: Wed, 17 Jan 2018 14:25:26 +0000
|
||||||
|
Subject: test-concurrency: Use Python 3 syntax for octal
|
||||||
|
|
||||||
|
This also works in Python 2.7, and is a little clearer.
|
||||||
|
|
||||||
|
Signed-off-by: Simon McVittie <smcv@debian.org>
|
||||||
|
---
|
||||||
|
tests/test-concurrency.py | 2 +-
|
||||||
|
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||||
|
|
||||||
|
diff --git a/tests/test-concurrency.py b/tests/test-concurrency.py
|
||||||
|
index bdcc1d9..6fade24 100755
|
||||||
|
--- a/tests/test-concurrency.py
|
||||||
|
+++ b/tests/test-concurrency.py
|
||||||
|
@@ -33,7 +33,7 @@ def fatal(msg):
|
||||||
|
# different files with different checksums.
|
||||||
|
def mktree(dname, serial=0):
|
||||||
|
print('Creating tree', dname, file=sys.stderr)
|
||||||
|
- os.mkdir(dname, 0755)
|
||||||
|
+ os.mkdir(dname, 0o755)
|
||||||
|
for v in xrange(20):
|
||||||
|
with open('{}/{}'.format(dname, v), 'w') as f:
|
||||||
|
f.write('{} {} {}\n'.format(dname, serial, v))
|
||||||
36
debian/patches/tests-bootloader-entries-crosscheck-Use-Python-3-friendly.patch
vendored
Normal file
36
debian/patches/tests-bootloader-entries-crosscheck-Use-Python-3-friendly.patch
vendored
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
From: Simon McVittie <smcv@debian.org>
|
||||||
|
Date: Wed, 17 Jan 2018 15:19:12 +0000
|
||||||
|
Subject: tests/bootloader-entries-crosscheck: Use Python 3-friendly sorting
|
||||||
|
|
||||||
|
This is a little clearer than a strcmp()-style negative/zero/positive
|
||||||
|
return, and also works in Python 2.
|
||||||
|
|
||||||
|
Signed-off-by: Simon McVittie <smcv@debian.org>
|
||||||
|
---
|
||||||
|
tests/bootloader-entries-crosscheck.py | 6 +++---
|
||||||
|
1 file changed, 3 insertions(+), 3 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/tests/bootloader-entries-crosscheck.py b/tests/bootloader-entries-crosscheck.py
|
||||||
|
index 38e8e45..5faa548 100755
|
||||||
|
--- a/tests/bootloader-entries-crosscheck.py
|
||||||
|
+++ b/tests/bootloader-entries-crosscheck.py
|
||||||
|
@@ -38,8 +38,8 @@ def fatal(msg):
|
||||||
|
sys.stderr.write('\n')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
-def compare_entries_descending(a, b):
|
||||||
|
- return int(b['version']) - int(a['version'])
|
||||||
|
+def entry_get_version(entry):
|
||||||
|
+ return int(entry['version'])
|
||||||
|
|
||||||
|
def get_ostree_option(optionstring):
|
||||||
|
for o in optionstring.split():
|
||||||
|
@@ -65,7 +65,7 @@ for fname in os.listdir(loaderpath):
|
||||||
|
v = line[s+1:]
|
||||||
|
entry[k] = v
|
||||||
|
entries.append(entry)
|
||||||
|
- entries.sort(compare_entries_descending)
|
||||||
|
+ entries.sort(key=entry_get_version, reverse=True)
|
||||||
|
|
||||||
|
# Parse SYSLINUX config
|
||||||
|
with open(syslinuxpath) as f:
|
||||||
Loading…
Reference in New Issue