mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-08 05:50:47 +00:00
Add support for pool/db fixtures, outuput match prepare.
This commit is contained in:
+31
-5
@@ -17,6 +17,9 @@ class BaseTest(object):
|
||||
"""
|
||||
|
||||
longTest = False
|
||||
fixturePool = False
|
||||
fixtureDB = False
|
||||
|
||||
expectedCode = 0
|
||||
configFile = {
|
||||
"rootDir": "%s/.aptly" % os.environ["HOME"],
|
||||
@@ -28,6 +31,11 @@ class BaseTest(object):
|
||||
}
|
||||
configOverride = {}
|
||||
|
||||
fixtureDBDir = os.path.join(os.environ["HOME"], "aptly-fixture-db")
|
||||
fixturePoolDir = os.path.join(os.environ["HOME"], "aptly-fixture-pool")
|
||||
|
||||
outputMatchPrepare = None
|
||||
|
||||
def test(self):
|
||||
self.prepare()
|
||||
self.run()
|
||||
@@ -46,7 +54,22 @@ class BaseTest(object):
|
||||
f.write(json.dumps(cfg))
|
||||
f.close()
|
||||
|
||||
def fixture_available(self):
|
||||
if self.fixturePool and not os.path.exists(self.fixturePoolDir):
|
||||
return False
|
||||
if self.fixtureDB and not os.path.exists(self.fixtureDBDir):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
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"))
|
||||
|
||||
if self.fixtureDB:
|
||||
shutil.copytree(self.fixtureDBDir, os.path.join(os.environ["HOME"], ".aptly", "db"))
|
||||
|
||||
if hasattr(self, "fixtureCmds"):
|
||||
for cmd in self.fixtureCmds:
|
||||
self.run_cmd(cmd)
|
||||
@@ -78,12 +101,16 @@ class BaseTest(object):
|
||||
return self.gold_processor(open(gold, "r").read())
|
||||
|
||||
def check_output(self):
|
||||
self.verify_match(self.get_gold(), self.output)
|
||||
self.verify_match(self.get_gold(), self.output, match_prepare=self.outputMatchPrepare)
|
||||
|
||||
def check_cmd_output(self, command, gold_name):
|
||||
self.verify_match(self.get_gold(gold_name), self.run_cmd(command))
|
||||
def check_cmd_output(self, command, gold_name, match_prepare=None):
|
||||
self.verify_match(self.get_gold(gold_name), self.run_cmd(command), match_prepare)
|
||||
|
||||
def verify_match(self, a, b, match_prepare=None):
|
||||
if match_prepare is not None:
|
||||
a = match_prepare(a)
|
||||
b = match_prepare(b)
|
||||
|
||||
def verify_match(self, 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")]))
|
||||
|
||||
@@ -98,4 +125,3 @@ class BaseTest(object):
|
||||
self.prepare_remove_all()
|
||||
self.prepare_default_config()
|
||||
self.prepare_fixture()
|
||||
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ def run(include_long_tests=False):
|
||||
continue
|
||||
|
||||
t = o()
|
||||
if t.longTest and not include_long_tests:
|
||||
if t.longTest and not include_long_tests or not t.fixture_available():
|
||||
numSkipped += 1
|
||||
continue
|
||||
|
||||
|
||||
Reference in New Issue
Block a user