def _render_channel_as_mdstr(input_channel: channel.Channel) -> Text: """Render a Channel as markdown string with the following format. **Type**: input_channel.type_name **Artifact: artifact1** **Properties**: **key1**: value1 **key2**: value2 ...... Args: input_channel: the channel to be rendered. Returns: a md-formatted string representation of the channel. """ md_str = '**Type**: {}\n\n'.format( _sanitize_underscore(input_channel.type_name)) rendered_artifacts = [] # List all artifacts in the channel. for single_artifact in input_channel.get(): rendered_artifacts.append(_render_artifact_as_mdstr(single_artifact)) return md_str + '\n\n'.join(rendered_artifacts)
def build_output_artifact_spec( channel_spec: channel.Channel ) -> pipeline_pb2.ComponentOutputsSpec.ArtifactSpec: """Builds artifact type spec for an output channel.""" # We use the first artifact instance if available from channel, otherwise # create one. artifacts = list(channel_spec.get()) artifact_instance = artifacts[0] if artifacts else channel_spec.type() result = pipeline_pb2.ComponentOutputsSpec.ArtifactSpec() result.artifact_type.CopyFrom( pipeline_pb2.ArtifactTypeSchema( instance_schema=get_artifact_schema(artifact_instance))) _validate_properties_schema( instance_schema=result.artifact_type.instance_schema, properties=channel_spec.type.PROPERTIES) struct_proto = pack_artifact_properties(artifact_instance) if struct_proto: result.metadata.CopyFrom(struct_proto) return result
def testValidChannel(self): instance_a = _MyType() instance_b = _MyType() chnl = Channel(_MyType).set_artifacts([instance_a, instance_b]) self.assertEqual(chnl.type_name, 'MyTypeName') self.assertCountEqual(chnl.get(), [instance_a, instance_b])
def test_valid_channel(self): instance_a = Artifact('MyTypeName') instance_b = Artifact('MyTypeName') chnl = Channel('MyTypeName', artifacts=[instance_a, instance_b]) self.assertEqual(chnl.type_name, 'MyTypeName') self.assertItemsEqual(chnl.get(), [instance_a, instance_b])