gump-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From leosim...@apache.org
Subject svn commit: r159180 - in gump/branches/Gump3/pygump/python/gump: engine/modeller.py test/testModeller.py
Date Sun, 27 Mar 2005 19:10:09 GMT
Author: leosimons
Date: Sun Mar 27 11:10:09 2005
New Revision: 159180

URL: http://svn.apache.org/viewcvs?view=rev&rev=159180
Log:
* Basic tests for all the functions in the modeller module.

* found a bug in the _find_xxx methods; they weren't calling _find_tag_... properly

Modified:
    gump/branches/Gump3/pygump/python/gump/engine/modeller.py
    gump/branches/Gump3/pygump/python/gump/test/testModeller.py

Modified: gump/branches/Gump3/pygump/python/gump/engine/modeller.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/engine/modeller.py?view=diff&r1=159179&r2=159180
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/engine/modeller.py (original)
+++ gump/branches/Gump3/pygump/python/gump/engine/modeller.py Sun Mar 27 11:10:09 2005
@@ -74,17 +74,17 @@
 
 def _find_project_containing_node(node):
     """Walk up the DOM hierarchy to locate a <project> Element."""
-    return _find_ancestor_by_tag("project")
+    return _find_ancestor_by_tag(node, "project")
 
 
 def _find_module_containing_node(node):
     """Walk up the DOM hierarchy to locate a <module> Element."""
-    return _find_ancestor_by_tag("module")
+    return _find_ancestor_by_tag(node, "module")
 
 
 def _find_repository_containing_node(node):
     """Walk up the DOM hierarchy to locate a <repository> Element."""
-    return _find_ancestor_by_tag("repository")
+    return _find_ancestor_by_tag(node, "repository")
 
 
 def _import_node(target_node, new_node):

Modified: gump/branches/Gump3/pygump/python/gump/test/testModeller.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/test/testModeller.py?view=diff&r1=159179&r2=159180
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/test/testModeller.py (original)
+++ gump/branches/Gump3/pygump/python/gump/test/testModeller.py Sun Mar 27 11:10:09 2005
@@ -25,6 +25,11 @@
 from gump.engine.modeller import _find_element_text
 from gump.engine.modeller import _do_drop
 from gump.engine.modeller import _find_ancestor_by_tag
+from gump.engine.modeller import _find_document_containing_node
+from gump.engine.modeller import _find_repository_containing_node
+from gump.engine.modeller import _find_module_containing_node
+from gump.engine.modeller import _find_project_containing_node
+from gump.engine.modeller import _import_node
 
 class ModellerTestCase(TestCase):
     def setUp(self):
@@ -51,12 +56,33 @@
           </some>
         </with>
       </tags>
+      <repository>
+        <module>
+          <project>
+            <nested>
+              <uniquetaghere>
+                <foo/>
+              </uniquetaghere>
+            </nested>
+          </project>
+        </module>
+      </repository>
     </nested>
   </some>
 </root>
 """
         self.sampledom = minidom.parseString(self.samplexml)
-        
+
+        self.samplexml2 = """<?xml version="1.0"?>
+
+<otherroot info="true">
+  <newelem attr="yo">contents</newelem>
+  <newstuff>ignore</newstuff>
+  <newelem>ignore</newelem>
+</otherroot>
+"""
+        self.sampledom2 = minidom.parseString(self.samplexml2)
+
     def test_find_element_text(self):
         root = self.sampledom.documentElement
         text = _find_element_text(root, "elem")
@@ -77,6 +103,7 @@
             pass
     
     def test_do_drop(self):
+        # todo test all possibilities
         to_remove = self.sampledom.documentElement.getElementsByTagName("stuff").item(0)
         dropped = []
         _do_drop(to_remove, dropped)
@@ -85,10 +112,52 @@
         self.assertEqual(to_remove, dropped[0])
     
     def test_find_ancestor_by_tag(self):
+        # todo test all possibilities
         in_elem = self.sampledom.documentElement.getElementsByTagName("in").item(0)
         first_some_elem = in_elem.parentNode.parentNode.parentNode
         found_some = _find_ancestor_by_tag(in_elem, "some")
         self.assertEqual(first_some_elem, found_some)
+    
+    def test_find_document_containing_node(self):
+        # todo test all possibilities
+        in_elem = self.sampledom.documentElement.getElementsByTagName("in").item(0)
+        found_doc = _find_document_containing_node(in_elem)
+        self.assertEqual(self.sampledom,found_doc)
+    
+    def test_find_repository_containing_node(self):
+        # todo test all possibilities
+        child_elem = self.sampledom.documentElement.getElementsByTagName("uniquetaghere").item(0)
+        required_repo = child_elem.parentNode.parentNode.parentNode.parentNode
+        found_repo = _find_repository_containing_node(child_elem)
+        self.assertEqual(required_repo, found_repo)
+        
+    def test_find_module_containing_node(self):
+        # todo test all possibilities
+        child_elem = self.sampledom.documentElement.getElementsByTagName("uniquetaghere").item(0)
+        required_module = child_elem.parentNode.parentNode.parentNode
+        found_repo = _find_module_containing_node(child_elem)
+        self.assertEqual(required_module, found_repo)
+        
+    def test_find_project_containing_node(self):
+        # todo test all possibilities
+        child_elem = self.sampledom.documentElement.getElementsByTagName("uniquetaghere").item(0)
+        required_project = child_elem.parentNode.parentNode
+        found_repo = _find_project_containing_node(child_elem)
+        self.assertEqual(required_project, found_repo)
+    
+    def test_import_node(self):
+        # todo test all possibilities
+        oldroot = self.sampledom.documentElement
+        newroot = self.sampledom2.documentElement
+        _import_node(oldroot, newroot)
+        self.assertEqual("root", oldroot.tagName)
+        self.assertEqual(1, oldroot.attributes.length)
+        self.assertEqual("info", oldroot.attributes.item(0).nodeName.__str__())
+        self.assertEqual("true", oldroot.attributes.item(0).nodeValue.__str__())
+        self.assertEqual(2, oldroot.getElementsByTagName("elem").length)
+        self.assertEqual(1, oldroot.getElementsByTagName("uniquetaghere").length)
+        self.assertEqual(2, oldroot.getElementsByTagName("newelem").length)
+        self.assertEqual(1, oldroot.getElementsByTagName("newstuff").length)
 
 # this is used by testrunner.py to determine what tests to run
 def test_suite():



Mime
View raw message