Beispiel #1
0
    def testExecutionParameterTypeCheck(self):
        int_parameter = ExecutionParameter(type=int)
        int_parameter.type_check('int_parameter', 8)
        with self.assertRaisesRegex(
                TypeError, "Expected type <(class|type) 'int'>"
                " for parameter u?'int_parameter'"):
            int_parameter.type_check('int_parameter', 'string')

        list_parameter = ExecutionParameter(type=List[int])
        list_parameter.type_check('list_parameter', [])
        list_parameter.type_check('list_parameter', [42])
        with self.assertRaisesRegex(TypeError,
                                    'Expecting a list for parameter'):
            list_parameter.type_check('list_parameter', 42)

        with self.assertRaisesRegex(
                TypeError, "Expecting item type <(class|type) "
                "'int'> for parameter u?'list_parameter'"):
            list_parameter.type_check('list_parameter', [42, 'wrong item'])

        dict_parameter = ExecutionParameter(type=Dict[str, int])
        dict_parameter.type_check('dict_parameter', {})
        dict_parameter.type_check('dict_parameter', {'key1': 1, 'key2': 2})
        with self.assertRaisesRegex(TypeError,
                                    'Expecting a dict for parameter'):
            dict_parameter.type_check('dict_parameter', 'simple string')

        with self.assertRaisesRegex(
                TypeError, "Expecting value type "
                "<(class|type) 'int'>"):
            dict_parameter.type_check('dict_parameter', {'key1': '1'})

        proto_parameter = ExecutionParameter(type=example_gen_pb2.Input)
        proto_parameter.type_check('proto_parameter', example_gen_pb2.Input())
        proto_parameter.type_check('proto_parameter',
                                   {'splits': [{
                                       'name': 'hello'
                                   }]})
        proto_parameter.type_check('proto_parameter', {'wrong_field': 42})
        with self.assertRaisesRegex(
                TypeError,
                "Expected type <class 'tfx.proto.example_gen_pb2.Input'>"):
            proto_parameter.type_check('proto_parameter', 42)
        with self.assertRaises(json_format.ParseError):
            proto_parameter.type_check('proto_parameter', {'splits': 42})
Beispiel #2
0
    def testExecutionParameterTypeCheck(self):
        int_parameter = ExecutionParameter(type=int)
        int_parameter.type_check('int_parameter', 8)
        with self.assertRaisesRegexp(
                TypeError, "Expected type <(class|type) 'int'>"
                " for parameter u?'int_parameter'"):
            int_parameter.type_check('int_parameter', 'string')

        list_parameter = ExecutionParameter(type=List[int])
        list_parameter.type_check('list_parameter', [])
        list_parameter.type_check('list_parameter', [42])
        with self.assertRaisesRegexp(TypeError,
                                     'Expecting a list for parameter'):
            list_parameter.type_check('list_parameter', 42)

        with self.assertRaisesRegexp(
                TypeError, "Expecting item type <(class|type) "
                "'int'> for parameter u?'list_parameter'"):
            list_parameter.type_check('list_parameter', [42, 'wrong item'])

        dict_parameter = ExecutionParameter(type=Dict[Text, int])
        dict_parameter.type_check('dict_parameter', {})
        dict_parameter.type_check('dict_parameter', {'key1': 1, 'key2': 2})
        with self.assertRaisesRegexp(TypeError,
                                     'Expecting a dict for parameter'):
            dict_parameter.type_check('dict_parameter', 'simple string')

        with self.assertRaisesRegexp(
                TypeError, "Expecting value type "
                "<(class|type) 'int'>"):
            dict_parameter.type_check('dict_parameter', {'key1': '1'})
Beispiel #3
0
    def testExecutionParameterTypeCheck(self):
        int_parameter = ExecutionParameter(type=int)
        int_parameter.type_check('int_parameter', 8)
        with self.assertRaisesRegex(
                TypeError, "Expected type <(class|type) 'int'>"
                " for parameter u?'int_parameter'"):
            int_parameter.type_check('int_parameter', 'string')

        list_parameter = ExecutionParameter(type=List[int])
        list_parameter.type_check('list_parameter', [])
        list_parameter.type_check('list_parameter', [42])
        with self.assertRaisesRegex(TypeError,
                                    'Expecting a list for parameter'):
            list_parameter.type_check('list_parameter', 42)

        with self.assertRaisesRegex(
                TypeError, "Expecting item type <(class|type) "
                "'int'> for parameter u?'list_parameter'"):
            list_parameter.type_check('list_parameter', [42, 'wrong item'])

        dict_parameter = ExecutionParameter(type=Dict[str, int])
        dict_parameter.type_check('dict_parameter', {})
        dict_parameter.type_check('dict_parameter', {'key1': 1, 'key2': 2})
        with self.assertRaisesRegex(TypeError,
                                    'Expecting a dict for parameter'):
            dict_parameter.type_check('dict_parameter', 'simple string')

        with self.assertRaisesRegex(
                TypeError, "Expecting value type "
                "<(class|type) 'int'>"):
            dict_parameter.type_check('dict_parameter', {'key1': '1'})

        proto_parameter = ExecutionParameter(type=example_gen_pb2.Input)
        proto_parameter.type_check('proto_parameter', example_gen_pb2.Input())
        proto_parameter.type_check(
            'proto_parameter',
            proto_utils.proto_to_json(example_gen_pb2.Input()))
        proto_parameter.type_check('proto_parameter',
                                   {'splits': [{
                                       'name': 'hello'
                                   }]})
        proto_parameter.type_check('proto_parameter', {'wrong_field': 42})
        with self.assertRaisesRegex(
                TypeError,
                "Expected type <class 'tfx.proto.example_gen_pb2.Input'>"):
            proto_parameter.type_check('proto_parameter', 42)
        with self.assertRaises(json_format.ParseError):
            proto_parameter.type_check('proto_parameter', {'splits': 42})

        output_channel = channel.Channel(type=_OutputArtifact)

        placeholder_parameter = ExecutionParameter(type=str)
        placeholder_parameter.type_check(
            'wrapped_channel_placeholder_parameter',
            output_channel.future()[0].value)
        placeholder_parameter.type_check(
            'placeholder_parameter',
            placeholder.runtime_info('platform_config').base_dir)
        with self.assertRaisesRegex(
                TypeError,
                'Only simple RuntimeInfoPlaceholders are supported'):
            placeholder_parameter.type_check(
                'placeholder_parameter',
                placeholder.runtime_info('platform_config').base_dir +
                placeholder.exec_property('version'))