gump-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From leosim...@apache.org
Subject svn commit: r123494 - in gump/trunk/python: . gump/actor/mysql gump/core/runner gump/test
Date Tue, 28 Dec 2004 11:30:06 GMT
Author: leosimons
Date: Tue Dec 28 03:30:02 2004
New Revision: 123494

URL: http://svn.apache.org/viewcvs?view=rev&rev=123494
Log:
Start work on Dynagumper unit tests
Added:
   gump/trunk/python/gump.log.config
   gump/trunk/python/gump/test/mockobjects.py
   gump/trunk/python/gump/test/testAllPyUnitTests.py.disabled.for.now
      - copied unchanged from r123492, gump/trunk/python/gump/test/testAllPyUnitTests.py
   gump/trunk/python/gump/test/testDynagumper.py
Removed:
   gump/trunk/python/gump/test/testAllPyUnitTests.py
Modified:
   gump/trunk/python/gump/actor/mysql/dynagumper.py
   gump/trunk/python/gump/core/runner/runner.py

Added: gump/trunk/python/gump.log.config
Url: http://svn.apache.org/viewcvs/gump/trunk/python/gump.log.config?view=auto&rev=123494
==============================================================================
--- (empty file)
+++ gump/trunk/python/gump.log.config	Tue Dec 28 03:30:02 2004
@@ -0,0 +1,25 @@
+[loggers]
+keys=root
+
+[handlers]
+keys=stdout
+
+[formatters]
+keys=simple
+
+[logger_root]
+level=INFO
+handlers=stdout
+propagate=1
+qualname=gump
+
+[handler_stdout]
+class=StreamHandler
+level=NOTSET
+formatter=simple
+args=(sys.stdout,)
+
+[formatter_simple]
+format=%(message)s
+datefmt=
+

Modified: gump/trunk/python/gump/actor/mysql/dynagumper.py
Url: http://svn.apache.org/viewcvs/gump/trunk/python/gump/actor/mysql/dynagumper.py?view=diff&rev=123494&p1=gump/trunk/python/gump/actor/mysql/dynagumper.py&r1=123493&p2=gump/trunk/python/gump/actor/mysql/dynagumper.py&r2=123494
==============================================================================
--- gump/trunk/python/gump/actor/mysql/dynagumper.py	(original)
+++ gump/trunk/python/gump/actor/mysql/dynagumper.py	Tue Dec 28 03:30:02 2004
@@ -20,6 +20,8 @@
 import MySQLdb
 import MySQLdb.cursors
 
+import platform
+
 from gump import log
 from gump.core.run.gumprun import *
 import gump.core.run.actor
@@ -29,69 +31,57 @@
     Populate the DynaGump run metadata database.
     """
     
-    def __init__(self,run):              
+    def __init__(self,run,conn):
         gump.core.run.actor.AbstractRunActor.__init__(self,run)    
-        self.dbInfo=self.workspace.getDatabaseInformation()
+        self.conn = conn
+
+    def _execute(self, cmd):
+        cursor = self.conn.cursor()
+        cursor.execute(cmd)
+        #try:
+        #    cursor = None    
+        #    try:
+        #        cursor = self.conn.cursor()
+        #        try:
+        #            cursor.execute(cmd)
+        #        except Exception, details:
+        #            log.error('SQL Error on [%s] : %s' % (cmd, details), exc_info=1)
+        #    finally:
+        #        if cursor: cursor.close()
+        #except Exception, details:
+        #    log.error('SQL Connection Error: %s' % (details), exc_info=1)
+    
+    def ensureThisHostIsInDatabase(self):
+        (system, host, release, version, machine, processor) = platform.uname()
+        tablename = "hosts"
+        description = "%s (%s,%s,%s,%s,%s)" % (host, system, release, version, machine, processor)
+        cmd = "INSERT INTO %s (address, name, cpu_arch, description) VALUES ('%s', '%s',
'%s', '%s')" \
+                % (tablename, host, host, processor, description)
+        
+        self._execute(cmd)
         
     def processOtherEvent(self,event):   
-        conn=None
-        helper=None
-        try:
-            conn=self.getConnected()
-            # do the actual work right here...
-            log.warning('dynagumper.py line 42: need to implement event processing')
-        finally:
-            if conn: conn.close()
+        # do the actual work right here...
+        log.warning('dynagumper.py processOtherEvent(): need to implement event processing')
                       
     def processWorkspace(self):
         """
         Add information about the workspace to the database.
         """
-        conn=None
-        helper=None
-        try:
-            conn=self.getConnected()
-            # do the actual work right here...
-            log.warning('dynagumper.py line 56: need to implement workspace event processing')
-        finally:
-            if conn: conn.close()
+        # do the actual work right here...
+        self.ensureThisHostIsInDatabase()
+        log.warning('dynagumper.py processWorkspace: need to implement workspace event processing')
     
     def processModule(self,module):    
         """
         Add information about the module to the database.
         """
-        conn=None
-        helper=None
-        try:
-            conn=self.getConnected()
-            # do the actual work
-            log.warning('dynagumper.py line 68: need to implement module event processing')
-        finally:
-            if conn: conn.close()
+        # do the actual work
+        log.warning('dynagumper.py processModule: need to implement module event processing')
     
     def processProject(self,project):    
         """
         Add information about the project to the database.
         """
-        conn=None
-        helper=None
-        try:
-            conn=self.getConnected()
-            # do the actual work right here...
-            log.warning('dynagumper.py line 82: need to implement project event processing')
-        finally:
-            if conn: conn.close()
-        
-        
-    def getConnected(self):
-        """
-        Get a database connection.
-        """
-                
-        return MySQLdb.Connect(
-                    host=self.dbInfo.getHost(), 
-                    user=self.dbInfo.getUser(),
-                    passwd=self.dbInfo.getPasswd(), 
-                    db=self.dbInfo.getDatabase(),
-                    compress=1,
-                    cursorclass=MySQLdb.cursors.DictCursor)
+        # do the actual work right here...
+        log.warning('dynagumper.py processProject: need to implement project event processing')

Modified: gump/trunk/python/gump/core/runner/runner.py
Url: http://svn.apache.org/viewcvs/gump/trunk/python/gump/core/runner/runner.py?view=diff&rev=123494&p1=gump/trunk/python/gump/core/runner/runner.py&r1=123493&p2=gump/trunk/python/gump/core/runner/runner.py&r2=123494
==============================================================================
--- gump/trunk/python/gump/core/runner/runner.py	(original)
+++ gump/trunk/python/gump/core/runner/runner.py	Tue Dec 28 03:30:02 2004
@@ -155,11 +155,27 @@
                 log.warning('Unable to register Historical Database Actor :  %s ' % details,
                             exc_info=1)
 
-        # Add DynaGump database populator
+        # Add Dynagump database populator
         if self.run.getWorkspace().hasDatabaseInformation():
             try:
-                import gump.actor.mysql.dynagumper
-                self.run.registerActor(gump.actor.mysql.dynagumper.Dynagumper(self.run))
+                conn = None
+                try:
+                    # create the database connection
+                    dbInfo = self.run.getWorkspace().getDatabaseInformation()
+                    import MySQLdb
+                    conn = MySQLdb.Connect(
+                        host=self.dbInfo.getHost(), 
+                        user=self.dbInfo.getUser(),
+                        passwd=self.dbInfo.getPasswd(), 
+                        db=self.dbInfo.getDatabase(),
+                        compress=1,
+                        cursorclass=MySQLdb.cursors.DictCursor)
+    
+                    # now create the Dynagumper
+                    import gump.actor.mysql.dynagumper
+                    self.run.registerActor(gump.actor.mysql.dynagumper.Dynagumper(self.run,conn))
+                finally:
+                    if conn: conn.close()
             except Exception, details:
                 log.warning('Unable to register Dynagump Database Actor :  %s ' % details,
                             exc_info=1)

Added: gump/trunk/python/gump/test/mockobjects.py
Url: http://svn.apache.org/viewcvs/gump/trunk/python/gump/test/mockobjects.py?view=auto&rev=123494
==============================================================================
--- (empty file)
+++ gump/trunk/python/gump/test/mockobjects.py	Tue Dec 28 03:30:02 2004
@@ -0,0 +1,69 @@
+#!/usr/bin/env python
+
+# Copyright 2004 The Apache Software Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+#     http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+__copyright__ = "Copyright (c) 2004 The Apache Software Foundation"
+__license__   = "http://www.apache.org/licenses/LICENSE-2.0"
+
+class MockConnection:
+    def __init__(self,cursor):
+        self._cursor = cursor
+    def cursor(self):
+        return self._cursor
+
+class MockCursor:
+    def __init__(self):
+        self.lastCommand = ''
+    
+    def execute(self,command):
+        self.lastCommand = command
+
+class MockWorkspace:
+    def __init__(self):
+        pass
+
+class MockOptions:
+    def __init__(self):
+        pass
+
+class MockGumpSet:
+    def __init__(self):
+        pass
+
+class MockRun:
+    def __init__(self,workspace,options,gumpSet):
+        self.workspace = workspace
+        self.options = options
+        self.gumpSet = gumpSet
+        
+    def getWorkspace(self):
+        return self.workspace
+    
+    def getOptions(self):
+        return self.options
+    
+    def getGumpSet(self):
+        return self.gumpSet
+
+class MockObjects:
+    def __init__(self):
+        self.workspace = MockWorkspace()
+        self.options = MockOptions()
+        self.gumpSet = MockGumpSet()
+        self.run = MockRun(self.workspace,self.options,self.gumpSet)
+        self.cursor = MockCursor()
+        self.conn = MockConnection(self.cursor)
+
+mocks = MockObjects()

Deleted: /gump/trunk/python/gump/test/testAllPyUnitTests.py
Url: http://svn.apache.org/viewcvs/gump/trunk/python/gump/test/testAllPyUnitTests.py?view=auto&rev=123493
==============================================================================

Copied: gump/trunk/python/gump/test/testAllPyUnitTests.py.disabled.for.now (from r123492,
gump/trunk/python/gump/test/testAllPyUnitTests.py)
Url: http://svn.apache.org/viewcvs/gump/trunk/python/gump/test/testAllPyUnitTests.py.disabled.for.now?view=diff&rev=123494&p1=gump/trunk/python/gump/test/testAllPyUnitTests.py&r1=123492&p2=gump/trunk/python/gump/test/testAllPyUnitTests.py.disabled.for.now&r2=123494
==============================================================================

Added: gump/trunk/python/gump/test/testDynagumper.py
Url: http://svn.apache.org/viewcvs/gump/trunk/python/gump/test/testDynagumper.py?view=auto&rev=123494
==============================================================================
--- (empty file)
+++ gump/trunk/python/gump/test/testDynagumper.py	Tue Dec 28 03:30:02 2004
@@ -0,0 +1,60 @@
+#!/usr/bin/env python
+
+# Copyright 2004 The Apache Software Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+#     http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+__copyright__ = "Copyright (c) 2004 The Apache Software Foundation"
+__license__   = "http://www.apache.org/licenses/LICENSE-2.0"
+
+import unittest
+from unittest import TestCase
+
+from gump.test.mockobjects import *
+
+from gump.actor.mysql.dynagumper import *
+from gump.core.model.workspace import *
+
+
+class DynagumperTestCase(TestCase):
+    def setUp(self):
+        self.workspace = MockWorkspace()
+        self.options = MockOptions()
+        self.gumpSet = MockGumpSet()
+        self.run = MockRun(self.workspace,self.options,self.gumpSet)
+        self.cursor = MockCursor()
+        self.conn = MockConnection(self.cursor)
+        self.dynagumper = Dynagumper(self.run,self.conn)
+    
+    def tearDown(self):
+        self.cleanupDatabaseMess()
+        
+    def testExecute(self):
+        self.dynagumper._execute("blah")
+        self.assertEquals( self.cursor.lastCommand, "blah" )
+        # you can do anything inside a test
+        # use the assertXXX methods on TestCase
+        # to check conditions
+        #self.assert_( True )
+        #self.assertEquals( type({}), type({}) )
+    
+    def cleanupDatabaseMess(self):
+        pass # TODO
+
+# this is used by testrunner.py to determine what tests to run
+def test_suite():
+    return unittest.makeSuite(DynagumperTestCase,'test')
+
+# this allows us to run this test by itself from the commandline
+if __name__ == '__main__':
+    unittest.main()

Mime
View raw message