Skip to content

Commit

Permalink
test: fix default value for additional param
Browse files Browse the repository at this point in the history
In Python, the default values of parameters are evaluated only once
during their declaration. So, whenever the default parameter is used
the same object will be used. Since we use a list, which is a mutable
object, this could lead to unexpected results.

PR-URL: #2553
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
  • Loading branch information
thefourtheye committed Sep 15, 2015
1 parent b981364 commit 52f84ad
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions test/testpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,19 @@

class SimpleTestCase(test.TestCase):

def __init__(self, path, file, arch, mode, context, config, additional=[]):
def __init__(self, path, file, arch, mode, context, config, additional=None):
super(SimpleTestCase, self).__init__(context, path, arch, mode)
self.file = file
self.config = config
self.arch = arch
self.mode = mode
self.tmpdir = join(dirname(self.config.root), 'tmp')
self.additional_flags = additional
if additional is not None:
self.additional_flags = additional
else:
self.additional_flags = []



def GetLabel(self):
return "%s %s" % (self.mode, self.GetName())

Expand Down Expand Up @@ -81,10 +84,13 @@ def GetSource(self):

class SimpleTestConfiguration(test.TestConfiguration):

def __init__(self, context, root, section, additional=[]):
def __init__(self, context, root, section, additional=None):
super(SimpleTestConfiguration, self).__init__(context, root)
self.section = section
self.additional_flags = additional
if additional is not None:
self.additional_flags = additional
else:
self.additional_flags = []

def Ls(self, path):
def SelectTest(name):
Expand All @@ -110,7 +116,7 @@ def GetTestStatus(self, sections, defs):
test.ReadConfigurationInto(status_file, sections, defs)

class ParallelTestConfiguration(SimpleTestConfiguration):
def __init__(self, context, root, section, additional=[]):
def __init__(self, context, root, section, additional=None):
super(ParallelTestConfiguration, self).__init__(context, root, section,
additional)

Expand All @@ -122,8 +128,8 @@ def ListTests(self, current_path, path, arch, mode):
return result

class AddonTestConfiguration(SimpleTestConfiguration):
def __init__(self, context, root, section, additional=[]):
super(AddonTestConfiguration, self).__init__(context, root, section)
def __init__(self, context, root, section, additional=None):
super(AddonTestConfiguration, self).__init__(context, root, section, additional)

def Ls(self, path):
def SelectTest(name):
Expand Down

0 comments on commit 52f84ad

Please sign in to comment.