Skip to content

Commit

Permalink
fix remaining tests
Browse files Browse the repository at this point in the history
  • Loading branch information
djmitche committed Sep 25, 2014
1 parent e54c6fd commit 439f644
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 78 deletions.
12 changes: 11 additions & 1 deletion master/buildbot/process/buildstep.py
Expand Up @@ -386,7 +386,8 @@ def methodInfo(m):

stepResult = summary.get('step', u'finished')
if not isinstance(stepResult, unicode):
raise TypeError("step result string must be unicode")
raise TypeError("step result string must be unicode (got %r)"
% (stepResult,))
yield self.master.data.updates.setStepStateStrings(self.stepid,
[stepResult])

Expand Down Expand Up @@ -1052,6 +1053,9 @@ def makeRemoteShellCommand(self, collectStdout=False, collectStderr=False,
stdio = yield self.addLog(stdioLogName)
kwargs['command'] = flatten(kwargs['command'], (list, tuple))

# store command away for display
self.command = kwargs['command']

# check for the usePTY flag
if kwargs['usePTY'] != 'slave-config':
if self.slaveVersionIsOlderThan("shell", "2.7"):
Expand Down Expand Up @@ -1102,6 +1106,12 @@ def makeRemoteShellCommand(self, collectStdout=False, collectStderr=False,

defer.returnValue(cmd)

def getResultSummary(self):
summary = util.command_to_string(self.command)
if not summary:
return super(ShellMixin, self).getResultSummary()
return {u'step': summary}

# Parses the logs for a list of regexs. Meant to be invoked like:
# regexes = ((re.compile(...), FAILURE), (re.compile(...), WARNINGS))
# self.addStep(ShellCommand,
Expand Down
6 changes: 1 addition & 5 deletions master/buildbot/steps/python_twisted.py
Expand Up @@ -595,13 +595,9 @@ def createSummary(self, loog):
def evaluateCommand(self, cmd):
return self.results

# TODO: better rewrite this as new-style
def getText(self, cmd, results):
def describe(self, done=False):
return self.text

def getText2(self, cmd, results):
return self.text2


class RemovePYCs(ShellCommand):
name = "remove-.pyc"
Expand Down
8 changes: 0 additions & 8 deletions master/buildbot/steps/shellsequence.py
Expand Up @@ -14,7 +14,6 @@
# Copyright Buildbot Team Members

from buildbot import config
from buildbot import util
from buildbot.process import buildstep
from buildbot.status import results
from twisted.internet import defer
Expand Down Expand Up @@ -115,10 +114,3 @@ def runShellSequence(self, commands):

def run(self):
return self.runShellSequence(self.commands)

def getResultSummary(self):
if self.last_command:
summary = util.command_to_string(self.last_command)
if summary:
return {u'step': summary}
return super(ShellSequence, self).getResultSummary()
18 changes: 13 additions & 5 deletions master/buildbot/steps/slave.py
Expand Up @@ -155,11 +155,19 @@ def commandComplete(self, cmd):
self.finished(SUCCESS)

# TODO: BuildStep subclasses don't have a describe()....
def describe(self, done=False):
desc = self.descriptionDone if done else self.description
desc = desc[:]
desc.extend([self.src, "to", self.dest])
return desc
def getResultSummary(self):
src = self.src
if isinstance(src, str):
src = src.decode('ascii', errors='replace')
dest = self.dest
if isinstance(dest, str):
dest = dest.decode('ascii', errors='replace')
copy = u"%s to %s" % (src, dest)
if self.results == SUCCESS:
rv = u'Copied ' + copy
else:
rv = u'Copying ' + copy + ' failed.'
return {u'step': rv}


class RemoveDirectory(SlaveBuildStep):
Expand Down
51 changes: 2 additions & 49 deletions master/buildbot/test/unit/test_process_buildstep.py
Expand Up @@ -251,39 +251,6 @@ def createException(*args, **kwargs):
d.addCallback(lambda _: self.assertTrue(called[0]))
return d

def test_describe(self):
description = ['oogaBooga']
descriptionDone = ['oogaBooga done!']
step = buildstep.BuildStep(description=description,
descriptionDone=descriptionDone)
step.rendered = True
self.assertEqual(step.describe(), description)
self.assertEqual(step.describe(done=True), descriptionDone)

step2 = buildstep.BuildStep()
step2.rendered = True
self.assertEqual(step2.describe(), [step2.name])
self.assertEqual(step2.describe(done=True), [step2.name])

def test_describe_suffix(self):
description = ['oogaBooga']
descriptionDone = ['oogaBooga done!']
descriptionSuffix = ['oogaBooga suffix']

step = buildstep.BuildStep(description=description,
descriptionDone=descriptionDone,
descriptionSuffix=descriptionSuffix)
step.rendered = True
self.assertEqual(step.describe(), description + descriptionSuffix)
self.assertEqual(step.describe(done=True),
descriptionDone + descriptionSuffix)

step2 = buildstep.BuildStep(descriptionSuffix=descriptionSuffix)
step2.rendered = True
self.assertEqual(step2.describe(), [step2.name] + descriptionSuffix)
self.assertEqual(step2.describe(done=True),
[step2.name] + descriptionSuffix)

@defer.inlineCallbacks
def test_step_getLog(self):
testcase = self
Expand Down Expand Up @@ -895,20 +862,6 @@ def test_description(self):
self.expectOutcome(result=SUCCESS, state_string=u"'foo BAR'")
yield self.runStep()

def test_getCommandSummary_long(self):
self.setupStep(SimpleShellCommand(command=['aaa', 'bbb', 'ccc']))
self.assertEqual(self.step._getCommandSummary(), u"'aaa bbb ...'")

def test_getCommandSummary_short(self):
self.setupStep(SimpleShellCommand(command=['aaa']))
self.assertEqual(self.step._getCommandSummary(), u"'aaa'")

def test_getCommandSummary_non_unicode(self):
self.setupStep(SimpleShellCommand(command=['a', 'invalid\xff']))
self.assertEqual(self.step._getCommandSummary(),
u"'a invalid\ufffd'")

def test_getCommandSummary_nested(self):
def test_getResultSummary(self):
self.setupStep(SimpleShellCommand(command=['a', ['b', 'c']]))
self.assertEqual(self.step._getCommandSummary(),
u"'a b ...'")
self.assertEqual(self.step.getResultSummary(), {u'step': u"'a b ...'"})
4 changes: 2 additions & 2 deletions master/buildbot/test/unit/test_steps_http.py
Expand Up @@ -86,7 +86,7 @@ def test_404(self):
self.setupStep(http.GET(url))
self.expectLogfile('log', "URL: %s\n ------ Content ------\n404" % (url, ))
self.expectLogfile('content', "404")
self.expectOutcome(result=FAILURE, state_string="Status code: 404")
self.expectOutcome(result=FAILURE, state_string="Status code: 404 (failure)")
return self.runStep()

def test_POST(self):
Expand All @@ -99,7 +99,7 @@ def test_POST(self):
self.setupStep(http.POST(url))
self.expectLogfile('log', "URL: %s\n ------ Content ------\n%s" % (url, content))
self.expectLogfile('content', content)
self.expectOutcome(result=FAILURE, state_string="Status code: 405")
self.expectOutcome(result=FAILURE, state_string="Status code: 405 (failure)")
return self.runStep()

def test_header(self):
Expand Down
6 changes: 3 additions & 3 deletions master/buildbot/test/unit/test_steps_master.py
Expand Up @@ -84,10 +84,10 @@ def test_real_cmd_interrupted(self):
if runtime.platformType == 'win32':
# windows doesn't have signals, so we don't get 'killed'
self.expectOutcome(result=EXCEPTION,
state_string="failed (1)")
state_string="failed (1) (failure)")
else:
self.expectOutcome(result=EXCEPTION,
state_string="killed (9)")
state_string="killed (9) (exception)")
d = self.runStep()
self.step.interrupt("KILL")
return d
Expand All @@ -97,7 +97,7 @@ def test_real_cmd_fails(self):
self.setupStep(
master.MasterShellCommand(command=cmd))
self.expectLogfile('stdio', "")
self.expectOutcome(result=FAILURE, state_string="failed (1)")
self.expectOutcome(result=FAILURE, state_string="failed (1) (failure)")
return self.runStep()

def test_constr_args(self):
Expand Down
3 changes: 3 additions & 0 deletions master/buildbot/test/unit/test_steps_mswin.py
Expand Up @@ -15,6 +15,7 @@

from buildbot.status.results import EXCEPTION
from buildbot.status.results import FAILURE
from buildbot.status.results import Results
from buildbot.status.results import SUCCESS
from buildbot.status.results import WARNINGS
from buildbot.steps import mswin
Expand Down Expand Up @@ -54,6 +55,8 @@ def _run_simple_test(self, source, destination, expected_args=None, expected_cod
+ expected_code
)
state_string = "'robocopy %s ...'" % source
if expected_res != SUCCESS:
state_string += ' (%s)' % (Results[expected_res])
self.expectOutcome(result=expected_res, state_string=state_string)
return self.runStep()

Expand Down
Expand Up @@ -39,7 +39,7 @@ def test_success(self):
ExpectShell(workdir='wkdir', usePTY='slave-config',
command=['lintian', '-v', 'foo_0.23_i386.changes'])
+ 0)
self.expectOutcome(result=SUCCESS, state_string="'lintian -v ...'")
self.expectOutcome(result=SUCCESS, state_string="Lintian")
return self.runStep()

def test_success_suppressTags(self):
Expand Down
5 changes: 3 additions & 2 deletions master/buildbot/test/unit/test_steps_python.py
Expand Up @@ -434,7 +434,8 @@ def test_failure(self):
stdout='oh noes!')
+ 1
)
self.expectOutcome(result=FAILURE, state_string="sphinx 0 warnings")
self.expectOutcome(result=FAILURE,
state_string="sphinx 0 warnings (failure)")
return self.runStep()

def test_nochange(self):
Expand All @@ -460,7 +461,7 @@ def test_warnings(self):
+ 0
)
self.expectOutcome(result=WARNINGS,
state_string="sphinx 2 warnings")
state_string="sphinx 2 warnings (warnings)")
self.expectLogfile("warnings", warnings)
d = self.runStep()

Expand Down
4 changes: 2 additions & 2 deletions master/buildbot/test/unit/test_steps_python_twisted.py
Expand Up @@ -195,7 +195,7 @@ def test_run_failure(self):
+ ExpectShell.log('stdio', stdout=failureLog)
+ 1
)
self.expectOutcome(result=FAILURE, state_string='tests 8 failures')
self.expectOutcome(result=FAILURE, state_string='tests 8 failures (failure)')
self.expectLogfile('problems', failureLog.split('\n\n', 1)[1])
self.expectLogfile('warnings', textwrap.dedent('''\
buildbot.test.unit.test_steps_python_twisted.Trial.test_run_env_nodupe ... [FAILURE]/home/dustin/code/buildbot/t/buildbot/master/buildbot/test/fake/logfile.py:92: UserWarning: step uses removed LogFile method `getText`
Expand Down Expand Up @@ -315,5 +315,5 @@ def test_run_warnings(self):
+ 0
)
self.expectLogfile('warnings', 'colon: meaning warning')
self.expectOutcome(result=WARNINGS, state_string='hlint warnings')
self.expectOutcome(result=WARNINGS, state_string='hlint (warnings)')
return self.runStep()
4 changes: 4 additions & 0 deletions master/docs/developer/cls-buildsteps.rst
Expand Up @@ -620,6 +620,10 @@ This class can only be used in new-style steps.

All that remains is to run the command with :py:meth:`~buildbot.process.buildstep.BuildStep.runCommand`.

The :py:class:`ShellMixin` class implements :py:meth:`~buildbot.process.buildstep.BuildStep.getResultSummary`, returning a summary of the command.
If no command was specified or run, it falls back to the default ``getResultSummary`` based on ``descriptionDone``.
Subclasses can override this method to return a more appropriate status.

Exceptions
----------

Expand Down

0 comments on commit 439f644

Please sign in to comment.