class BaseConfigTest(unittest.TestCase): """Implements setUp for tests that test the configuration parsing.""" def setUp(self): self.config = CmConfigParser('commitmessage/commitmessage.conf') def testModules(self): """Makes sure the modules are being read in correctly.""" expected = { 'cvsroot': '^/CVSROOT', 'ibm2': '^/ibm2', 'stephen': '^/stephen', 'stephen-misc': '^/stephen/misc', 'module1': '^/'} for name, value in expected.items(): self.assertEquals(value, self.config.get('modules', name)) self.assertEquals(len(expected), len(self.config.options('modules'))) def testViews(self): """Makes sure the views are being read in correctly.""" expected = { 'bombsight': 'commitmessage.views.bugtracking.FogBugzView', 'email': 'commitmessage.views.email.TigrisStyleEmailView', 'dump': 'commitmessage.views.misc.DumpView'} for name, value in expected.items(): self.assertEquals(value, self.config.get('views', name)) self.assertEquals(len(expected), len(self.config.options('views'))) def testGetModulesForPath(self): """Test getting the modules for a given path.""" self.assertEquals(['cvsroot', 'module1'], self.config.getModulesForPath('/CVSROOT/blah/bar.txt')) self.assertEquals(['module1', 'stephen'], self.config.getModulesForPath('/stephen/etc/etc/bar.txt')) self.assertEquals(['module1', 'stephen', 'stephen-misc'], self.config.getModulesForPath('/stephen/misc/bar.txt')) def testGetViewsForModule(self): """Test getting the views for a given module.""" expected = { 'cvsroot': ['email', 'bombsight'], 'stephen': ['email', 'bombsight'], 'ibm2': ['bombsight'], 'module1': ['dump', 'email']} model = Model() for key, value in expected.items(): views = self.config.getViewsForModule(key, model) for view in views: self.assertEquals(1, expected[key].index(view.name) > -1) if view.name == 'email': self.assertEquals('@beachead.com', view.keyword_from()) self.assertEquals(len(expected[key]), len(views))
def main(): profiling, configFile = 0, 'commitmessage.conf' options, args = getopt.getopt(sys.argv[1:], "c:p") for option, value in options: if option == '-c': configFile = value if option == '-p': profiling = 1 if profiling: import hotshot i = 0 while 1: f = currentDir + os.sep + 'commitmessage%s.profile' % i if not os.path.exists(f): break i += 1 profile = hotshot.Profile(f) profile.start() # Handle loading the default conf from within the commitmessage module if configFile[0] != '/' and configFile[0] != '.' and configFile[1] != ':': configFile = rootCmPath + os.sep + configFile config = CmConfigParser(configFile) controller = getNewInstance(config.get('scm', 'controller')) # Remove the -c configFile argument that getopt looks for above and pass on # the rest of the arguments getopt did not grok to the controller cleanArgs = [sys.argv[0]] cleanArgs.extend(args) # getNewInstance does not call the __init__ constructor, so we do controller.__init__(config, cleanArgs, sys.stdin) controller.process() if profiling: profile.stop() profile.close()