Пример #1
0
    def testCreateApp(self):
        #this is minimal logconfig that python's logger seems to accept:
        app = vesper.app.createApp(static_path=['static'], 
          logconfig = '''
          [loggers]
          keys=root

          [handlers]
          keys=hand01

          [formatters]
          keys=form01

          [logger_root]
          level=DEBUG
          handlers=hand01

          [handler_hand01]
          class=StreamHandler
          level=NOTSET
          formatter=form01
          args=(sys.stdout,)

          [formatter_form01]
          format=%(asctime)s %(levelname)s %(name)s %(message)s
          datefmt=%d %b %H:%M:%S
          '''
        )
        root = app.load()
        self.failUnless(root)
        
        cmdline = ['-x', '--foo=bar', '--transaction_log=test.log', '-fname', '-c', 'test.config']
        app = vesper.app.createApp()
        root = app.run(cmdline=cmdline)
        self.assertEquals(app.foo, 'bar')
        self.assertEquals(app.baz, 1)
        self.assertEquals(app.f, 'name')
        self.assertEquals(root.defaultStore.transaction_log, 'test.log')
        
        #test trying to loading a store with the wrong kind of file
        cmdline = ['-s', 'test.config']
        app = vesper.app.createApp()
        from vesper.data.base.utils import ParseException
        try:
            root = app.run(cmdline=cmdline)
        except ParseException, e: 
            #XXX should report better error message when failing to load store
            self.assertEquals(str(e), 'unrecognized or invalid file contents')
Пример #2
0
    def testCreateApp(self):
        #this is minimal logconfig that python's logger seems to accept:
        app = vesper.app.createApp(static_path=['static'], 
          logconfig = '''
          [loggers]
          keys=root

          [handlers]
          keys=hand01

          [formatters]
          keys=form01

          [logger_root]
          level=DEBUG
          handlers=hand01

          [handler_hand01]
          class=StreamHandler
          level=NOTSET
          formatter=form01
          args=(sys.stdout,)

          [formatter_form01]
          format=%(asctime)s %(levelname)s %(name)s %(message)s
          datefmt=%d %b %H:%M:%S
          '''
        )
        root = app.load()
        self.failUnless(root)
        
        cmdline = ['-x', '--foo=bar', '--transaction_log=test.log', '-fname', '-c', 'test.config']
        called = False
        @vesper.app.Command("foo")
        def testCmdFoo(kw, retVal):
            self.assertEquals(kw._params.foo, 'bar')
            self.assertEquals(kw._params.f, 'name')
            kw.__server__.testCmdCalled = True

        @vesper.app.Command("bar")
        def testCmdBar(kw, retVal):
            self.fail("shouldn't have been called")
            return retVal

        app = vesper.app.createApp(actions = {
            'run-cmds' : [testCmdFoo, testCmdBar, lambda x,y: y],
        })
        root = app.run(cmdline=cmdline)
        self.assertEquals(app.foo, 'bar')
        self.assertEquals(app.baz, 1)
        self.assertEquals(app.f, 'name')
        self.assertEquals(root.defaultStore.transaction_log, 'test.log')
        self.failUnless(root.testCmdCalled ) 
        
        #test trying to loading a store with the wrong kind of file
        cmdline = ['-s', 'test.config']
        app = vesper.app.createApp()
        from vesper.data.base.utils import ParseException
        try:
            root = app.run(cmdline=cmdline)
        except ParseException, e: 
            #XXX should report better error message when failing to load store
            self.assertEquals(str(e), 'unrecognized or invalid file contents')