def test_is_node(self): """Tests the utils.is_node function""" d = { 'a': { 'b': False, 'c': None }, 'd': None, 'e': { 'f': { 'g': None } } } self.assertEqual(False, utils.is_node(False, '')) self.assertEqual(False, utils.is_node({}, '')) self.assertEqual(False, utils.is_node({'x': False}, 'x')) self.assertEqual(True, utils.is_node(d, 'a')) self.assertEqual(False, utils.is_node(d, 'b')) self.assertEqual(False, utils.is_node(d, 'c')) self.assertEqual(False, utils.is_node(d, 'd')) self.assertEqual(True, utils.is_node(d, 'e')) self.assertEqual(False, utils.is_node(d, 'f')) self.assertEqual(False, utils.is_node(d, 'g'))
def consume(tree, parent, includes, excludes, substitutes): if is_node(tree, 'includes'): dfs(tree['includes'], parent, includes, lambda ref, v: to_forward_ref(ref)) if is_node(tree, 'excludes'): dfs(tree['excludes'], parent, excludes, lambda ref, v: ref) if is_node(tree, 'substitutes'): dfs(tree['substitutes'], parent, substitutes, lambda ref, v: u'{0}={1}'.format(ref, shell_escape(v)))