Permalink
Browse files

Merge pull request #3387 from buildbot/autofix/wrapped2_to3_fix

Fix "Avoid mutable default arguments" issue
  • Loading branch information...
2 parents 7a2cda7 + e20f3f3 commit 119a673276ac843c3ece2d181267df3253ad1c83 @tardyp tardyp committed on GitHub Jul 22, 2017
Showing with 155 additions and 48 deletions.
  1. +3 −1 master/buildbot/config.py
  2. +17 −3 master/buildbot/interfaces.py
  3. +3 −1 master/buildbot/process/factory.py
  4. +9 −3 master/buildbot/test/fake/remotecommand.py
  5. +3 −1 master/buildbot/test/fake/secrets.py
  6. +3 −1 master/buildbot/test/integration/test_upgrade.py
  7. +6 −2 master/buildbot/test/unit/test_config.py
  8. +3 −1 master/buildbot/test/unit/test_data_builds.py
  9. +12 −4 master/buildbot/test/unit/test_data_buildsets.py
  10. +3 −1 master/buildbot/test/unit/test_data_changes.py
  11. +3 −1 master/buildbot/test/unit/test_db_buildrequests.py
  12. +5 −1 master/buildbot/test/unit/test_master.py
  13. +3 −4 master/buildbot/test/unit/test_process_buildrequestdistributor.py
  14. +15 −5 master/buildbot/test/unit/test_process_results.py
  15. +3 −1 master/buildbot/test/unit/test_reporters_mail.py
  16. +8 −2 master/buildbot/test/unit/test_schedulers_base.py
  17. +3 −1 master/buildbot/test/unit/test_schedulers_forcesched.py
  18. +5 −1 master/buildbot/test/unit/test_schedulers_timed_NightlyTriggerable.py
  19. +3 −1 master/buildbot/test/unit/test_schedulers_triggerable.py
  20. +3 −1 master/buildbot/test/unit/test_scripts_checkconfig.py
  21. +3 −1 master/buildbot/test/unit/test_steps_source_p4.py
  22. +11 −3 master/buildbot/test/unit/test_steps_source_repo.py
  23. +7 −1 master/buildbot/test/unit/test_steps_vstudio.py
  24. +3 −1 master/buildbot/test/util/db.py
  25. +3 −1 master/buildbot/test/util/validation.py
  26. +6 −2 master/buildbot/test/util/www.py
  27. +3 −1 master/buildbot/www/hooks/bitbucketserver.py
  28. +6 −2 worker/buildbot_worker/runprocess.py
@@ -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):
@@ -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
@@ -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
@@ -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,
@@ -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
@@ -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.
@@ -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):
@@ -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:
@@ -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
@@ -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,
@@ -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):
@@ -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)
@@ -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)
@@ -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)
@@ -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)
@@ -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'),
@@ -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'),
@@ -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,
@@ -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)
@@ -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)
@@ -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)
@@ -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,
@@ -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})
@@ -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:
@@ -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,
@@ -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:
@@ -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,
@@ -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(
@@ -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')})
@@ -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)
@@ -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)
Oops, something went wrong.

0 comments on commit 119a673

Please sign in to comment.