Ejemplo n.º 1
0
    def testHelp(self):
        mainHandler = main.RbuildMain()
        mainHandler.registerCommand(FooCommand)
        cmd = helpcommand.HelpCommand()
        cmd.setMainHandler(mainHandler)
        rc, txt = self.captureOutput(cmd.runCommand, None, {},
                                     ['rbuild', 'help'])
        self.assertEquals(rc, 0)
        assert (txt == '''\
rbuild: Conary-based Product Development Tool

Common Commands
  foo   bar

Information Display
  help  Display help information
''')
        rc, txt = self.captureOutput(cmd.runCommand, None, {},
                                     ['rbuild', 'help', 'foo'])
        self.assertEquals(rc, 0)
        txt = txt.replace('usage', 'Usage')  #difference between 2.4/2.5
        txt = txt.replace('options', 'Options')  #difference between 2.4/2.5
        assert (txt == '''\
Usage: rbuild foo 

Long help text goes here

Options:

(Use --verbose to get a full option listing)
''')
        self.assertRaises(SystemExit, self.captureOutput, cmd.runCommand, None,
                          {}, ['rbuild', 'help', 'bam'])
Ejemplo n.º 2
0
    def testUsageByClass(self):
        mainHandler = main.RbuildMain()
        #Test with a regular command
        cmd = mainHandler.getCommand(['rbuild', 'config'], self.rbuildCfg)
        usage = mainHandler._getUsageByClass(cmd)
        self.assertEquals(usage.strip(), 'rbuild config')

        cmd = mainHandler.getCommand(['rbuild', 'init'], self.rbuildCfg)
        usage = mainHandler._getUsageByClass(cmd)
        self.assertEquals(
            usage.strip(),
            'rbuild init <project shortname> <version>\n   or: rbuild init <label>'
        )

        class FakeCommand:
            name = 'bar'
            paramHelp = 'some help'

        cmd = FakeCommand()
        usage = mainHandler._getUsageByClass(cmd)
        self.assertEquals(usage, 'rbuild bar some help')

        cmd = mainHandler.getCommand(['rbuild', 'config'], self.rbuildCfg)
        mainHandler.name = None
        self.assertRaises(AssertionError, mainHandler._getUsageByClass, cmd)
Ejemplo n.º 3
0
    def testInvalidSubCommandHelp(self):
        mainHandler = main.RbuildMain()
        mainHandler.registerCommand(FooSubCommand)
        cmd = helpcommand.HelpCommand()
        cmd.setMainHandler(mainHandler)

        self.assertRaises(SystemExit, self.captureOutput, cmd.runCommand, None,
                          {}, ['rbuild', 'help', 'foo', 'bam'])
Ejemplo n.º 4
0
    def testUpdateCommandNoActiveStage(self):
        mainHandler = main.RbuildMain()
        handle = self._getHandle()
        handle.productStore._mock.set(_currentStage=None)

        cmd = handle.Commands.getCommandClass('update')()
        cmd.setMainHandler(mainHandler)

        self.assertRaises(errors.MissingActiveStageError, cmd.runCommand,
                          handle, {}, ['rbuild', 'update', 'stage'])
Ejemplo n.º 5
0
    def testUpdateCommandNoProductStore(self):
        mainHandler = main.RbuildMain()
        handle = self._getHandle()
        cmd = handle.Commands.getCommandClass('update')()
        cmd.setMainHandler(mainHandler)

        handle.productStore = None

        for subcommand in (None, 'product', 'packages', 'all', 'stage',
                           'stage foo'):
            args = ['rbuild', 'update']
            if subcommand:
                args = args + subcommand.split()
            self.assertRaises(errors.MissingProductStoreError, cmd.runCommand,
                              handle, {}, args)
Ejemplo n.º 6
0
    def testRunCommand(self):
        mainHandler = main.RbuildMain()

        cmd = mainHandler.getCommand(['rbuild', 'help'], self.rbuildCfg)
        productStore = mock.MockObject()
        h = mainHandler.handle
        h.productStore = productStore

        cfg = h.getConfig()
        mock.mock(h.Config, 'isComplete')
        h.Config.isComplete._mock.setReturn(False, cfg)
        mock.mockMethod(h.Config.initializeConfig)
        outputList = []
        rc, txt = self.captureOutput(mainHandler.runCommand, cmd,
                                     self.rbuildCfg, {}, ['rbuild', 'help'])
        h.Config.initializeConfig._mock.assertNotCalled()

        cmd = mainHandler.getCommand(['rbuild', 'build'], self.rbuildCfg)
        self.rbuildCfg.serverUrl = 'some value'
        productStore = mock.MockObject()
        mainHandler.handle.productStore = productStore
        self.checkCall(mainHandler.runCommand,
                       [cmd, self.rbuildCfg, {
                           'stage': 'foo'
                       }, []], {},
                       'rbuild_plugins.build.BuildCommand.runCommand',
                       [cmd, handle.RbuildHandle, {}, []])
        productStore.setActiveStageName._mock.assertCalled('foo')

        class FakeCommand:
            def runCommand(self, handle, argSet, args):
                raise errors.PluginError('eek')

        cmd = FakeCommand()
        h = mainHandler.handle
        h.ui = mock.MockObject()
        self.assertRaises(errors.PluginError, mainHandler.runCommand, cmd,
                          mock.MockObject(), {}, [])
        self.assertEquals(h.ui.popContext._mock.popCall()[0][0],
                          'Command failed with exception %r')
        h.ui.popContext._mock.raiseErrorOnAccess(IOError)
        # Note: not IOError -- the IOError should be ignored and the
        # PluginError should propogate
        self.assertRaises(errors.PluginError, mainHandler.runCommand, cmd,
                          mock.MockObject(), {}, [])
Ejemplo n.º 7
0
    def testInitializeConfig(self):
        mainHandler = main.RbuildMain()
        cmd = mainHandler.getCommand(['rbuild', 'build'], self.rbuildCfg)
        self.rbuildCfg.serverUrl = 'some value'
        productStore = mock.MockObject()
        h = mainHandler.handle
        h.productStore = productStore

        cfg = h.getConfig()
        mock.mock(h.Config, 'isComplete')
        h.Config.isComplete._mock.setReturn(False, cfg)
        mock.mockMethod(h.Config.initializeConfig)
        self.checkCall(mainHandler.runCommand,
                       [cmd, self.rbuildCfg, {
                           'stage': 'foo'
                       }, []], {},
                       'rbuild_plugins.build.BuildCommand.runCommand',
                       [cmd, handle.RbuildHandle, {}, []])
Ejemplo n.º 8
0
    def testUpdateCommandParsing(self):
        mainHandler = main.RbuildMain()
        handle = self._getHandle()
        cmd = handle.Commands.getCommandClass('update')()
        cmd.setMainHandler(mainHandler)
        handle.productStore.update._mock.setDefaultReturn(None)
        mock.mockMethod(handle.Update.updateByCurrentDirectory)
        mock.mockMethod(handle.Update.updateAllStages)
        mock.mockMethod(handle.Update.updateCurrentStage)
        mock.mockMethod(handle.Update.updateStages)
        from rbuild_plugins import update
        mock.mock(update.UpdateCommand, 'usage')

        cmd.runCommand(handle, {}, ['rbuild', 'update'])
        handle.Update.updateByCurrentDirectory._mock.assertCalled()

        cmd.runCommand(handle, {}, ['rbuild', 'update', 'product'])
        handle.productStore.update._mock.assertCalled()

        cmd.runCommand(handle, {}, ['rbuild', 'update', 'packages'])
        handle.Update.updateAllStages._mock.assertCalled()

        cmd.runCommand(handle, {}, ['rbuild', 'update', 'all'])
        handle.productStore.update._mock.assertCalled()
        handle.Update.updateAllStages._mock.assertCalled()

        cmd.runCommand(handle, {}, ['rbuild', 'update', 'stage'])
        handle.Update.updateCurrentStage._mock.assertCalled()

        cmd.runCommand(handle, {}, ['rbuild', 'update', 'stage', 'foo'])
        handle.Update.updateStages._mock.assertCalled(['foo'])

        cmd.runCommand(handle, {}, ['rbuild', 'update', 'stage', 'foo', 'bar'])
        handle.Update.updateStages._mock.assertCalled(['foo', 'bar'])

        # unknown arguments
        cmd.runCommand(handle, {}, ['rbuild', 'update', 'unknown'])
        update.UpdateCommand.usage._mock.assertCalled()
Ejemplo n.º 9
0
    def testNoSubCommandHelp(self):
        '''
        Regression test for APPENG-2736
        '''
        mainHandler = main.RbuildMain()
        mainHandler.registerCommand(FooCommand)
        cmd = helpcommand.HelpCommand()
        cmd.setMainHandler(mainHandler)

        rc, txt = self.captureOutput(cmd.runCommand, None, {},
                                     ['rbuild', 'help', 'foo', 'bar'])
        self.assertEquals(rc, 0)
        txt = txt.replace('usage', 'Usage')  # difference between 2.4/2.5
        txt = txt.replace('options', 'Options')  # difference between 2.4/2.5
        assert (txt == '''\
Usage: rbuild foo 

Long help text goes here

Options:

(Use --verbose to get a full option listing)
''')
Ejemplo n.º 10
0
    def testCommandWithNoDocs(self):
        baseCommand = self.genCommand2()
        subCommand = self.genSubCommand()
        cmd = baseCommand()
        mainHandler = main.RbuildMain()
        mainHandler._registerCommand(baseCommand)
        cmd.setMainHandler(mainHandler)
        baseCommand.registerSubCommand('sub', subCommand)
        _, txt = self.captureOutput(cmd.runCommand, None, {}, ['main'])
        self.assertEquals(
            txt, '''\
%(usage)s: rbuild main <subcommand> [options]



Subcommands:
     sub  executes subcommand

(Use 'rbuild help main <subcommand>' for help on a subcommand)

%(options)s:

(Use --verbose to get a full option listing)
''' % self.optparseDifferences)
Ejemplo n.º 11
0
    def testRegisterCommand(self):
        baseCommand = self.genCommand()
        subCommand = self.genSubCommand()
        cmd = baseCommand()
        mainHandler = main.RbuildMain()
        mainHandler._registerCommand(baseCommand)
        cmd.setMainHandler(mainHandler)
        rc, txt = self.captureOutput(cmd.runCommand, None, {},
                                     ['main', 'sub', 'arg'])
        self.assertEquals(
            txt, '''%(usage)s: rbuild main <subcommand> [options]

My command usage

Subcommands:

(Use 'rbuild help main <subcommand>' for help on a subcommand)

%(options)s:

(Use --verbose to get a full option listing)
''' % self.optparseDifferences)
        assert (rc == 1)
        baseCommand.registerSubCommand('sub', subCommand)
        assert (baseCommand.getSubCommandClass('sub') == subCommand)
        assert (baseCommand.getSubCommandClass('unknownsub') == None)
        cmd = baseCommand()
        cmd.setMainHandler(mainHandler)
        rc, txt = self.captureOutput(cmd.runCommand, None, {}, ['main'])
        mainCommandUsage = '''\
%(usage)s: rbuild main <subcommand> [options]

My command usage

Subcommands:
     sub  executes subcommand

(Use 'rbuild help main <subcommand>' for help on a subcommand)

%(options)s:

(Use --verbose to get a full option listing)
''' % self.optparseDifferences
        self.assertEquals(txt, mainCommandUsage)
        assert (rc == 1)
        rc, txt = self.captureOutput(cmd.runCommand, None, {},
                                     ['main', 'unknownsub'])
        assert (rc == 1)
        self.assertEquals(txt, mainCommandUsage)
        rc, txt = self.captureOutput(cmd.runCommand, None, {},
                                     ['main', 'unknownsub', 'unknownsubsub'])
        assert (rc == 1)
        self.assertEquals(txt, mainCommandUsage)
        rc, txt = self.captureOutput(cmd.runCommand, None, {},
                                     ['rbuild', 'main', 'sub', 'arg'])
        self.assertEquals(rc, 0)
        self.assertEquals(txt, "['main', 'sub', 'arg']\n")

        cmd.setMainHandler(mainHandler)
        rc, txt = self.captureOutput(cmd.runCommand, None, {},
                                     ['rbuild', 'main', 'sub', 'arg', 'arg2'])
        self.assertEquals(rc, 1)
        subCommandUsage = '''\
%(usage)s: rbuild main sub option1 option2

general documentation about sub command

%(options)s:

(Use --verbose to get a full option listing)
''' % self.optparseDifferences
        self.assertEquals(txt, subCommandUsage)

        helpCommand = helpcommand.HelpCommand()
        helpCommand.setMainHandler(mainHandler)
        rc, txt = self.captureOutput(helpCommand.runCommand, None, {},
                                     ['rbuild', 'help', 'main', 'sub'])
        self.assertEquals(txt, subCommandUsage)

        rc, txt = self.captureOutput(helpCommand.runCommand, None, {},
                                     ['rbuild', 'help', 'main'])
        self.assertEquals(txt, mainCommandUsage)
Ejemplo n.º 12
0
 def testGetCommand(self):
     mainHandler = main.RbuildMain()
     cmd = mainHandler.getCommand(['rbuild', 'build'], self.rbuildCfg)
     self.assertEquals(cmd.__class__.__name__, 'BuildCommand')