Browse Source

test: fix default value for additional param

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: https://github.com/nodejs/node/pull/2553
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
v5.x
Sakthipriyan Vairamani 9 years ago
parent
commit
52f84add77
  1. 16
      test/testpy/__init__.py

16
test/testpy/__init__.py

@ -40,14 +40,17 @@ FILES_PATTERN = re.compile(r"//\s+Files:(.*)")
class SimpleTestCase(test.TestCase): 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) super(SimpleTestCase, self).__init__(context, path, arch, mode)
self.file = file self.file = file
self.config = config self.config = config
self.arch = arch self.arch = arch
self.mode = mode self.mode = mode
self.tmpdir = join(dirname(self.config.root), 'tmp') self.tmpdir = join(dirname(self.config.root), 'tmp')
if additional is not None:
self.additional_flags = additional self.additional_flags = additional
else:
self.additional_flags = []
def GetLabel(self): def GetLabel(self):
@ -81,10 +84,13 @@ class SimpleTestCase(test.TestCase):
class SimpleTestConfiguration(test.TestConfiguration): 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) super(SimpleTestConfiguration, self).__init__(context, root)
self.section = section self.section = section
if additional is not None:
self.additional_flags = additional self.additional_flags = additional
else:
self.additional_flags = []
def Ls(self, path): def Ls(self, path):
def SelectTest(name): def SelectTest(name):
@ -110,7 +116,7 @@ class SimpleTestConfiguration(test.TestConfiguration):
test.ReadConfigurationInto(status_file, sections, defs) test.ReadConfigurationInto(status_file, sections, defs)
class ParallelTestConfiguration(SimpleTestConfiguration): 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, super(ParallelTestConfiguration, self).__init__(context, root, section,
additional) additional)
@ -122,8 +128,8 @@ class ParallelTestConfiguration(SimpleTestConfiguration):
return result return result
class AddonTestConfiguration(SimpleTestConfiguration): class AddonTestConfiguration(SimpleTestConfiguration):
def __init__(self, context, root, section, additional=[]): def __init__(self, context, root, section, additional=None):
super(AddonTestConfiguration, self).__init__(context, root, section) super(AddonTestConfiguration, self).__init__(context, root, section, additional)
def Ls(self, path): def Ls(self, path):
def SelectTest(name): def SelectTest(name):

Loading…
Cancel
Save