mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-16 07:10:54 +00:00
New upstream version 1.5.0+ds1
This commit is contained in:
+45
-14
@@ -5,9 +5,11 @@ import importlib
|
||||
import os
|
||||
import inspect
|
||||
import fnmatch
|
||||
import re
|
||||
import sys
|
||||
import traceback
|
||||
import random
|
||||
import subprocess
|
||||
|
||||
from lib import BaseTest
|
||||
from s3_lib import S3Test
|
||||
@@ -22,9 +24,17 @@ except ImportError:
|
||||
return s
|
||||
|
||||
|
||||
PYTHON_MINIMUM_VERSION = (3, 9)
|
||||
|
||||
|
||||
def natural_key(string_):
|
||||
"""See https://blog.codinghorror.com/sorting-for-humans-natural-sort-order/"""
|
||||
return [int(s) if s.isdigit() else s for s in re.split(r'(\d+)', string_)]
|
||||
|
||||
|
||||
def walk_modules(package):
|
||||
yield importlib.import_module(package)
|
||||
for name in glob.glob(package + "/*.py"):
|
||||
for name in sorted(glob.glob(package + "/*.py"), key=natural_key):
|
||||
name = os.path.splitext(os.path.basename(name))[0]
|
||||
if name == "__init__":
|
||||
continue
|
||||
@@ -37,14 +47,14 @@ def run(include_long_tests=False, capture_results=False, tests=None, filters=Non
|
||||
Run system test.
|
||||
"""
|
||||
if not tests:
|
||||
tests = glob.glob("t*_*")
|
||||
tests = sorted(glob.glob("t*_*"), key=natural_key)
|
||||
fails = []
|
||||
numTests = numFailed = numSkipped = 0
|
||||
lastBase = None
|
||||
|
||||
for test in tests:
|
||||
for testModule in walk_modules(test):
|
||||
for name in dir(testModule):
|
||||
for name in sorted(dir(testModule), key=natural_key):
|
||||
o = getattr(testModule, name)
|
||||
|
||||
if not (inspect.isclass(o) and issubclass(o, BaseTest) and o is not BaseTest and
|
||||
@@ -68,22 +78,29 @@ def run(include_long_tests=False, capture_results=False, tests=None, filters=Non
|
||||
if not matches:
|
||||
continue
|
||||
|
||||
sys.stdout.write("%s:%s... " % (test, o.__name__))
|
||||
sys.stdout.flush()
|
||||
|
||||
t = o()
|
||||
if t.longTest and not include_long_tests or not t.fixture_available():
|
||||
if t.longTest and not include_long_tests or not t.fixture_available() or t.skipTest:
|
||||
numSkipped += 1
|
||||
msg = 'SKIP'
|
||||
if t.skipTest and t.skipTest is not True:
|
||||
# If we have a reason to skip, print it
|
||||
msg += ': ' + t.skipTest
|
||||
sys.stdout.write(colored(msg + "\n", color="yellow"))
|
||||
continue
|
||||
|
||||
numTests += 1
|
||||
|
||||
sys.stdout.write("%s:%s... " % (test, o.__name__))
|
||||
|
||||
try:
|
||||
t.captureResults = capture_results
|
||||
t.test()
|
||||
except BaseException:
|
||||
except Exception:
|
||||
numFailed += 1
|
||||
typ, val, tb = sys.exc_info()
|
||||
fails.append((test, t, typ, val, tb, testModule))
|
||||
traceback.print_exception(typ, val, tb)
|
||||
sys.stdout.write(colored("FAIL\n", color="red"))
|
||||
else:
|
||||
sys.stdout.write(colored("OK\n", color="green"))
|
||||
@@ -93,16 +110,18 @@ def run(include_long_tests=False, capture_results=False, tests=None, filters=Non
|
||||
if lastBase is not None:
|
||||
lastBase.shutdown_class()
|
||||
|
||||
print "TESTS: %d SUCCESS: %d FAIL: %d SKIP: %d" % (numTests, numTests - numFailed, numFailed, numSkipped)
|
||||
print("TESTS: %d SUCCESS: %d FAIL: %d SKIP: %d" % (
|
||||
numTests, numTests - numFailed, numFailed, numSkipped))
|
||||
|
||||
if len(fails) > 0:
|
||||
print "\nFAILURES (%d):" % (len(fails), )
|
||||
print("\nFAILURES (%d):" % (len(fails), ))
|
||||
|
||||
for (test, t, typ, val, tb, testModule) in fails:
|
||||
doc = t.__doc__ or ''
|
||||
print "%s:%s %s" % (test, t.__class__.__name__, testModule.__name__ + ": " + doc.strip())
|
||||
print("%s:%s %s" % (test, t.__class__.__name__,
|
||||
testModule.__name__ + ": " + doc.strip()))
|
||||
traceback.print_exception(typ, val, tb)
|
||||
print "=" * 60
|
||||
print("=" * 60)
|
||||
|
||||
sys.exit(1)
|
||||
|
||||
@@ -110,9 +129,21 @@ def run(include_long_tests=False, capture_results=False, tests=None, filters=Non
|
||||
if __name__ == "__main__":
|
||||
if 'APTLY_VERSION' not in os.environ:
|
||||
try:
|
||||
os.environ['APTLY_VERSION'] = os.popen("make version").read().strip()
|
||||
except BaseException, e:
|
||||
print "Failed to capture current version: ", e
|
||||
os.environ['APTLY_VERSION'] = os.popen(
|
||||
"make version").read().strip()
|
||||
except BaseException as e:
|
||||
print("Failed to capture current version: ", e)
|
||||
|
||||
if sys.version_info < PYTHON_MINIMUM_VERSION:
|
||||
raise RuntimeError(f'Tests require Python {PYTHON_MINIMUM_VERSION} or higher.')
|
||||
|
||||
output = subprocess.check_output(['gpg1', '--version'], text=True)
|
||||
if not output.startswith('gpg (GnuPG) 1'):
|
||||
raise RuntimeError('Tests require gpg v1')
|
||||
|
||||
output = subprocess.check_output(['gpgv1', '--version'], text=True)
|
||||
if not output.startswith('gpgv (GnuPG) 1'):
|
||||
raise RuntimeError('Tests require gpgv v1')
|
||||
|
||||
os.chdir(os.path.realpath(os.path.dirname(sys.argv[0])))
|
||||
random.seed()
|
||||
|
||||
Reference in New Issue
Block a user