Skip to content

Commit

Permalink
fix bugs in handling unkown return codes, pyflakes
Browse files Browse the repository at this point in the history
..and return Deferreds from test methods.
  • Loading branch information
djmitche committed Aug 10, 2013
1 parent 44c52eb commit f465a19
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
5 changes: 2 additions & 3 deletions master/buildbot/steps/mswin.py
Expand Up @@ -14,10 +14,9 @@
# Copyright Buildbot Team Members

from twisted.python import log
from twisted.python.failure import Failure

from buildbot.steps.shell import ShellCommand
from buildbot.status.results import SUCCESS, WARNINGS, FAILURE
from buildbot.status.results import SUCCESS, WARNINGS, FAILURE, EXCEPTION


class Robocopy(ShellCommand):
Expand Down Expand Up @@ -83,5 +82,5 @@ def evaluateCommand(self, cmd):
if (cmd.rc & flag) == flag:
return result

log.err(Failure(), "Unknown return code for Robocopy: %s" % cmd.rc)
log.msg("Unknown return code for Robocopy: %s" % cmd.rc)
return EXCEPTION
2 changes: 0 additions & 2 deletions master/buildbot/test/unit/test_changes_p4poller.py
Expand Up @@ -13,12 +13,10 @@
#
# Copyright Buildbot Team Members

import time
import datetime
from twisted.trial import unittest
from buildbot.changes.p4poller import P4Source, get_simple_split, P4PollerError
from buildbot.test.util import changesource, gpo
from buildbot.util import epoch2datetime

first_p4changes = \
"""Change 1 on 2006/04/13 by slamb@testclient 'first rev'
Expand Down
33 changes: 20 additions & 13 deletions master/buildbot/test/unit/test_steps_mswin.py
Expand Up @@ -13,14 +13,12 @@
#
# Copyright Buildbot Team Members

from buildbot.status.results import SUCCESS, FAILURE, WARNINGS
from buildbot.status.results import SUCCESS, FAILURE, WARNINGS, EXCEPTION
from buildbot.steps import mswin
from buildbot.test.fake.remotecommand import ExpectShell
from buildbot.test.util import steps
from twisted.trial import unittest
from buildbot.process.properties import Property

from mock import Mock
from twisted.internet import defer


class TestRobocopySimple(steps.BuildStepMixin, unittest.TestCase):
Expand Down Expand Up @@ -56,59 +54,68 @@ def _run_simple_test(self, source, destination, expected_args=None, expected_cod
status_text.append('warnings')
elif expected_res == FAILURE:
status_text.append('failed')
elif expected_res == EXCEPTION:
status_text.append('exception')
self.expectOutcome(result=expected_res, status_text=status_text)
return self.runStep()

def test_copy(self):
self._run_simple_test('D:\source', 'E:\dest')
return self._run_simple_test('D:\source', 'E:\dest')

def test_copy_files(self):
self._run_simple_test(
return self._run_simple_test(
'D:\source', 'E:\dest', files=['a.txt', 'b.txt', '*.log'],
expected_args=['a.txt', 'b.txt', '*.log']
)

def test_copy_recursive(self):
self._run_simple_test(
return self._run_simple_test(
'D:\source', 'E:\dest', recursive=True,
expected_args=['/E']
)

def test_mirror_files(self):
self._run_simple_test(
return self._run_simple_test(
'D:\source', 'E:\dest', files=['*.foo'], mirror=True,
expected_args=['*.foo', '/MIR']
)

def test_move_files(self):
self._run_simple_test(
return self._run_simple_test(
'D:\source', 'E:\dest', files=['*.foo'], move=True,
expected_args=['*.foo', '/MOVE']
)

def test_exclude(self):
self._run_simple_test(
return self._run_simple_test(
'D:\source', 'E:\dest', files=['blah*'], exclude=['*.foo', '*.bar'],
expected_args=['blah*', '/XF', '*.foo', '*.bar']
)

@defer.inlineCallbacks
def test_codes(self):
# Codes that mean uneventful copies (including no copy at all).
for i in [0, 1]:
self._run_simple_test(
yield self._run_simple_test(
'D:\source', 'E:\dest', expected_code=i,
expected_res=SUCCESS
)

# Codes that mean some mismatched or extra files were found.
for i in range(2, 8):
self._run_simple_test(
yield self._run_simple_test(
'D:\source', 'E:\dest', expected_code=i,
expected_res=WARNINGS
)
# Codes that mean errors have been encountered.
for i in range(8, 32):
self._run_simple_test(
yield self._run_simple_test(
'D:\source', 'E:\dest', expected_code=i,
expected_res=FAILURE
)

# bit 32 is meaningless
yield self._run_simple_test(
'D:\source', 'E:\dest', expected_code=32,
expected_res=EXCEPTION
)
5 changes: 2 additions & 3 deletions master/buildbot/test/unit/test_steps_source_p4.py
Expand Up @@ -15,16 +15,15 @@
# Portions Copyright 2013 Bad Dog Consulting


import textwrap
import platform
from twisted.trial import unittest
from buildbot.steps.source.p4 import P4
from buildbot.status.results import SUCCESS
from buildbot.test.util import sourcesteps
from buildbot.test.util.properties import ConstantRenderable
from buildbot.test.fake.remotecommand import ExpectShell, Expect
from buildbot import config
import textwrap
import os.path
import platform

_is_windows = (platform.system() == 'Windows')

Expand Down

0 comments on commit f465a19

Please sign in to comment.