mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-07-26 13:47:40 +00:00
Add --capture to auto-create 'gold' results when fail.
This commit is contained in:
+14
-3
@@ -84,6 +84,8 @@ class BaseTest(object):
|
|||||||
|
|
||||||
outputMatchPrepare = None
|
outputMatchPrepare = None
|
||||||
|
|
||||||
|
captureResults = False
|
||||||
|
|
||||||
def test(self):
|
def test(self):
|
||||||
self.prepare()
|
self.prepare()
|
||||||
self.run()
|
self.run()
|
||||||
@@ -181,12 +183,21 @@ class BaseTest(object):
|
|||||||
def expand_environ(self, gold):
|
def expand_environ(self, gold):
|
||||||
return string.Template(gold).substitute(os.environ)
|
return string.Template(gold).substitute(os.environ)
|
||||||
|
|
||||||
|
def get_gold_filename(self, gold_name="gold"):
|
||||||
|
return os.path.join(os.path.dirname(inspect.getsourcefile(self.__class__)), self.__class__.__name__ + "_" + gold_name)
|
||||||
|
|
||||||
def get_gold(self, gold_name="gold"):
|
def get_gold(self, gold_name="gold"):
|
||||||
gold = os.path.join(os.path.dirname(inspect.getsourcefile(self.__class__)), self.__class__.__name__ + "_" + gold_name)
|
return self.gold_processor(open(self.get_gold_filename(gold_name), "r").read())
|
||||||
return self.gold_processor(open(gold, "r").read())
|
|
||||||
|
|
||||||
def check_output(self):
|
def check_output(self):
|
||||||
self.verify_match(self.get_gold(), self.output, match_prepare=self.outputMatchPrepare)
|
try:
|
||||||
|
self.verify_match(self.get_gold(), self.output, match_prepare=self.outputMatchPrepare)
|
||||||
|
except:
|
||||||
|
if self.captureResults:
|
||||||
|
with open(self.get_gold_filename(), "w") as f:
|
||||||
|
f.write(self.output)
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
|
||||||
def check_cmd_output(self, command, gold_name, match_prepare=None, expected_code=0):
|
def check_cmd_output(self, command, gold_name, match_prepare=None, expected_code=0):
|
||||||
self.verify_match(self.get_gold(gold_name), self.run_cmd(command, expected_code=expected_code), match_prepare)
|
self.verify_match(self.get_gold(gold_name), self.run_cmd(command, expected_code=expected_code), match_prepare)
|
||||||
|
|||||||
+11
-4
@@ -16,7 +16,7 @@ except ImportError:
|
|||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
def run(include_long_tests=False, tests=None, filters=None):
|
def run(include_long_tests=False, capture_results=False, tests=None, filters=None):
|
||||||
"""
|
"""
|
||||||
Run system test.
|
Run system test.
|
||||||
"""
|
"""
|
||||||
@@ -56,6 +56,7 @@ def run(include_long_tests=False, tests=None, filters=None):
|
|||||||
sys.stdout.write("%s:%s... " % (test, o.__name__))
|
sys.stdout.write("%s:%s... " % (test, o.__name__))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
t.captureResults = capture_results
|
||||||
t.test()
|
t.test()
|
||||||
except BaseException, e:
|
except BaseException, e:
|
||||||
numFailed += 1
|
numFailed += 1
|
||||||
@@ -81,10 +82,16 @@ def run(include_long_tests=False, tests=None, filters=None):
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
os.chdir(os.path.realpath(os.path.dirname(sys.argv[0])))
|
os.chdir(os.path.realpath(os.path.dirname(sys.argv[0])))
|
||||||
include_long_tests = False
|
include_long_tests = False
|
||||||
|
capture_results = False
|
||||||
tests = None
|
tests = None
|
||||||
args = sys.argv[1:]
|
args = sys.argv[1:]
|
||||||
if len(args) > 0 and args[0] == "--long":
|
|
||||||
include_long_tests = True
|
while len(args) > 0 and args[0].startswith("--"):
|
||||||
|
if args[0] == "--long":
|
||||||
|
include_long_tests = True
|
||||||
|
elif args[0] == "--capture":
|
||||||
|
capture_results = True
|
||||||
|
|
||||||
args = args[1:]
|
args = args[1:]
|
||||||
|
|
||||||
tests = []
|
tests = []
|
||||||
@@ -96,4 +103,4 @@ if __name__ == "__main__":
|
|||||||
else:
|
else:
|
||||||
filters.append(arg)
|
filters.append(arg)
|
||||||
|
|
||||||
run(include_long_tests, tests, filters)
|
run(include_long_tests, capture_results, tests, filters)
|
||||||
|
|||||||
Reference in New Issue
Block a user