gump-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From leosim...@apache.org
Subject svn commit: r158281 - in gump/branches/Gump3/pygump/python/gump: engine/modeller.py test/testModeller.py test/testUtilMysql.py util/sysinfo.py
Date Sun, 20 Mar 2005 03:09:12 GMT
Author: leosimons
Date: Sat Mar 19 19:09:11 2005
New Revision: 158281

URL: http://svn.apache.org/viewcvs?view=rev&rev=158281
Log:
Add option to ignore mysql test failures, and start testing some modeller bits.

Added:
    gump/branches/Gump3/pygump/python/gump/test/testModeller.py
      - copied, changed from r158086, gump/branches/Gump3/pygump/python/gump/test/testExample.py
Modified:
    gump/branches/Gump3/pygump/python/gump/engine/modeller.py
    gump/branches/Gump3/pygump/python/gump/test/testUtilMysql.py
    gump/branches/Gump3/pygump/python/gump/util/sysinfo.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=158280&r2=158281
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/engine/modeller.py (original)
+++ gump/branches/Gump3/pygump/python/gump/engine/modeller.py Sat Mar 19 19:09:11 2005
@@ -32,7 +32,11 @@
 ###
 def _find_element_text(parent, element_name):
     """Retrieves the text contents of an element like <blah>text</blah>."""
-    return parent.getElementsByTagName(element_name).item(0).firstChild.data
+    elem = parent.getElementsByTagName(element_name).item(0).firstChild
+    if elem:
+        return elem.data
+    else:
+        return ""
 
 
 def _do_drop(to_remove, dropped_nodes=None):
@@ -41,7 +45,7 @@
     node_to_remove_element_from = to_remove.parentNode
     node_to_remove_element_from.removeChild(to_remove)
     
-    if dropped_nodes:
+    if dropped_nodes != None:
         dropped_nodes.append(to_remove)
 
 

Copied: gump/branches/Gump3/pygump/python/gump/test/testModeller.py (from r158086, gump/branches/Gump3/pygump/python/gump/test/testExample.py)
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/test/testModeller.py?view=diff&rev=158281&p1=gump/branches/Gump3/pygump/python/gump/test/testExample.py&r1=158086&p2=gump/branches/Gump3/pygump/python/gump/test/testModeller.py&r2=158281
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/test/testExample.py (original)
+++ gump/branches/Gump3/pygump/python/gump/test/testModeller.py Sat Mar 19 19:09:11 2005
@@ -17,39 +17,59 @@
 __copyright__ = "Copyright (c) 2005 The Apache Software Foundation"
 __license__   = "http://www.apache.org/licenses/LICENSE-2.0"
 
-"""
-    This is an example of a testcase. Simply copy and rename this file
-    (the filename has to start with "test"), then rename the class below,
-    update the reference to the classname in the test_suite() method,
-    and write your test methods.
-    
-    See the documentation for the unittest package for more help with
-    tests. You can run all tests from the commandline using "./gump test".
-"""
-
 import unittest
 from unittest import TestCase
 
-class ExampleTestCase(TestCase):
+from xml.dom import minidom
+
+from gump.engine.modeller import _find_element_text
+from gump.engine.modeller import _do_drop
+
+class ModellerTestCase(TestCase):
     def setUp(self):
-        # initialize tests here
-        pass
-    
-    def tearDown(self):
-        # clean up after tests here
-        pass
+        self.samplexml = """<?xml version="1.0"?>
+
+<root>
+  blah
+  <elem>contents</elem>
+  <stuff>ignore</stuff>
+  <elem>ignore</elem>
+  <blah></blah>
+</root>
+"""
+        self.sampledom = minidom.parseString(self.samplexml)
         
-    def test_something(self):
-        # you can do anything inside a test
-        # use the assertXXX methods on TestCase
-        # to check conditions
-        self.assert_( True )
-        self.assertEquals( type({}), type({}) )
+    def test_find_element_text(self):
+        root = self.sampledom.documentElement
+        text = _find_element_text(root, "elem")
+        self.assertEqual("contents", text)
+        text = _find_element_text(root, "blah")
+        self.assertEqual("", text)
+        try:
+            _find_element_text(root, "notthere")
+        except:
+            pass
+        try:
+            _find_element_text(None, "stuff")
+        except:
+            pass
+        try:
+            _find_element_text(root, None)
+        except:
+            pass
+    
+    def test_do_drop(self):
+        to_remove = self.sampledom.documentElement.getElementsByTagName("stuff").item(0)
+        dropped = []
+        _do_drop(to_remove, dropped)
+        self.assertEqual(0, len(self.sampledom.documentElement.getElementsByTagName("stuff")))
+        self.assertEqual(1, len(dropped))
+        self.assertEqual(to_remove, dropped[0])
 
 # this is used by testrunner.py to determine what tests to run
 def test_suite():
     # be sure to change the referenceto the TestCase class you create above!
-    return unittest.makeSuite(ExampleTestCase,'test')
+    return unittest.makeSuite(ModellerTestCase,'test')
 
 # this allows us to run this test by itself from the commandline
 if __name__ == '__main__':

Modified: gump/branches/Gump3/pygump/python/gump/test/testUtilMysql.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/test/testUtilMysql.py?view=diff&r1=158280&r2=158281
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/test/testUtilMysql.py (original)
+++ gump/branches/Gump3/pygump/python/gump/test/testUtilMysql.py Sat Mar 19 19:09:11 2005
@@ -20,6 +20,8 @@
 import unittest
 from unittest import TestCase
 
+import os
+
 import pmock
 from pmock import *
 
@@ -73,11 +75,16 @@
             (rows, result) = d.execute("DROP TABLE gump_unit_test;")
             self.assertEqual(0, rows)
         except Exception:
-            print """
+            if not os.environ.has_key("GUMP_TEST_NO_MYSQL"):
+                print """
 The MySQL test depends on a running mysql server to which one can connect
 as a test user. That seems to have failed. This is probably not critical.
+
+You can avoid seeing this error by setting the environment variable
+  GUMP_TEST_NO_MYSQL
+prior to running this test.
 """
-            raise
+                raise
 
         
 

Modified: gump/branches/Gump3/pygump/python/gump/util/sysinfo.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/util/sysinfo.py?view=diff&r1=158280&r2=158281
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/util/sysinfo.py (original)
+++ gump/branches/Gump3/pygump/python/gump/util/sysinfo.py Sat Mar 19 19:09:11 2005
@@ -93,7 +93,10 @@
     cmd = 'cat /proc/meminfo | grep MemTotal | sed -e "s/[^0-9]//g"'
     (result, output, error) = _system(cmd)
     if not result: # exit status 0 is good!
-        amount = int(output)
+        try:
+            amount = int(output)
+        except:
+            pass
     
     return amount
     
@@ -104,7 +107,10 @@
     cmd = "cat /proc/cpuinfo | grep MHz | sed -e 's/[^0-9]//g' | awk '!x[$0]++'"
     (result, output, error) = _system(cmd)
     if not result: # exit status 0 is good!
-        amount = int(output)
+        try:
+            amount = int(output)
+        except:
+            pass
     
     return amount
 
@@ -115,6 +121,9 @@
     cmd = 'cat /proc/cpuinfo | grep "^processor" | sed -e "s/[^0-9]//g" | grep -c ".*"'
     (result, output, error) = _system(cmd)
     if not result: # exit status 0 is good!
-        amount = int(output)
+        try:
+            amount = int(output)
+        except:
+            pass
     
     return amount



Mime
View raw message