Skip to content

Commit

Permalink
Merge efe346b into 2123b48
Browse files Browse the repository at this point in the history
  • Loading branch information
osherdp committed Jan 31, 2019
2 parents 2123b48 + efe346b commit 3eb7944
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -3,7 +3,7 @@
from setuptools import setup, find_packages


__version__ = "6.0.1"
__version__ = "6.1.0"

result_handlers = [
"db = rotest.core.result.handlers.db_handler:DBHandler",
Expand Down
3 changes: 2 additions & 1 deletion src/rotest/core/block.py
Expand Up @@ -156,7 +156,8 @@ def validate_inputs(self, extra_inputs=[]):
for (name, value) in iteritems(self.get_inputs())
if not value.is_optional()]

required_inputs.extend(itervalues(self._pipes))
for pipe in itervalues(self._pipes):
required_inputs.append(pipe.parameter_name)

missing_inputs = [input_name for input_name in required_inputs
if (input_name not in self.__dict__ and
Expand Down
25 changes: 20 additions & 5 deletions src/rotest/core/flow_component.py
Expand Up @@ -30,8 +30,24 @@

class PipeTo(object):
"""Used as reference to another parameter when using blocks and flows."""
def __init__(self, parameter_name):
def __init__(self, parameter_name, formula=None):
self.parameter_name = parameter_name
self.formula = formula

def get_value(self, block):
"""Extract the pointed value from the block.
Args:
block (AbstractFlowComponent): component to extract value from.
Returns:
object. pointed value.
"""
value = getattr(block, self.parameter_name)
if self.formula is not None:
value = self.formula(value)

return value


class BlockInput(object):
Expand Down Expand Up @@ -267,8 +283,8 @@ def setup_method_wrapper(*args, **kwargs):
iteritems(self.get_inputs())
if value.is_optional()})

for pipe_name, pipe_target in iteritems(self._pipes):
setattr(self, pipe_name, getattr(self, pipe_target))
for pipe_name, pipe in iteritems(self._pipes):
setattr(self, pipe_name, pipe.get_value(self))

if not self.is_main:
# Validate all required inputs were passed
Expand Down Expand Up @@ -393,11 +409,10 @@ def _set_parameters(self, override_previous=True, **parameters):
"""
for name, value in iteritems(parameters):
if isinstance(value, PipeTo):
parameter_name = value.parameter_name
if override_previous or (name not in self.__dict__ and
name not in self._pipes):

self._pipes[name] = parameter_name
self._pipes[name] = value

else:
if override_previous or (name not in self.__dict__ and
Expand Down
22 changes: 22 additions & 0 deletions tests/core/test_flow.py
Expand Up @@ -448,6 +448,28 @@ def test_pipes_happy_flow(self):

self.validate_blocks(test_flow, successes=2)

def test_pipes_with_formula(self):
"""Validate parametrize behavior when using formulas."""
writer_block = create_writer_block(inject_name='some_name',
inject_value=5)

reader_block = create_reader_block(inject_name='pipe_target',
inject_value=6)

MockFlow.blocks = (
writer_block,
reader_block.params(pipe_target=PipeTo(
'some_name',
formula=lambda value: value + 1)))

test_flow = MockFlow()
self.run_test(test_flow)

self.assertTrue(self.result.wasSuccessful(),
'Flow failed when it should have succeeded')

self.validate_blocks(test_flow, successes=2)

def test_pipes_in_common(self):
"""Validate parametrize behavior when using pipes in common."""
ReadingBlock = create_reader_block(inject_name='pipe_target',
Expand Down

0 comments on commit 3eb7944

Please sign in to comment.