Print when test is skipped

This commit is contained in:
Andrey Smirnov
2019-07-10 21:12:41 +03:00
committed by Andrey Smirnov
parent bb1def2910
commit ca5b7758ce
3 changed files with 38 additions and 20 deletions
+27 -15
View File
@@ -39,8 +39,8 @@ class FileHTTPServerRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
words = filter(None, words) words = filter(None, words)
path = self.rootPath path = self.rootPath
for word in words: for word in words:
drive, word = os.path.splitdrive(word) _, word = os.path.splitdrive(word)
head, word = os.path.split(word) _, word = os.path.split(word)
if word in (os.curdir, os.pardir): if word in (os.curdir, os.pardir):
continue continue
path = os.path.join(path, word) path = os.path.join(path, word)
@@ -138,7 +138,8 @@ class BaseTest(object):
if os.path.exists(os.path.join(os.environ["HOME"], ".aptly.conf")): if os.path.exists(os.path.join(os.environ["HOME"], ".aptly.conf")):
os.remove(os.path.join(os.environ["HOME"], ".aptly.conf")) os.remove(os.path.join(os.environ["HOME"], ".aptly.conf"))
if os.path.exists(os.path.join(os.environ["HOME"], ".gnupg", "aptlytest.gpg")): if os.path.exists(os.path.join(os.environ["HOME"], ".gnupg", "aptlytest.gpg")):
os.remove(os.path.join(os.environ["HOME"], ".gnupg", "aptlytest.gpg")) os.remove(os.path.join(
os.environ["HOME"], ".gnupg", "aptlytest.gpg"))
def prepare_default_config(self): def prepare_default_config(self):
cfg = self.configFile.copy() cfg = self.configFile.copy()
@@ -168,18 +169,21 @@ class BaseTest(object):
def prepare_fixture(self): def prepare_fixture(self):
if self.fixturePool: if self.fixturePool:
os.makedirs(os.path.join(os.environ["HOME"], ".aptly"), 0755) os.makedirs(os.path.join(os.environ["HOME"], ".aptly"), 0755)
os.symlink(self.fixturePoolDir, os.path.join(os.environ["HOME"], ".aptly", "pool")) os.symlink(self.fixturePoolDir, os.path.join(
os.environ["HOME"], ".aptly", "pool"))
if self.fixturePoolCopy: if self.fixturePoolCopy:
os.makedirs(os.path.join(os.environ["HOME"], ".aptly"), 0755) os.makedirs(os.path.join(os.environ["HOME"], ".aptly"), 0755)
shutil.copytree(self.fixturePoolDir, os.path.join(os.environ["HOME"], ".aptly", "pool"), ignore=shutil.ignore_patterns(".git")) shutil.copytree(self.fixturePoolDir, os.path.join(
os.environ["HOME"], ".aptly", "pool"), ignore=shutil.ignore_patterns(".git"))
if self.fixtureDB: if self.fixtureDB:
shutil.copytree(self.fixtureDBDir, os.path.join(os.environ["HOME"], ".aptly", "db")) shutil.copytree(self.fixtureDBDir, os.path.join(
os.environ["HOME"], ".aptly", "db"))
if self.fixtureWebServer: if self.fixtureWebServer:
self.webServerUrl = self.start_webserver(os.path.join(os.path.dirname(inspect.getsourcefile(self.__class__)), self.webServerUrl = self.start_webserver(os.path.join(os.path.dirname(inspect.getsourcefile(self.__class__)),
self.fixtureWebServer)) self.fixtureWebServer))
if self.requiresGPG2: if self.requiresGPG2:
self.run_cmd([ self.run_cmd([
@@ -195,7 +199,8 @@ class BaseTest(object):
self.run_cmd(cmd) self.run_cmd(cmd)
def run(self): def run(self):
self.output = self.output_processor(self.run_cmd(self.runCmd, self.expectedCode)) self.output = self.output_processor(
self.run_cmd(self.runCmd, self.expectedCode))
def _start_process(self, command, stderr=subprocess.STDOUT, stdout=None): def _start_process(self, command, stderr=subprocess.STDOUT, stdout=None):
if not hasattr(command, "__iter__"): if not hasattr(command, "__iter__"):
@@ -223,10 +228,12 @@ class BaseTest(object):
output, _ = proc.communicate() output, _ = proc.communicate()
if expected_code is not None: if expected_code is not None:
if proc.returncode != expected_code: if proc.returncode != expected_code:
raise Exception("exit code %d != %d (output: %s)" % (proc.returncode, expected_code, output)) raise Exception("exit code %d != %d (output: %s)" % (
proc.returncode, expected_code, output))
return output return output
except Exception, e: except Exception, e:
raise Exception("Running command %s failed: %s" % (command, str(e))) raise Exception("Running command %s failed: %s" %
(command, str(e)))
def gold_processor(self, gold): def gold_processor(self, gold):
return gold return gold
@@ -245,7 +252,8 @@ class BaseTest(object):
def check_output(self): def check_output(self):
try: try:
self.verify_match(self.get_gold(), self.output, match_prepare=self.outputMatchPrepare) self.verify_match(self.get_gold(), self.output,
match_prepare=self.outputMatchPrepare)
except: # noqa: E722 except: # noqa: E722
if self.captureResults: if self.captureResults:
if self.outputMatchPrepare is not None: if self.outputMatchPrepare is not None:
@@ -279,7 +287,8 @@ class BaseTest(object):
contents = self.read_file(path) contents = self.read_file(path)
try: try:
self.verify_match(self.get_gold(gold_name), contents, match_prepare=match_prepare) self.verify_match(self.get_gold(gold_name),
contents, match_prepare=match_prepare)
except: # noqa: E722 except: # noqa: E722
if self.captureResults: if self.captureResults:
if match_prepare is not None: if match_prepare is not None:
@@ -334,7 +343,8 @@ class BaseTest(object):
if k not in b: if k not in b:
diff += "unexpected key '%s'\n" % (k,) diff += "unexpected key '%s'\n" % (k,)
elif b[k] != v: elif b[k] != v:
diff += "wrong value '%s' for key '%s', expected '%s'\n" % (v, k, b[k]) diff += "wrong value '%s' for key '%s', expected '%s'\n" % (
v, k, b[k])
if diff: if diff:
raise Exception("content doesn't match:\n" + diff) raise Exception("content doesn't match:\n" + diff)
@@ -344,7 +354,8 @@ class BaseTest(object):
b = match_prepare(b) b = match_prepare(b)
if a != b: if a != b:
diff = "".join(difflib.unified_diff([l + "\n" for l in a.split("\n")], [l + "\n" for l in b.split("\n")])) diff = "".join(difflib.unified_diff(
[l + "\n" for l in a.split("\n")], [l + "\n" for l in b.split("\n")]))
raise Exception("content doesn't match:\n" + diff + "\n") raise Exception("content doesn't match:\n" + diff + "\n")
@@ -357,7 +368,8 @@ class BaseTest(object):
def start_webserver(self, directory): def start_webserver(self, directory):
FileHTTPServerRequestHandler.rootPath = directory FileHTTPServerRequestHandler.rootPath = directory
self.webserver = ThreadedTCPServer(("localhost", 0), FileHTTPServerRequestHandler) self.webserver = ThreadedTCPServer(
("localhost", 0), FileHTTPServerRequestHandler)
server_thread = threading.Thread(target=self.webserver.serve_forever) server_thread = threading.Thread(target=self.webserver.serve_forever)
server_thread.daemon = True server_thread.daemon = True
+1
View File
@@ -3,3 +3,4 @@ requests
requests-unixsocket requests-unixsocket
python-swiftclient python-swiftclient
flake8 flake8
termcolor
+10 -5
View File
@@ -68,15 +68,17 @@ def run(include_long_tests=False, capture_results=False, tests=None, filters=Non
if not matches: if not matches:
continue continue
sys.stdout.write("%s:%s... " % (test, o.__name__))
sys.stdout.flush()
t = o() 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():
numSkipped += 1 numSkipped += 1
sys.stdout.write(colored("SKIP\n", color="yellow"))
continue continue
numTests += 1 numTests += 1
sys.stdout.write("%s:%s... " % (test, o.__name__))
try: try:
t.captureResults = capture_results t.captureResults = capture_results
t.test() t.test()
@@ -93,14 +95,16 @@ def run(include_long_tests=False, capture_results=False, tests=None, filters=Non
if lastBase is not None: if lastBase is not None:
lastBase.shutdown_class() 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: if len(fails) > 0:
print "\nFAILURES (%d):" % (len(fails), ) print "\nFAILURES (%d):" % (len(fails), )
for (test, t, typ, val, tb, testModule) in fails: for (test, t, typ, val, tb, testModule) in fails:
doc = t.__doc__ or '' 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) traceback.print_exception(typ, val, tb)
print "=" * 60 print "=" * 60
@@ -110,7 +114,8 @@ def run(include_long_tests=False, capture_results=False, tests=None, filters=Non
if __name__ == "__main__": if __name__ == "__main__":
if 'APTLY_VERSION' not in os.environ: if 'APTLY_VERSION' not in os.environ:
try: try:
os.environ['APTLY_VERSION'] = os.popen("make version").read().strip() os.environ['APTLY_VERSION'] = os.popen(
"make version").read().strip()
except BaseException, e: except BaseException, e:
print "Failed to capture current version: ", e print "Failed to capture current version: ", e