From 63f7258f0ac509cda5e208d2b9a03b44a452c24c Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Mon, 17 Aug 2015 15:14:26 -0500 Subject: [PATCH] Better error messages from invalid sample tasks An invalid sample JSON task file gave an error message that didn't give the filename. This commit fixes that, and does some minor cleanup around invalid YAML tasks. Change-Id: I21f38e015e310a6450286f700c634ebd03eec5be --- tests/unit/doc/test_task_samples.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/unit/doc/test_task_samples.py b/tests/unit/doc/test_task_samples.py index 63218aeaf3..103c05a744 100644 --- a/tests/unit/doc/test_task_samples.py +++ b/tests/unit/doc/test_task_samples.py @@ -55,8 +55,7 @@ class TaskSampleTestCase(test.TestCase): eng.validate() except Exception: print(traceback.format_exc()) - self.assertTrue(False, - "Wrong task config %s" % full_path) + self.fail("Invalid task file: %s" % full_path) else: scenarios.update(task_config.keys()) @@ -77,7 +76,11 @@ class TaskSampleTestCase(test.TestCase): continue full_path = os.path.join(dirname, filename) with open(full_path) as task_file: - json.load(task_file) + try: + json.load(task_file) + except Exception: + print(traceback.format_exc()) + self.fail("Invalid JSON file: %s" % full_path) def test_task_config_pair_existance(self): inexistent_paths = []