From f0ac6c12f5a5b7be6cd61404e6e66ea21e12725f Mon Sep 17 00:00:00 2001 From: akorosov Date: Wed, 7 Mar 2018 20:55:51 +0100 Subject: [PATCH] #91 increase test coverage for node --- nansat/node.py | 25 ------------------------- nansat/tests/test_node.py | 13 +++++++++++++ nansat/tests/test_vrt.py | 1 - 3 files changed, 13 insertions(+), 26 deletions(-) diff --git a/nansat/node.py b/nansat/node.py index b400504d2..8d5a131e9 100644 --- a/nansat/node.py +++ b/nansat/node.py @@ -169,31 +169,6 @@ def delNode(self, tag, options=None): for i in sorted(ideleted, reverse=True): self.children.pop(i) - def find_dom_child(self, dom, tagName, n=0): - '''Recoursively find child of the dom''' - children = dom.childNodes - theChild = None - - chn = 0 - for child in children: - print(child, child.nodeType, chn) - if child.nodeType == 1: - print(child.tagName) - if str(child.tagName) == tagName: - print(child.tagName, tagName, 'OK') - if chn == n: - theChild = child - chn += 1 - - if theChild is not None: - break - - if child.hasChildNodes(): - print('has childs') - theChild = self.find_dom_child(child, tagName, n) - - return theChild - def nodeList(self, tag): ''' Produce a list of subnodes with the same tag. diff --git a/nansat/tests/test_node.py b/nansat/tests/test_node.py index b9bd408bc..4a2ee3a17 100644 --- a/nansat/tests/test_node.py +++ b/nansat/tests/test_node.py @@ -23,10 +23,14 @@ def test_creation(self): tag = 'Root' value = ' Value ' anAttr = 'elValue' + new_value = 'New Value' node = Node(tag, value=value, anAttr=anAttr) self.assertEqual(node.tag, tag) self.assertDictEqual(node.attributes, {'anAttr': anAttr}) self.assertEqual(node.value, value.strip()) + self.assertEqual(node[tag], value.strip()) + node[tag] = new_value + self.assertEqual(node.value, new_value) def test_getAttributeList(self): tag = 'Root' @@ -145,3 +149,12 @@ def test_search_node(self): root += firstLevel3 self.assertEqual(root.node(firstLevelTag,0), firstLevel) self.assertEqual(root.node(firstLevelTag,1), firstLevel2) + + def test_str(self): + tag = 'Root' + value = 'Value' + node = Node(tag, value=value) + self.assertEqual(str(node), '%s\n value: [%s]' % (tag, value)) + +if __name__ == "__main__": + unittest.main() diff --git a/nansat/tests/test_vrt.py b/nansat/tests/test_vrt.py index ede846a4e..54d7f88fe 100644 --- a/nansat/tests/test_vrt.py +++ b/nansat/tests/test_vrt.py @@ -599,6 +599,5 @@ def test_make_filename(self): self.assertTrue(os.path.exists(filename3)) - if __name__ == "__main__": unittest.main()