pactest: pass entire test to rule.check()

We were piecemeal passing fields from the test object in and it was getting
out of hand, and future work would have added yet another argument. Instead,
just pass the entire test object and entrust the rule to get what it needs.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2011-01-29 11:23:55 -06:00
parent ef86da97f5
commit ce089e1b97
2 changed files with 12 additions and 12 deletions

View File

@ -34,17 +34,16 @@ def __str__(self):
return self.rule return self.rule
return self.rule[:37] + '...' return self.rule[:37] + '...'
def check(self, root, retcode, localdb, files): def check(self, test):
""" """
""" """
success = 1 success = 1
[test, args] = self.rule.split("=") [testname, args] = self.rule.split("=")
if test[0] == "!": if testname[0] == "!":
self.false = 1 self.false = 1
test = test.lstrip("!") testname = testname.lstrip("!")
[kind, case] = test.split("_") [kind, case] = testname.split("_")
if "|" in args: if "|" in args:
[key, value] = args.split("|", 1) [key, value] = args.split("|", 1)
else: else:
@ -52,19 +51,20 @@ def check(self, root, retcode, localdb, files):
if kind == "PACMAN": if kind == "PACMAN":
if case == "RETCODE": if case == "RETCODE":
if retcode != int(key): if test.retcode != int(key):
success = 0 success = 0
elif case == "OUTPUT": elif case == "OUTPUT":
logfile = os.path.join(root, util.LOGFILE) logfile = os.path.join(test.root, util.LOGFILE)
if not os.access(logfile, os.F_OK): if not os.access(logfile, os.F_OK):
print "LOGFILE not found, cannot validate 'OUTPUT' rule" print "LOGFILE not found, cannot validate 'OUTPUT' rule"
success = 0 success = 0
elif not util.grep(os.path.join(root, util.LOGFILE), key): elif not util.grep(logfile, key):
success = 0 success = 0
else: else:
print "PACMAN rule '%s' not found" % case print "PACMAN rule '%s' not found" % case
success = -1 success = -1
elif kind == "PKG": elif kind == "PKG":
localdb = test.db["local"]
newpkg = localdb.db_read(key) newpkg = localdb.db_read(key)
if not newpkg: if not newpkg:
success = 0 success = 0
@ -107,12 +107,12 @@ def check(self, root, retcode, localdb, files):
print "PKG rule '%s' not found" % case print "PKG rule '%s' not found" % case
success = -1 success = -1
elif kind == "FILE": elif kind == "FILE":
filename = os.path.join(root, key) filename = os.path.join(test.root, key)
if case == "EXIST": if case == "EXIST":
if not os.path.isfile(filename): if not os.path.isfile(filename):
success = 0 success = 0
elif case == "MODIFIED": elif case == "MODIFIED":
for f in files: for f in test.files:
if f.name == key: if f.name == key:
if not f.ismodified(): if not f.ismodified():
success = 0 success = 0

View File

@ -263,7 +263,7 @@ def check(self):
print "==> Checking rules" print "==> Checking rules"
for i in self.rules: for i in self.rules:
success = i.check(self.root, self.retcode, self.db["local"], self.files) success = i.check(self)
if success == 1: if success == 1:
msg = " OK " msg = " OK "
self.result["success"] += 1 self.result["success"] += 1