def testGetParameterFromOutput(self, mock_read):
    mock_read.return_value = _get_text_from_testdata('executor_output.json')

    self.assertEqual(entrypoint_utils.get_parameter_from_output(
        file_path=os.path.join('testdata', 'executor_output.json'),
        param_name='int_output'
    ), 42)
    self.assertEqual(entrypoint_utils.get_parameter_from_output(
        file_path=os.path.join('testdata', 'executor_output.json'),
        param_name='string_output'
    ), 'hello world!')
    self.assertEqual(entrypoint_utils.get_parameter_from_output(
        file_path=os.path.join('testdata', 'executor_output.json'),
        param_name='float_output'
    ), 12.12)
Exemplo n.º 2
0
    def __init__(self,
                 value: Optional[Union[str, float, int]] = None,
                 metadata_file: Optional[str] = None,
                 field_name: Optional[str] = None):
        """Instantiates an InputParam object.

    Args:
      value: The actual value of the parameter.
      metadata_file: The location of the metadata JSON file output by the
        producer step.
      field_name: The output name of the producer.

    Raises:
      ValueError: when neither of the following is true:
        1) value is provided, and metadata_file and field_name are not; or
        2) both metadata_file and field_name are provided, and value is not.
    """
        if not (value is not None and not (metadata_file or field_name) or
                (metadata_file and field_name and value is None)):
            raise ValueError(
                'Either value or both metadata_file and field_name '
                'needs to be provided. Got value={value}, field_name='
                '{field_name}, metadata_file={metadata_file}'.format(
                    value=value,
                    field_name=field_name,
                    metadata_file=metadata_file))
        if value is not None:
            self._value = value
        else:
            # Parse the value by inspecting the producer's metadata JSON file.
            self._value = entrypoint_utils.get_parameter_from_output(
                metadata_file, field_name)

        self._metadata_file = metadata_file
        self._field_name = field_name