diff --git a/camkes/parser/fdtQueryEngine.py b/camkes/parser/fdtQueryEngine.py index 8273147b..5449903f 100644 --- a/camkes/parser/fdtQueryEngine.py +++ b/camkes/parser/fdtQueryEngine.py @@ -596,20 +596,21 @@ def resolve_fdt_node(cls, node): resolved['this-node-path'] = node_path return resolved + # An empty query is supported for convenience reasons, it produces an empty + # result. Any real query must find a match, otherwise an error is raised. def resolve(self, args): - result = self.engine.query(args) - if not len(result): - raise ParseError(f'DTB query failed: {args}') - query_results = [] - for entry in result: - if not len(entry): - query_results.append({}) - else: - node = entry[0] - node_resolved = self.resolve_fdt_node(node) - query_results.append(node_resolved) - + if (len(args) > 0): + result = self.engine.query(args) + if not len(result): + raise ParseError(f'DTB query failed: {args}') + for entry in result: + if not len(entry): + query_results.append({}) + else: + node = entry[0] + node_resolved = self.resolve_fdt_node(node) + query_results.append(node_resolved) return { 'query': query_results, 'dtb-size': [self.dtb_file_size] diff --git a/camkes/parser/tests/testdtbmatchquery.py b/camkes/parser/tests/testdtbmatchquery.py index c05fc4c7..4302a9ab 100755 --- a/camkes/parser/tests/testdtbmatchquery.py +++ b/camkes/parser/tests/testdtbmatchquery.py @@ -209,7 +209,13 @@ def test_multiple_queries(self): self.assertEquals(node['dtb-size'], [self.dtbSize]) def test_blank(self): - self.assertRaises(ParseError, self.dtbQuery.resolve, []) + # For convenience reasons an empty query list is allowed and does not + # raise a ParseError. It returns an empty result list instead. + node = self.dtbQuery.resolve([]) + self.assertIn('query', node) + self.assertEquals(len(node['query']), 0) + self.assertIn('dtb-size', node) + self.assertEquals(node['dtb-size'], [self.dtbSize]) def test_blank_query(self): node = self.dtbQuery.resolve([{}])