lib/oeqa: add oeTest superclass

Add oeTest superclass, make oeRuntimeTest inherit that and
make the necesarry adjustments. Tests in lib/oeqa/runtime don't
change, they still inherit oeRuntimeTest.
We should do this because oetest.py in the future can be a base module
for more stuff than oeRuntimeTest.

(From OE-Core rev: cd4ed41a070bd52c446ac3df8337f17ab9421145)

Signed-off-by: Stefan Stanacar <stefanx.stanacar@intel.com>
Signed-off-by: Saul Wold <sgw@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Stefan Stanacar
2013-11-01 12:37:56 +02:00
committed by Richard Purdie
parent 90c709da9b
commit 19aeca1cac
2 changed files with 26 additions and 24 deletions

View File

@@ -17,9 +17,9 @@ from oeqa.utils.sshcontrol import SSHControl
def runTests(tc):
# set the context object passed from the test class
setattr(oeRuntimeTest, "tc", tc)
setattr(oeTest, "tc", tc)
# set ps command to use
setattr(oeRuntimeTest, "pscmd", "ps -ef" if oeRuntimeTest.hasPackage("procps") else "ps")
setattr(oeRuntimeTest, "pscmd", "ps -ef" if oeTest.hasPackage("procps") else "ps")
# prepare test suite, loader and runner
suite = unittest.TestSuite()
testloader = unittest.TestLoader()
@@ -36,33 +36,28 @@ def runTests(tc):
class oeRuntimeTest(unittest.TestCase):
class oeTest(unittest.TestCase):
longMessage = True
testFailures = []
testSkipped = []
testErrors = []
def __init__(self, methodName='runTest'):
self.target = oeRuntimeTest.tc.target
super(oeRuntimeTest, self).__init__(methodName)
def run(self, result=None):
super(oeRuntimeTest, self).run(result)
super(oeTest, self).run(result)
# we add to our own lists the results, we use those for decorators
if len(result.failures) > len(oeRuntimeTest.testFailures):
oeRuntimeTest.testFailures.append(str(result.failures[-1][0]).split()[0])
if len(result.skipped) > len(oeRuntimeTest.testSkipped):
oeRuntimeTest.testSkipped.append(str(result.skipped[-1][0]).split()[0])
if len(result.errors) > len(oeRuntimeTest.testErrors):
oeRuntimeTest.testErrors.append(str(result.errors[-1][0]).split()[0])
if len(result.failures) > len(oeTest.testFailures):
oeTest.testFailures.append(str(result.failures[-1][0]).split()[0])
if len(result.skipped) > len(oeTest.testSkipped):
oeTest.testSkipped.append(str(result.skipped[-1][0]).split()[0])
if len(result.errors) > len(oeTest.testErrors):
oeTest.testErrors.append(str(result.errors[-1][0]).split()[0])
@classmethod
def hasPackage(self, pkg):
pkgfile = os.path.join(oeRuntimeTest.tc.d.getVar("WORKDIR", True), "installed_pkgs.txt")
pkgfile = os.path.join(oeTest.tc.d.getVar("WORKDIR", True), "installed_pkgs.txt")
with open(pkgfile) as f:
data = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
@@ -77,12 +72,19 @@ class oeRuntimeTest(unittest.TestCase):
@classmethod
def hasFeature(self,feature):
if feature in oeRuntimeTest.tc.d.getVar("IMAGE_FEATURES", True).split() or \
feature in oeRuntimeTest.tc.d.getVar("DISTRO_FEATURES", True).split():
if feature in oeTest.tc.d.getVar("IMAGE_FEATURES", True).split() or \
feature in oeTest.tc.d.getVar("DISTRO_FEATURES", True).split():
return True
else:
return False
class oeRuntimeTest(oeTest):
def __init__(self, methodName='runTest'):
self.target = oeRuntimeTest.tc.target
super(oeRuntimeTest, self).__init__(methodName)
@classmethod
def restartTarget(self,params=None):
@@ -102,7 +104,7 @@ def getmodule(pos=2):
def skipModule(reason, pos=2):
modname = getmodule(pos)
if modname not in oeRuntimeTest.tc.testsrequired:
if modname not in oeTest.tc.testsrequired:
raise unittest.SkipTest("%s: %s" % (modname, reason))
else:
raise Exception("\nTest %s wants to be skipped.\nReason is: %s" \

View File

@@ -15,7 +15,7 @@ class skipIfFailure(object):
def __call__(self,f):
def wrapped_f(*args):
if self.testcase in (oeRuntimeTest.testFailures or oeRuntimeTest.testErrors):
if self.testcase in (oeTest.testFailures or oeTest.testErrors):
raise unittest.SkipTest("Testcase dependency not met: %s" % self.testcase)
return f(*args)
wrapped_f.__name__ = f.__name__
@@ -28,7 +28,7 @@ class skipIfSkipped(object):
def __call__(self,f):
def wrapped_f(*args):
if self.testcase in oeRuntimeTest.testSkipped:
if self.testcase in oeTest.testSkipped:
raise unittest.SkipTest("Testcase dependency not met: %s" % self.testcase)
return f(*args)
wrapped_f.__name__ = f.__name__
@@ -41,9 +41,9 @@ class skipUnlessPassed(object):
def __call__(self,f):
def wrapped_f(*args):
if self.testcase in oeRuntimeTest.testSkipped or \
self.testcase in oeRuntimeTest.testFailures or \
self.testcase in oeRuntimeTest.testErrors:
if self.testcase in oeTest.testSkipped or \
self.testcase in oeTest.testFailures or \
self.testcase in oeTest.testErrors:
raise unittest.SkipTest("Testcase dependency not met: %s" % self.testcase)
return f(*args)
wrapped_f.__name__ = f.__name__