Commit b5b85225 authored by ale's avatar ale
Browse files

Fix parameterization of probes

Context was not being copied correctly, so all parameterized probes
got the last attribute value.

Fixes issue #1.
parent 14bd1e56
Pipeline #6176 passed with stages
in 2 minutes and 8 seconds
...@@ -13,6 +13,9 @@ except ImportError: ...@@ -13,6 +13,9 @@ except ImportError:
class Context(dict): class Context(dict):
def copy(self):
return Context(self.items())
def with_logger(self, name, buffer): def with_logger(self, name, buffer):
ctx = Context(self.items()) ctx = Context(self.items())
h = logging.StreamHandler(buffer) h = logging.StreamHandler(buffer)
...@@ -81,7 +84,7 @@ def parameterize(probe, attr, values): ...@@ -81,7 +84,7 @@ def parameterize(probe, attr, values):
for probe in probes_list: for probe in probes_list:
for v in values: for v in values:
name = '%s/%s=%s' % (probe.name, attr, v) name = '%s/%s=%s' % (probe.name, attr, v)
ctx = probe.ctx ctx = probe.ctx.copy()
ctx[attr] = v ctx[attr] = v
out.append(Probe(probe.fn, name, ctx)) out.append(Probe(probe.fn, name, ctx))
return out return out
...@@ -9,6 +9,15 @@ class DriverTest(unittest.TestCase): ...@@ -9,6 +9,15 @@ class DriverTest(unittest.TestCase):
def tearDown(self): def tearDown(self):
pass pass
def test_parameterize(self):
values = ['one', 'two', 'three']
probes = parameterize(
TEST_PROBES[0],
'test_attr',
values)
for probe, value in zip(probes, values):
self.assertEquals(probe.ctx['test_attr'], value)
def test_run_probes(self): def test_run_probes(self):
for p in TEST_PROBES: for p in TEST_PROBES:
p(self.results) p(self.results)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment