Convert tests to Python 3

Fix #938
This commit is contained in:
Lorenzo Bolla
2022-01-27 11:35:35 +01:00
parent a40cfc679c
commit 035d5314b0
27 changed files with 241 additions and 284 deletions
+9 -19
View File
@@ -2,21 +2,13 @@ import os
import hashlib
import inspect
import re
import zlib
from lib import BaseTest
from lib import BaseTest, ungzip_if_required
def strip_processor(output):
return "\n".join([l for l in output.split("\n") if not l.startswith(' ') and not l.startswith('Date:')])
def ungzip_if_required(output):
if output.startswith("\x1f\x8b"):
return zlib.decompress(output, 16 + zlib.MAX_WBITS)
return output
class PublishRepo1Test(BaseTest):
"""
publish repo: default
@@ -60,9 +52,9 @@ class PublishRepo1Test(BaseTest):
self.check_file_contents('public/dists/maverick/main/binary-i386/Packages',
'binary', match_prepare=lambda s: "\n".join(sorted(s.split("\n"))))
self.check_file_contents('public/dists/maverick/main/Contents-i386.gz',
'contents_i386', match_prepare=ungzip_if_required)
'contents_i386', match_prepare=ungzip_if_required, mode='b', ensure_utf8=False)
self.check_file_contents('public/dists/maverick/Contents-i386.gz',
'contents_i386_legacy', match_prepare=ungzip_if_required)
'contents_i386_legacy', match_prepare=ungzip_if_required, mode='b', ensure_utf8=False)
# verify signatures
self.run_cmd([self.gpgFinder.gpg, "--no-auto-check-trustdb", "--keyring", os.path.join(os.path.dirname(inspect.getsourcefile(BaseTest)), "files", "aptly.pub"),
@@ -101,8 +93,7 @@ class PublishRepo1Test(BaseTest):
else:
h = hashlib.sha512()
h.update(self.read_file(os.path.join(
'public/dists/maverick', path)))
h.update(self.read_file(os.path.join('public/dists/maverick', path), mode='b'))
if h.hexdigest() != fileHash:
raise Exception("file hash doesn't match for %s: %s != %s" % (
@@ -545,8 +536,7 @@ class PublishRepo17Test(BaseTest):
else:
h = hashlib.sha512()
h.update(self.read_file(os.path.join(
'public/dists/maverick', path)))
h.update(self.read_file(os.path.join('public/dists/maverick', path), mode='b'))
if h.hexdigest() != fileHash:
raise Exception("file hash doesn't match for %s: %s != %s" % (
@@ -637,8 +627,8 @@ class PublishRepo23Test(BaseTest):
runCmd = "aptly publish repo -component=main,contrib repo1"
expectedCode = 2
def outputMatchPrepare(_, s):
return "\n".join([l for l in s.split("\n") if l.startswith("ERROR")])
def outputMatchPrepare(self, s):
return "\n".join([l for l in self.ensure_utf8(s).split("\n") if l.startswith("ERROR")])
class PublishRepo24Test(BaseTest):
@@ -832,8 +822,8 @@ class PublishRepo31Test(BaseTest):
gold_processor = BaseTest.expand_environ
configOverride = {"gpgProvider": "internal"}
def outputMatchPrepare(_, s):
return re.sub(r' \d{4}-\d{2}-\d{2}', '', s)
def outputMatchPrepare(self, s):
return re.sub(r' \d{4}-\d{2}-\d{2}', '', self.ensure_utf8(s))
def check(self):
super(PublishRepo31Test, self).check()
+10 -20
View File
@@ -1,8 +1,7 @@
import os
import hashlib
import inspect
import zlib
from lib import BaseTest
from lib import BaseTest, ungzip_if_required
def strip_processor(output):
@@ -13,13 +12,6 @@ def sorted_processor(output):
return "\n".join(sorted(output.split("\n")))
def ungzip_if_required(output):
if output.startswith("\x1f\x8b"):
return zlib.decompress(output, 16 + zlib.MAX_WBITS)
return output
class PublishSnapshot1Test(BaseTest):
"""
publish snapshot: defaults
@@ -75,9 +67,9 @@ class PublishSnapshot1Test(BaseTest):
'packages_amd64', match_prepare=sorted_processor)
self.check_file_contents('public/dists/maverick/main/Contents-i386.gz',
'contents_i386', match_prepare=ungzip_if_required)
'contents_i386', match_prepare=ungzip_if_required, mode='b', ensure_utf8=False)
self.check_file_contents('public/dists/maverick/main/Contents-amd64.gz',
'contents_amd64', match_prepare=ungzip_if_required)
'contents_amd64', match_prepare=ungzip_if_required, mode='b', ensure_utf8=False)
# verify signatures
self.run_cmd([self.gpgFinder.gpg, "--no-auto-check-trustdb", "--keyring", os.path.join(os.path.dirname(inspect.getsourcefile(BaseTest)), "files", "aptly.pub"),
@@ -116,8 +108,7 @@ class PublishSnapshot1Test(BaseTest):
else:
h = hashlib.sha512()
h.update(self.read_file(os.path.join(
'public/dists/maverick', path)))
h.update(self.read_file(os.path.join('public/dists/maverick', path), mode='b'))
if h.hexdigest() != fileHash:
raise Exception("file hash doesn't match for %s: %s != %s" % (
@@ -841,8 +832,7 @@ class PublishSnapshot26Test(BaseTest):
else:
h = hashlib.sha512()
h.update(self.read_file(os.path.join(
'public/dists/maverick', path)))
h.update(self.read_file(os.path.join('public/dists/maverick', path), mode='b'))
if h.hexdigest() != fileHash:
raise Exception("file hash doesn't match for %s: %s != %s" % (
@@ -940,8 +930,8 @@ class PublishSnapshot32Test(BaseTest):
runCmd = "aptly publish snapshot -component=main,contrib snap32.1"
expectedCode = 2
def outputMatchPrepare(_, s):
return "\n".join([l for l in s.split("\n") if l.startswith("ERROR")])
def outputMatchPrepare(self, s):
return "\n".join([l for l in self.ensure_utf8(s).split("\n") if l.startswith("ERROR")])
class PublishSnapshot33Test(BaseTest):
@@ -1093,7 +1083,7 @@ class PublishSnapshot35Test(BaseTest):
else:
h = hashlib.sha512()
h.update(self.read_file(os.path.join('public/dists/stretch', path)))
h.update(self.read_file(os.path.join('public/dists/stretch', path), mode='b'))
if h.hexdigest() != fileHash:
raise Exception("file hash doesn't match for %s: %s != %s" % (
@@ -1217,6 +1207,6 @@ class PublishSnapshot39Test(BaseTest):
'packages_amd64', match_prepare=sorted_processor)
self.check_file_contents('public/dists/maverick/main/Contents-i386.gz',
'contents_i386', match_prepare=ungzip_if_required)
'contents_i386', match_prepare=ungzip_if_required, mode='b', ensure_utf8=False)
self.check_file_contents('public/dists/maverick/main/Contents-amd64.gz',
'contents_amd64', match_prepare=ungzip_if_required)
'contents_amd64', match_prepare=ungzip_if_required, mode='b', ensure_utf8=False)
+5 -5
View File
@@ -82,7 +82,7 @@ class PublishSwitch1Test(BaseTest):
else:
h = hashlib.sha512()
h.update(self.read_file(os.path.join('public/dists/maverick', path)))
h.update(self.read_file(os.path.join('public/dists/maverick', path), mode='b'))
if h.hexdigest() != fileHash:
raise Exception("file hash doesn't match for %s: %s != %s" % (path, fileHash, h.hexdigest()))
@@ -346,7 +346,7 @@ class PublishSwitch8Test(BaseTest):
else:
h = hashlib.sha512()
h.update(self.read_file(os.path.join('public/dists/maverick', path)))
h.update(self.read_file(os.path.join('public/dists/maverick', path), mode='b'))
if h.hexdigest() != fileHash:
raise Exception("file hash doesn't match for %s: %s != %s" % (path, fileHash, h.hexdigest()))
@@ -378,8 +378,8 @@ class PublishSwitch9Test(BaseTest):
runCmd = "aptly publish switch -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec -component=a,b maverick snap2"
expectedCode = 2
def outputMatchPrepare(_, s):
return "\n".join([l for l in s.split("\n") if l.startswith("ERROR")])
def outputMatchPrepare(self, s):
return "\n".join([l for l in self.ensure_utf8(s).split("\n") if l.startswith("ERROR")])
class PublishSwitch10Test(BaseTest):
@@ -535,7 +535,7 @@ class PublishSwitch14Test(BaseTest):
else:
h = hashlib.sha512()
h.update(self.read_file(os.path.join('public/dists/maverick', path)))
h.update(self.read_file(os.path.join('public/dists/maverick', path), mode='b'))
if h.hexdigest() != fileHash:
raise Exception("file hash doesn't match for %s: %s != %s" % (path, fileHash, h.hexdigest()))
+2 -2
View File
@@ -82,7 +82,7 @@ class PublishUpdate1Test(BaseTest):
else:
h = hashlib.sha512()
h.update(self.read_file(os.path.join('public/dists/maverick', path)))
h.update(self.read_file(os.path.join('public/dists/maverick', path), mode='b'))
if h.hexdigest() != fileHash:
raise Exception("file hash doesn't match for %s: %s != %s" % (path, fileHash, h.hexdigest()))
@@ -427,7 +427,7 @@ class PublishUpdate12Test(BaseTest):
else:
h = hashlib.sha512()
h.update(self.read_file(os.path.join('public/dists/maverick', path)))
h.update(self.read_file(os.path.join('public/dists/maverick', path), mode='b'))
if h.hexdigest() != fileHash:
raise Exception("file hash doesn't match for %s: %s != %s" % (path, fileHash, h.hexdigest()))