Skip to content

Commit

Permalink
Print when test is skipped
Browse files Browse the repository at this point in the history
  • Loading branch information
smira committed Jul 10, 2019
1 parent 3b8c067 commit 6217c77
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 20 deletions.
42 changes: 27 additions & 15 deletions system/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def translate_path(self, path):
words = filter(None, words)
path = self.rootPath
for word in words:
drive, word = os.path.splitdrive(word)
head, word = os.path.split(word)
_, word = os.path.splitdrive(word)
_, word = os.path.split(word)
if word in (os.curdir, os.pardir):
continue
path = os.path.join(path, word)
Expand Down Expand Up @@ -138,7 +138,8 @@ def prepare_remove_all(self):
if os.path.exists(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")):
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):
cfg = self.configFile.copy()
Expand Down Expand Up @@ -168,18 +169,21 @@ def fixture_available(self):
def prepare_fixture(self):
if self.fixturePool:
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:
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:
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:
self.webServerUrl = self.start_webserver(os.path.join(os.path.dirname(inspect.getsourcefile(self.__class__)),
self.fixtureWebServer))
self.fixtureWebServer))

if self.requiresGPG2:
self.run_cmd([
Expand All @@ -195,7 +199,8 @@ def prepare_fixture(self):
self.run_cmd(cmd)

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):
if not hasattr(command, "__iter__"):
Expand Down Expand Up @@ -223,10 +228,12 @@ def run_cmd(self, command, expected_code=0):
output, _ = proc.communicate()
if expected_code is not None:
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
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):
return gold
Expand All @@ -245,7 +252,8 @@ def get_gold(self, gold_name="gold"):

def check_output(self):
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
if self.captureResults:
if self.outputMatchPrepare is not None:
Expand Down Expand Up @@ -279,7 +287,8 @@ def check_file_contents(self, path, gold_name, match_prepare=None):
contents = self.read_file(path)
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
if self.captureResults:
if match_prepare is not None:
Expand Down Expand Up @@ -334,7 +343,8 @@ def check_subset(self, a, b):
if k not in b:
diff += "unexpected key '%s'\n" % (k,)
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:
raise Exception("content doesn't match:\n" + diff)

Expand All @@ -344,7 +354,8 @@ def verify_match(self, a, b, match_prepare=None):
b = match_prepare(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")

Expand All @@ -357,7 +368,8 @@ def prepare(self):

def start_webserver(self, 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.daemon = True
Expand Down
15 changes: 10 additions & 5 deletions system/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,17 @@ 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():
numSkipped += 1
sys.stdout.write(colored("SKIP\n", color="yellow"))
continue

numTests += 1

sys.stdout.write("%s:%s... " % (test, o.__name__))

try:
t.captureResults = capture_results
t.test()
Expand All @@ -93,14 +95,16 @@ 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), )

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

Expand All @@ -110,7 +114,8 @@ 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()
os.environ['APTLY_VERSION'] = os.popen(
"make version").read().strip()
except BaseException, e:
print "Failed to capture current version: ", e

Expand Down

0 comments on commit 6217c77

Please sign in to comment.