public inbox for openembedded-core@lists.openembedded.org
 help / color / mirror / Atom feed
From: jwang <jing.j.wang@intel.com>
To: openembedded-core@lists.openembedded.org
Subject: [PATCH 2/4] meta: implement key baserunner features
Date: Tue, 13 Sep 2016 09:17:33 +0800	[thread overview]
Message-ID: <1473729455-32649-2-git-send-email-jing.j.wang@intel.com> (raw)
In-Reply-To: <1473729455-32649-1-git-send-email-jing.j.wang@intel.com>

From: zjh <junhuix.zhang@intel.com>

Baserunner contains three features:
1. load cases from a manifest file
2. load cases from a package such as "oeqa.runtime"
3. create runner engine based on pyunit textrunner

Signed-off-by: zjh <junhuix.zhang@intel.com>
---
 meta/lib/base/baserunner.py | 44 ++++++++++++++++++++++++++++++++++++++------
 1 file changed, 38 insertions(+), 6 deletions(-)

diff --git a/meta/lib/base/baserunner.py b/meta/lib/base/baserunner.py
index 56b838e..d59872f 100755
--- a/meta/lib/base/baserunner.py
+++ b/meta/lib/base/baserunner.py
@@ -31,30 +31,62 @@ class FakeOptions(object):
 class TestRunnerBase(object):
     '''test runner base '''
     def __init__(self, context=None):
-        self.tclist = []
+        self.testslist = []
         self.runner = None
         self.context = context if context else TestContext()
+        self.test_options = None
         self.test_result = None
         self.run_time = None
 
+    def __del__(self):
+        """
+        Because unittest.TestCase is a class object, it will exist as long as the python virtual machine process.
+        So tc can't be released if we don't release them explicitly.
+        """
+        if hasattr(unittest.TestCase, "tc"):
+            delattr(unittest.TestCase, "tc")
+
+    @staticmethod
+    def get_tc_from_manifest(fname):
+        '''get tc list from manifest format '''
+        with open(fname, "r") as f:
+            tclist = [n.strip() for n in f.readlines() \
+                                if n.strip() and not n.strip().startswith('#')]
+        return tclist
 
     def configure(self, options=FakeOptions()):
         '''configure before testing'''
-        pass
+        self.test_options = options
+        self.runner = unittest.TextTestRunner(stream=sys.stderr, \
+                                                  verbosity=2)
 
     def result(self):
         '''output test result '''
-        pass
+        return self.test_result
 
     def loadtest(self, names=None):
         '''load test suite'''
-        pass
+        if names is None:
+            names = self.testslist
+        testloader = unittest.TestLoader()
+        tclist = []
+        for name in names:
+            tset = testloader.loadTestsFromName(name)
+            if tset.countTestCases() > 0:
+                tclist.append(tset)
+            elif tset._tests == []:
+                tclist.append(testloader.discover(name, "[!_]*.py", os.path.curdir))
+        return testloader.suiteClass(tclist)
 
     def runtest(self, testsuite):
         '''run test suite'''
-        pass
+        starttime = time.time()
+        self.test_result = self.runner.run(testsuite)
+        self.run_time = time.time() - starttime
 
     def start(self, testsuite):
         '''start testing'''
-        pass
+        setattr(unittest.TestCase, "tc", self.context)
+        self.runtest(testsuite)
+        self.result()
 
-- 
2.1.4



  reply	other threads:[~2016-09-13  1:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-13  1:17 [PATCH 1/4] meta: introduce a small baserunner framework jwang
2016-09-13  1:17 ` jwang [this message]
2016-09-15 13:15   ` [PATCH 2/4] meta: implement key baserunner features Joshua Lock
2016-09-13  1:17 ` [PATCH 3/4] meta: use baserunner in oetest jwang
2016-09-15 13:15   ` Joshua Lock
2016-09-13  1:17 ` [PATCH 4/4] meta: modify runexported script to inherit the features from baserunner jwang
2016-09-15 13:15 ` [PATCH 1/4] meta: introduce a small baserunner framework Joshua Lock

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1473729455-32649-2-git-send-email-jing.j.wang@intel.com \
    --to=jing.j.wang@intel.com \
    --cc=openembedded-core@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox