Skip to content

Commit

Permalink
Merge pull request #3387 from buildbot/autofix/wrapped2_to3_fix
Browse files Browse the repository at this point in the history
Fix "Avoid mutable default arguments" issue
  • Loading branch information
tardyp committed Jul 22, 2017
2 parents 7a2cda7 + e20f3f3 commit 119a673
Show file tree
Hide file tree
Showing 28 changed files with 155 additions and 48 deletions.
4 changes: 3 additions & 1 deletion master/buildbot/config.py
Expand Up @@ -54,7 +54,9 @@

class ConfigErrors(Exception):

def __init__(self, errors=[]):
def __init__(self, errors=None):
if errors is None:
errors = []
self.errors = errors[:]

def __str__(self):
Expand Down
20 changes: 17 additions & 3 deletions master/buildbot/interfaces.py
Expand Up @@ -396,7 +396,7 @@ def getBuildSets():
@returns: list of L{IBuildSetStatus} implementations, via Deferred.
"""

def generateFinishedBuilds(builders=[], branches=[],
def generateFinishedBuilds(builders=None, branches=None,
num_builds=None, finished_before=None,
max_search=200):
"""Return a generator that will produce IBuildStatus objects each
Expand Down Expand Up @@ -429,6 +429,10 @@ def generateFinishedBuilds(builders=[], branches=[],
of builds that will be examined within any given
Builder.
"""
if builders is None:
builders = []
if branches is None:
branches = []

def subscribe(receiver):
"""Register an IStatusReceiver to receive new status events. The
Expand Down Expand Up @@ -614,7 +618,7 @@ def getEvent(number):
getEvent(-1) will return the most recent event. Events are numbered,
but it probably doesn't make sense to ever do getEvent(+n)."""

def generateFinishedBuilds(branches=[],
def generateFinishedBuilds(branches=None,
num_builds=None,
max_buildnum=None, finished_before=None,
max_search=200,
Expand Down Expand Up @@ -655,6 +659,8 @@ def generateFinishedBuilds(branches=[],
This argument imposes a hard limit on the number
of builds that will be examined.
"""
if branches is None:
branches = []

def subscribe(receiver):
"""Register an IStatusReceiver to receive new status events. The
Expand All @@ -668,7 +674,7 @@ def unsubscribe(receiver):

class IEventSource(Interface):

def eventGenerator(branches=[], categories=[], committers=[], projects=[], minTime=0):
def eventGenerator(branches=None, categories=None, committers=None, projects=None, minTime=0):
"""This function creates a generator which will yield all of this
object's status events, starting with the most recent and progressing
backwards in time. These events provide the IStatusEvent interface.
Expand All @@ -692,6 +698,14 @@ def eventGenerator(branches=[], categories=[], committers=[], projects=[], minTi
@param minTime: a timestamp. Do not generate events occurring prior to
this timestamp.
"""
if branches is None:
branches = []
if categories is None:
categories = []
if committers is None:
committers = []
if projects is None:
projects = []


class IBuildStatus(Interface):
Expand Down
4 changes: 3 additions & 1 deletion master/buildbot/process/factory.py
Expand Up @@ -82,7 +82,9 @@ def addStep(self, step, **kwargs):
step = step(**kwargs)
self.steps.append(interfaces.IBuildStepFactory(step))

def addSteps(self, steps, withSecrets=[]):
def addSteps(self, steps, withSecrets=None):
if withSecrets is None:
withSecrets = []
if withSecrets:
self.addStep(DownloadSecretsToWorker(withSecrets))
for s in steps:
Expand Down
12 changes: 9 additions & 3 deletions master/buildbot/test/fake/remotecommand.py
Expand Up @@ -153,13 +153,15 @@ def custom_behavior(command):
"""

def __init__(self, remote_command, args, incomparable_args=[]):
def __init__(self, remote_command, args, incomparable_args=None):
"""
Expect a command named C{remote_command}, with args C{args}. Any args
in C{incomparable_args} are not cmopared, but must exist.
"""
if incomparable_args is None:
incomparable_args = []
self.remote_command = remote_command
self.incomparable_args = incomparable_args
self.args = args
Expand Down Expand Up @@ -304,10 +306,14 @@ class ExpectShell(Expect):
non-default arguments must be specified explicitly (e.g., usePTY).
"""

def __init__(self, workdir, command, env={},
def __init__(self, workdir, command, env=None,
want_stdout=1, want_stderr=1, initialStdin=None,
timeout=20 * 60, maxTime=None, logfiles={},
timeout=20 * 60, maxTime=None, logfiles=None,
usePTY=None, logEnviron=True):
if env is None:
env = {}
if logfiles is None:
logfiles = {}
args = dict(workdir=workdir, command=command, env=env,
want_stdout=want_stdout, want_stderr=want_stderr,
initial_stdin=initialStdin,
Expand Down
4 changes: 3 additions & 1 deletion master/buildbot/test/fake/secrets.py
Expand Up @@ -8,7 +8,9 @@ class FakeSecretStorage(SecretProviderBase):

name = "SecretsInFake"

def reconfigService(self, secretdict={}):
def reconfigService(self, secretdict=None):
if secretdict is None:
secretdict = {}
self.allsecrets = secretdict

def get(self, key):
Expand Down
4 changes: 3 additions & 1 deletion master/buildbot/test/integration/test_upgrade.py
Expand Up @@ -198,7 +198,9 @@ def gotError(self, e):
% str(e))
return e

def do_test_upgrade(self, pre_callbacks=[]):
def do_test_upgrade(self, pre_callbacks=None):
if pre_callbacks is None:
pre_callbacks = []
d = defer.succeed(None)
for cb in pre_callbacks:
d.addCallback(cb)
Expand Down
8 changes: 6 additions & 2 deletions master/buildbot/test/unit/test_config.py
Expand Up @@ -160,7 +160,9 @@ def setUp(self):
def tearDown(self):
return self.tearDownDirs()

def install_config_file(self, config_file, other_files={}):
def install_config_file(self, config_file, other_files=None):
if other_files is None:
other_files = {}
config_file = textwrap.dedent(config_file)
with open(os.path.join(self.basedir, self.filename), "w") as f:
f.write(config_file)
Expand Down Expand Up @@ -270,7 +272,9 @@ def patch_load_helpers(self):
self.patch(config.MasterConfig, n,
mock.Mock(side_effect=lambda: None))

def install_config_file(self, config_file, other_files={}):
def install_config_file(self, config_file, other_files=None):
if other_files is None:
other_files = {}
config_file = textwrap.dedent(config_file)
with open(os.path.join(self.basedir, self.filename), "w") as f:
f.write(config_file)
Expand Down
4 changes: 3 additions & 1 deletion master/buildbot/test/unit/test_data_builds.py
Expand Up @@ -270,8 +270,10 @@ def do_test_callthrough(self, dbMethodName, method, exp_args=None,
m.assert_called_with(*(exp_args or args), **(exp_kwargs or kwargs))

@defer.inlineCallbacks
def do_test_event(self, method, exp_events=[],
def do_test_event(self, method, exp_events=None,
*args, **kwargs):
if exp_events is None:
exp_events = []
self.patch(reactor, "seconds", lambda: 1)
yield method(*args, **kwargs)
self.master.mq.assertProductions(exp_events)
Expand Down
16 changes: 12 additions & 4 deletions master/buildbot/test/unit/test_data_buildsets.py
Expand Up @@ -227,8 +227,10 @@ def _buildRequestMessage3(self, brid, bsid, builderid):
self._buildRequestMessageDict(brid, bsid, builderid))

def _buildsetMessage(self, bsid, external_idstring=u'extid',
reason=u'because', scheduler=u'fakesched', sourcestampids=[234],
reason=u'because', scheduler=u'fakesched', sourcestampids=None,
submitted_at=A_TIMESTAMP):
if sourcestampids is None:
sourcestampids = [234]
ssmap = {234: self.SS234_DATA}
return (
('buildsets', str(bsid), 'new'),
Expand All @@ -240,7 +242,9 @@ def _buildsetMessage(self, bsid, external_idstring=u'extid',

def _buildsetCompleteMessage(self, bsid, complete_at=A_TIMESTAMP_EPOCH,
submitted_at=A_TIMESTAMP_EPOCH, external_idstring=u'extid',
reason=u'because', results=0, sourcestampids=[234]):
reason=u'because', results=0, sourcestampids=None):
if sourcestampids is None:
sourcestampids = [234]
ssmap = {234: self.SS234_DATA}
return (
('buildsets', str(bsid), 'complete'),
Expand Down Expand Up @@ -301,8 +305,8 @@ def maybeBuildsetComplete(self, bsid):

@defer.inlineCallbacks
def do_test_maybeBuildsetComplete(self,
buildRequestCompletions={},
buildRequestResults={},
buildRequestCompletions=None,
buildRequestResults=None,
buildsetComplete=False,
expectComplete=False,
expectMessage=False,
Expand All @@ -328,6 +332,10 @@ def do_test_maybeBuildsetComplete(self,
Then, maybeBuildsetComplete is called for buildset 72, and the
expectations are checked.
"""
if buildRequestCompletions is None:
buildRequestCompletions = {}
if buildRequestResults is None:
buildRequestResults = {}

clock = task.Clock()
clock.advance(A_TIMESTAMP)
Expand Down
4 changes: 3 additions & 1 deletion master/buildbot/test/unit/test_data_changes.py
Expand Up @@ -170,7 +170,9 @@ def addChange(self, files=None, comments=None, author=None,

def do_test_addChange(self, kwargs,
expectedRoutingKey, expectedMessage, expectedRow,
expectedChangeUsers=[]):
expectedChangeUsers=None):
if expectedChangeUsers is None:
expectedChangeUsers = []
clock = task.Clock()
clock.advance(10000000)
d = self.rtype.addChange(_reactor=clock, **kwargs)
Expand Down
4 changes: 3 additions & 1 deletion master/buildbot/test/unit/test_db_buildrequests.py
Expand Up @@ -495,8 +495,10 @@ def check(results):
return d

def do_test_completeBuildRequests(self, rows, now, expected=None,
expfailure=None, brids=[44],
expfailure=None, brids=None,
complete_at=None):
if brids is None:
brids = [44]
clock = task.Clock()
clock.advance(now)

Expand Down
6 changes: 5 additions & 1 deletion master/buildbot/test/unit/test_master.py
Expand Up @@ -80,8 +80,12 @@ def fromChdict(master, chdict):
return defer.succeed(self.fake_Change)
self.patch(Change, 'fromChdict', staticmethod(fromChdict))

def do_test_addChange_args(self, args=(), kwargs={}, exp_data_kwargs={}):
def do_test_addChange_args(self, args=(), kwargs=None, exp_data_kwargs=None):
# add default arguments
if kwargs is None:
kwargs = {}
if exp_data_kwargs is None:
exp_data_kwargs = {}
default_data_kwargs = {
'author': None,
'branch': None,
Expand Down
Expand Up @@ -683,12 +683,11 @@ def test_bldr_maybeStartBuild_fails_once(self):
self.bldr.config.nextWorker = nth_worker(-1)
# the builder fails to start the build; we'll see that the build
# was requested, but the brids will get claimed again
start_build_results = [False, True, True]

def maybeStartBuild(worker, builds, _fail=[False]):
def maybeStartBuild(worker, builds):
self.startedBuilds.append((worker.name, builds))
ret = _fail[0]
_fail[0] = True
return defer.succeed(ret)
return defer.succeed(start_build_results.pop(0))
self.bldr.maybeStartBuild = maybeStartBuild

self.addWorkers({'test-worker1': 1, 'test-worker2': 1})
Expand Down
20 changes: 15 additions & 5 deletions master/buildbot/test/unit/test_process_results.py
Expand Up @@ -51,11 +51,21 @@ def test_sort_worst_status(self):
])

def do_test_carc(self, result, previousResult, newResult, terminate,
haltOnFailure=[True, False], flunkOnWarnings=[
True, False],
flunkOnFailure=[True, False], warnOnWarnings=[
True, False],
warnOnFailure=[True, False]):
haltOnFailure=None, flunkOnWarnings=None,
flunkOnFailure=None, warnOnWarnings=None,
warnOnFailure=None):
if haltOnFailure is None:
haltOnFailure = [True, False]
if flunkOnWarnings is None:
flunkOnWarnings = [
True, False]
if flunkOnFailure is None:
flunkOnFailure = [True, False]
if warnOnWarnings is None:
warnOnWarnings = [
True, False]
if warnOnFailure is None:
warnOnFailure = [True, False]
for hof in haltOnFailure:
for fow in flunkOnWarnings:
for fof in flunkOnFailure:
Expand Down
4 changes: 3 additions & 1 deletion master/buildbot/test/unit/test_reporters_mail.py
Expand Up @@ -220,10 +220,12 @@ def test_buildMessage(self):
self.assertEqual(mn.createEmail.call_count, 1)

@defer.inlineCallbacks
def do_test_sendToInterestedUsers(self, lookup=None, extraRecipients=[],
def do_test_sendToInterestedUsers(self, lookup=None, extraRecipients=None,
sendToInterestedUsers=True,
exp_called_with=None, exp_TO=None,
exp_CC=None):
if extraRecipients is None:
extraRecipients = []
_, builds = yield self.setupBuildResults(SUCCESS)

mn = yield self.setupMailNotifier('from@example.org', lookup=lookup, extraRecipients=extraRecipients,
Expand Down
10 changes: 8 additions & 2 deletions master/buildbot/test/unit/test_schedulers_base.py
Expand Up @@ -43,8 +43,14 @@ def setUp(self):
def tearDown(self):
self.tearDownScheduler()

def makeScheduler(self, name='testsched', builderNames=['a', 'b'],
properties={}, codebases={'': {}}):
def makeScheduler(self, name='testsched', builderNames=None,
properties=None, codebases=None):
if builderNames is None:
builderNames = ['a', 'b']
if properties is None:
properties = {}
if codebases is None:
codebases = {'': {}}
dbBuilder = list()
builderid = 0
for builderName in builderNames:
Expand Down
4 changes: 3 additions & 1 deletion master/buildbot/test/unit/test_schedulers_forcesched.py
Expand Up @@ -54,8 +54,10 @@ def setUp(self):
def tearDown(self):
self.tearDownScheduler()

def makeScheduler(self, name='testsched', builderNames=['a', 'b'],
def makeScheduler(self, name='testsched', builderNames=None,
**kw):
if builderNames is None:
builderNames = ['a', 'b']
sched = self.attachScheduler(
ForceScheduler(name=name, builderNames=builderNames, **kw),
self.OBJECTID, self.SCHEDULERID,
Expand Down
Expand Up @@ -57,7 +57,11 @@ def tearDown(self):

# utilities

def assertBuildsetAdded(self, sourcestamps={}, properties={}):
def assertBuildsetAdded(self, sourcestamps=None, properties=None):
if sourcestamps is None:
sourcestamps = {}
if properties is None:
properties = {}
properties['scheduler'] = ('test', u'Scheduler')
self.assertEqual(self.addBuildsetCalls, [
('addBuildsetForSourceStampsWithDefaults', dict(
Expand Down
4 changes: 3 additions & 1 deletion master/buildbot/test/unit/test_schedulers_triggerable.py
Expand Up @@ -71,7 +71,9 @@ def makeScheduler(self, overrideBuildsetMethods=False, **kwargs):
return sched

@defer.inlineCallbacks
def assertTriggeredBuildset(self, idsDeferred, waited_for, properties={}, sourcestamps=None):
def assertTriggeredBuildset(self, idsDeferred, waited_for, properties=None, sourcestamps=None):
if properties is None:
properties = {}
bsid, brids = yield idsDeferred
properties.update({u'scheduler': ('n', u'Scheduler')})

Expand Down
4 changes: 3 additions & 1 deletion master/buildbot/test/unit/test_scripts_checkconfig.py
Expand Up @@ -44,8 +44,10 @@ def tearDown(self):

# tests

def do_test_load(self, config='', other_files={},
def do_test_load(self, config='', other_files=None,
stdout_re=None, stderr_re=None):
if other_files is None:
other_files = {}
configFile = os.path.join(self.configdir, 'master.cfg')
with open(configFile, "w") as f:
f.write(config)
Expand Down
4 changes: 3 additions & 1 deletion master/buildbot/test/unit/test_steps_source_p4.py
Expand Up @@ -45,7 +45,9 @@ def setUp(self):
def tearDown(self):
return self.tearDownSourceStep()

def setupStep(self, step, args={}, patch=None, **kwargs):
def setupStep(self, step, args=None, patch=None, **kwargs):
if args is None:
args = {}
step = sourcesteps.SourceStepMixin.setupStep(
self, step, args={}, patch=None, **kwargs)
self.build.getSourceStamp().revision = args.get('revision', None)
Expand Down

0 comments on commit 119a673

Please sign in to comment.