From 28a08d8eae2e29e732c4cff51346485e11e04e95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= Date: Tue, 4 Oct 2016 19:44:10 +0200 Subject: [PATCH] avocado.plugins.yaml_to_mux: Allow empty yaml files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch avoids avocado crash on empty multiplex yaml file. Empty file contains basically nothing and that is how it's handled now. Signed-off-by: Lukáš Doktor --- avocado/plugins/yaml_to_mux.py | 10 ++++++++-- selftests/.data/empty_file | 0 selftests/functional/test_multiplex.py | 13 ++++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 selftests/.data/empty_file diff --git a/avocado/plugins/yaml_to_mux.py b/avocado/plugins/yaml_to_mux.py index ffac1fa8..1bb68902 100644 --- a/avocado/plugins/yaml_to_mux.py +++ b/avocado/plugins/yaml_to_mux.py @@ -170,6 +170,8 @@ def _create_from_yaml(path, cls_node=tree.TreeNode): # Load the tree with open(path) as stream: loaded_tree = yaml.load(stream, Loader) + if loaded_tree is None: + return loaded_tree = tree_node_from_values('', loaded_tree) # Add prefix @@ -192,12 +194,16 @@ def create_from_yaml(paths, debug=False): """ def _merge(data, path): """ Normal run """ - data.merge(_create_from_yaml(path)) + tmp = _create_from_yaml(path) + if tmp: + data.merge(tmp) def _merge_debug(data, path): """ Use NamedTreeNodeDebug magic """ node_cls = tree.get_named_tree_cls(path) - data.merge(_create_from_yaml(path, node_cls)) + tmp = _create_from_yaml(path, node_cls) + if tmp: + data.merge(tmp) if not debug: data = tree.TreeNode() diff --git a/selftests/.data/empty_file b/selftests/.data/empty_file new file mode 100644 index 00000000..e69de29b diff --git a/selftests/functional/test_multiplex.py b/selftests/functional/test_multiplex.py index a40a8441..d8629dde 100644 --- a/selftests/functional/test_multiplex.py +++ b/selftests/functional/test_multiplex.py @@ -34,12 +34,17 @@ class MultiplexTests(unittest.TestCase): def setUp(self): self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__) - def run_and_check(self, cmd_line, expected_rc): + def run_and_check(self, cmd_line, expected_rc, tests=None): os.chdir(basedir) result = process.run(cmd_line, ignore_status=True) self.assertEqual(result.exit_status, expected_rc, "Command %s did not return rc " "%d:\n%s" % (cmd_line, expected_rc, result)) + if tests: + exp = ("PASS %s | ERROR 0 | FAIL %s | SKIP 0 | WARN 0 | " + "INTERRUPT 0" % tests) + self.assertIn(exp, result.stdout, "%s not in stdout:\n%s" + % (exp, result)) return result def test_mplex_plugin(self): @@ -101,6 +106,12 @@ class MultiplexTests(unittest.TestCase): expected_rc = exit_codes.AVOCADO_ALL_OK self.run_and_check(cmd_line, expected_rc) + def test_empty_file(self): + cmd_line = ("./scripts/avocado run -m selftests/.data/empty_file " + "-- passtest.py") + result = self.run_and_check(cmd_line, exit_codes.AVOCADO_ALL_OK, + (1, 0)) + def test_run_mplex_params(self): for variant_msg in (('/run/short', 'A'), ('/run/medium', 'ASDFASDF'), -- GitLab