gump-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From leosim...@apache.org
Subject svn commit: r209771 - in /gump/branches/Gump3/pygump/python: gump/config.py gump/engine/__init__.py gump/test/testConfig.py main.py
Date Fri, 08 Jul 2005 13:36:45 GMT
Author: leosimons
Date: Fri Jul  8 06:36:45 2005
New Revision: 209771

URL: http://svn.apache.org/viewcvs?rev=209771&view=rev
Log:
Clean up the config and bootstrap modules a little bit and add some unit tests. for them.

Modified:
    gump/branches/Gump3/pygump/python/gump/config.py
    gump/branches/Gump3/pygump/python/gump/engine/__init__.py
    gump/branches/Gump3/pygump/python/gump/test/testConfig.py
    gump/branches/Gump3/pygump/python/main.py

Modified: gump/branches/Gump3/pygump/python/gump/config.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/config.py?rev=209771&r1=209770&r2=209771&view=diff
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/config.py (original)
+++ gump/branches/Gump3/pygump/python/gump/config.py Fri Jul  8 06:36:45 2005
@@ -52,32 +52,8 @@
     else:
         config.log_level       = logging.INFO
     if settings.quiet:
-        settings.debug = False
+        config.debug = False
         config.log_level = logging.WARN
-    
-    # TODO: change main.py to do it like this
-    config.paths_home      = settings.homedir
-    config.paths_work      = settings.workdir
-    config.paths_logs      = settings.logdir
-    config.paths_workspace = settings.workspace
-    # resolve hrefs relative to workspace xml file
-    config.paths_metadata  = os.path.dirname(config.paths_workspace)
-    config.start_time      = settings.starttimeutc
-    
-    config.projects        = settings.projects
-    
-    config.mail_server     = settings.mailserver
-    config.mail_server_port = settings.mailport
-    config.mail_to         = settings.mailto
-    config.mail_from       = settings.mailfrom
-    
-    config.database_server = "localhost"
-    config.database_server = settings.databaseserver
-    config.database_port   = 3306
-    config.database_port = settings.databaseport
-    config.database_name = settings.databasename
-    config.database_user = settings.databaseuser
-    config.database_password = settings.databasepassword
     
     # set up other stuff
     run_config_hooks(config)

Modified: gump/branches/Gump3/pygump/python/gump/engine/__init__.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/engine/__init__.py?rev=209771&r1=209770&r2=209771&view=diff
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/engine/__init__.py (original)
+++ gump/branches/Gump3/pygump/python/gump/engine/__init__.py Fri Jul  8 06:36:45 2005
@@ -39,11 +39,22 @@
 __license__   = "http://www.apache.org/licenses/LICENSE-2.0"
 
 import logging
-
+import os
 from xml import dom
 from xml.dom import minidom
 
-from gump.config import *
+from gump.config import get_config
+from gump.config import get_logger
+from gump.config import get_vfs
+from gump.config import get_walker
+from gump.config import get_modeller_loader
+from gump.config import get_modeller_normalizer
+from gump.config import get_modeller_objectifier
+from gump.config import get_modeller_verifier
+from gump.config import get_dom_implementation
+from gump.config import get_plugin
+from gump.config import shutdown_logging
+
 from gump.util.io import open_file_or_stream
 from gump.util import ansicolor
 

Modified: gump/branches/Gump3/pygump/python/gump/test/testConfig.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/test/testConfig.py?rev=209771&r1=209770&r2=209771&view=diff
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/test/testConfig.py (original)
+++ gump/branches/Gump3/pygump/python/gump/test/testConfig.py Fri Jul  8 06:36:45 2005
@@ -23,11 +23,108 @@
 from pmock import *
 
 from gump.config import *
+import gump
+from gump.plugins import AbstractPlugin
+
+import logging
+import logging.config
 
 class ConfigTestCase(MockTestCase):
     def setUp(self):
-        pass
+        # replace various methods with mockup versions
+        def newfileconfig(filename):
+            self.failUnless(isinstance(filename, basestring))
+            self.failUnless(filename.startswith('gump.log.config'))
+        self.old_fileConfig = logging.config.fileConfig
+        logging.config.fileConfig = newfileconfig
+
+        def new_get_logger(config, name):
+            return self.get_mock_logger(config, name)
+        self.old_get_logger = gump.config.get_logger
+        gump.config.get_logger = new_get_logger
+    
+    def tearDown(self):
+        logging.config.fileConfig = self.old_fileConfig
+        gump.config.get_logger = self.old_get_logger
+    
+    def get_mock_logger(self, config, name):
+        self.failUnless(unittest.TestCase, isinstance(config, Config))
+        self.failUnless(unittest.TestCase, isinstance(name, basestring))
     
-    def test_something(self):
-        # TODO replace with something useful
-        pass
+        mock = self.mock()
+        mock.stubs().method("debug")
+        mock.stubs().method("info")
+        mock.stubs().method("warn")
+        mock.stubs().method("warning")
+        mock.stubs().method("error")
+        mock.stubs().method("critical")
+        mock.stubs().method("log")
+        mock.stubs().method("exception")
+        mock.stubs().method("close")
+        return mock
+
+    def test_run_config_hooks(self):
+        class MockConfig:
+            debug = False
+            quiet = False
+        
+        mock = MockConfig()
+        run_config_hooks(mock)
+        
+        mock.quiet = True
+        run_config_hooks(mock)
+        
+        mock.debug = True
+        run_config_hooks(mock)
+
+    def test_get_config(self):
+        testcase = self
+        class Settings:
+            def __hasattr__(self, name):
+                return True
+            
+            def __getattr__(self, name):
+                return name
+
+            def __setattr__(self, name, value):
+                testcase.fail("Config tried to set option on settings!")
+        
+        s = Settings()
+        c = get_config(s)
+        for arg in ["paths_home", "paths_work", "color", "irc", "blah"]:
+            value = getattr(c, arg)
+            self.assertEqual(arg, value)
+        self.assertEqual(c.log_level, logging.WARN)
+        self.assertFalse(c.debug)
+
+    def test_get_plugins(self):
+        class Config:
+            irc = "user@freenode.net/gump"
+            
+            def __hasattr__(self, name):
+                return True
+            
+            def __getattr__(self, name):
+                return name
+        
+        conf = Config()
+        (a,b,c) = get_plugins(conf)
+        
+        def test_results(a,b,c):
+            self.failUnless(isinstance(a,list))
+            self.failUnless(isinstance(b,list))
+            self.failUnless(isinstance(c,list))
+            l = []
+            l.extend(a)
+            l.extend(b)
+            l.extend(c)
+            for p in l:
+                self.failUnless(isinstance(p,AbstractPlugin))
+        test_results(a,b,c)
+        
+        conf.do_build = False
+        conf.do_update = False
+        conf.do_fill_database = False
+        conf.debug = False
+        (a,b,c) = get_plugins(conf)
+        test_results(a,b,c)

Modified: gump/branches/Gump3/pygump/python/main.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/main.py?rev=209771&r1=209770&r2=209771&view=diff
==============================================================================
--- gump/branches/Gump3/pygump/python/main.py (original)
+++ gump/branches/Gump3/pygump/python/main.py Fri Jul  8 06:36:45 2005
@@ -77,6 +77,7 @@
     usage = "gump run [options ...]"
 
     parser = OptionParser(usage=usage)
+
     parser.add_option("-d",
                       "--debug",
                       action="store_true",
@@ -89,6 +90,7 @@
                       help="print as little information as possible (overrides --debug)")
     parser.add_option("--homedir",
                       action="store",
+                      dest="paths_home",
                       default=_homedir,
                       help="the base directory for gump")
     parser.add_option("--hostname",
@@ -97,15 +99,18 @@
                       help="the hostname gump will use")
     parser.add_option("--workdir",
                       action="store",
+                      dest="paths_work",
                       default=_workdir,
                       help="the working directory gump will use")
     parser.add_option("--logdir",
                       action="store",
+                      dest="paths_logs",
                       default=_logdir,
                       help="the directory gump will write logs to")
     parser.add_option("-w",
                       "--workspace",
                       action="store",
+                      dest="paths_workspace",
                       default=_workspace,
                       help="path to the workspace gump will use")
     parser.add_option("-u",
@@ -128,22 +133,27 @@
                       help="put build results into the mysql database")
     parser.add_option("--databaseserver",
                       action="store",
+                      dest="database_server",
                       default=_databaseserver,
                       help="hostname of the database server gump will connect to")
     parser.add_option("--databaseport",
                       action="store",
+                      dest="database_port",
                       default=_databaseport,
                       help="port of the database server gump will connect to")
     parser.add_option("--databasename",
                       action="store",
+                      dest="database_name",
                       default=_databasename,
                       help="name of the database gump will connect to")
     parser.add_option("--databaseuser",
                       action="store",
+                      dest="database_user",
                       default=_databaseuser,
                       help="username gump will use to connect to the database")
     parser.add_option("--databasepassword",
                       action="store",
+                      dest="database_password",
                       default=_databasepassword,
                       help="password gump will use to connect to the database")
     parser.add_option("--color",
@@ -294,10 +304,10 @@
 
     # Mail reporting
     # unused options.private     = w.getAttribute('private')
-    options.mailserver  = w.getAttribute('mailserver') or 'localhost'
-    options.mailport    = w.getAttribute('mailport') or 25
-    options.mailto      = w.getAttribute('administrator') 
-    options.mailfrom    = w.getAttribute('email') or "%s@%s" % (user, options.hostname)
+    options.mail_server  = w.getAttribute('mailserver') or 'localhost'
+    options.mail_server_port    = w.getAttribute('mailport') or 25
+    options.mail_to      = w.getAttribute('administrator') 
+    options.mail_from    = w.getAttribute('email') or "%s@%s" % (user, options.hostname)
 
     # log (site) location(s)
     options.logurl      = w.getAttribute('logurl') 
@@ -339,7 +349,7 @@
 
 def send_error_email(Exception,details,options,log):
     """Send an error report by e-mail."""
-    if options.mailserver and options.mailport and options.mailto and options.mailfrom:
+    if options.mail_server and options.mail_server_port and options.mail_to and options.mail_from:
         subject="Fatal error during pygump run [%s: %s]" % (options.hostname, options.name)
         body="""An unexpected error occurred during the pygump run on
 %s (start time: %s, workspace: %s).
@@ -382,8 +392,8 @@
                        Exception, details, options.logurl, logbody)
         
         # send it off
-        _send_email(options.mailfrom, options.mailto, subject, body, options.mailserver,
-                   options.mailport)
+        _send_email(options.mail_from, options.mail_to, subject, body, options.mail_server,
+                   options.mail_server_port)
     else:
         raise Error, "Insufficient information in the workspace for sending e-mail."
 
@@ -435,9 +445,9 @@
     parser = get_parser(_homedir, _hostname, _projects, _workdir, _logdir, _workspace)
     options, args = parser.parse_args()
     
-    options.starttime = time.strftime('%d %b %Y %H:%M:%S', time.localtime())
-    options.starttimeutc = time.strftime('%d %b %Y %H:%M:%S', time.gmtime())
-    
+    options.starttime  = time.strftime('%d %b %Y %H:%M:%S', time.localtime())
+    options.start_time = time.strftime('%d %b %Y %H:%M:%S', time.gmtime())
+
     options.version = GUMP_VERSION
     
     # check for debug info
@@ -463,7 +473,7 @@
             print "       %s" % wingdbstubpath
 
     # create logger
-    log = _Logger(options.logdir)
+    log = _Logger(options.paths_logs)
     
     # fire it up!
     exitcode = 0
@@ -476,9 +486,9 @@
         log.debug("Pygump version %s starting..." % (options.version) )
         log.debug("  (the detailed log is written to %s)" % (log.filename) )
         log.debug('  - hostname           : ' + options.hostname)
-        log.debug('  - homedir            : ' + options.homedir)
+        log.debug('  - homedir            : ' + options.paths_home)
         log.debug('  - current time       : ' + options.starttime)
-        log.debug('  - current time (UTC) : ' + options.starttimeutc)
+        log.debug('  - current time (UTC) : ' + options.start_time)
         log.debug('  - python version     : ' + sys.version)
         log.debug('  - python command     : ' + pythoncmd)
         
@@ -493,16 +503,16 @@
         if not hasattr(options, "projects"):
             log.debug("No projects to build set, defaulting to 'all'")
             options.projects = ["all"]
-        if not os.path.exists(options.workspace):
-            abspath = os.path.join(options.homedir, options.workspace)
+        if not os.path.exists(options.paths_workspace):
+            abspath = os.path.join(options.paths_home, options.paths_workspace)
             if os.path.exists(abspath):
-                options.workspace = abspath
+                options.paths_workspace = abspath
             else:
                 log.error("Workspace not found : %s.\n       Maybe you need to specify --workspace=/absolute/path/to/some/workspace/file.xml?"
% options.workspace)
                 sys.exit(1)
         
         # get some more options from the workspace
-        _parse_workspace(options.workspace, options)
+        _parse_workspace(options.paths_workspace, options)
 
         try:
             # self-update



Mime
View raw message