summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYeoh Ee Peng <ee.peng.yeoh@intel.com>2017-05-21 11:22:22 -0700
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-05-25 23:59:31 +0100
commit61b2aef03a1e7b6a0e467a54cc0bd411ab3fc6ad (patch)
treeb758079be03c1f39ecccca2c3fc6b098863b6644
parent8da8909b7b0612beb71628bef06b5047608fd27a (diff)
downloadpoky-61b2aef03a1e7b6a0e467a54cc0bd411ab3fc6ad.tar.gz
base.py: add assertExists and assertNotExists to oeselftest
Current osselftest print confusing assertion message when using self.assertTrue(os.path.exists(filepath)) to test file path, example of confusing assertion message: AssertionError: False is not true Add the assertExists and assertNotExists to improve assertion message and simplify coding, using selft.assertExists(filepath), will print meaningful assertion message: AssertionError: <filepath> does not exist [YOCTO #11356] (From OE-Core rev: b0a74554ef926ce05078494ca8e67178b56232f5) Signed-off-by: Yeoh Ee Peng <ee.peng.yeoh@intel.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/lib/oeqa/selftest/base.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/meta/lib/oeqa/selftest/base.py b/meta/lib/oeqa/selftest/base.py
index 47a8ea8271..43a1951be3 100644
--- a/meta/lib/oeqa/selftest/base.py
+++ b/meta/lib/oeqa/selftest/base.py
@@ -18,6 +18,7 @@ from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_test_layer
18from oeqa.utils.decorators import LogResults 18from oeqa.utils.decorators import LogResults
19from random import choice 19from random import choice
20import glob 20import glob
21from unittest.util import safe_repr
21 22
22@LogResults 23@LogResults
23class oeSelfTest(unittest.TestCase): 24class oeSelfTest(unittest.TestCase):
@@ -214,6 +215,18 @@ be re-executed from a clean environment to ensure accurate results.")
214 self.log.debug("Writing to: %s\n%s\n" % (self.machineinc_path, data)) 215 self.log.debug("Writing to: %s\n%s\n" % (self.machineinc_path, data))
215 ftools.write_file(self.machineinc_path, data) 216 ftools.write_file(self.machineinc_path, data)
216 217
218 # check does path exist
219 def assertExists(self, expr, msg=None):
220 if not os.path.exists(expr):
221 msg = self._formatMessage(msg, "%s does not exist" % safe_repr(expr))
222 raise self.failureException(msg)
223
224 # check does path not exist
225 def assertNotExists(self, expr, msg=None):
226 if os.path.exists(expr):
227 msg = self._formatMessage(msg, "%s exists when it should not" % safe_repr(expr))
228 raise self.failureException(msg)
229
217 230
218def get_available_machines(): 231def get_available_machines():
219 # Get a list of all available machines 232 # Get a list of all available machines