def test_int_enum(self): result = rpc.translate_output_properties(4, translate_output_property, ContainerSize) self.assertIsInstance(result, ContainerSize) self.assertIsInstance(result, Enum) self.assertEqual(result, 4) self.assertEqual(result, ContainerSize.FOUR_INCH)
def test_any(self): output = { "value_dict": { "hello": "world" }, "value_list": ["hello"], "value_dict_dict": { "value": { "hello": "world" } }, "value_dict_mapping": { "value": { "hello": "world" } }, "value_list_list": [["hello"]], "value_list_sequence": [["hello"]], "value_str": "hello", } result = rpc.translate_output_properties(output, translate_output_property, OutputTypeWithAny) self.assertIsInstance(result, OutputTypeWithAny) self.assertEqual({"hello": "world"}, result.value_dict) self.assertEqual(["hello"], result.value_list) self.assertEqual({"value": {"hello": "world"}}, result.value_dict_dict) self.assertEqual({"value": { "hello": "world" }}, result.value_dict_mapping) self.assertEqual([["hello"]], result.value_list_list) self.assertEqual([["hello"]], result.value_list_sequence) self.assertEqual("hello", result.value_str)
def test_float_enum(self): result = rpc.translate_output_properties(0.1, translate_output_property, ContainerBrightness) self.assertIsInstance(result, ContainerBrightness) self.assertIsInstance(result, Enum) self.assertEqual(result, 0.1) self.assertEqual(result, ContainerBrightness.ZERO_POINT_ONE)
def test_str_enum(self): result = rpc.translate_output_properties("red", translate_output_property, ContainerColor) self.assertIsInstance(result, ContainerColor) self.assertIsInstance(result, Enum) self.assertEqual(result, "red") self.assertEqual(result, ContainerColor.RED)
def run_test(output: dict): result = rpc.translate_output_properties( output, translate_output_property, typ) self.assertIsInstance(result, typ) self.assertIs(result.third_arg, result["thirdArg"]) assertFoo(result.third_arg, "hello", 42) self.assertIs(result.third_optional_arg, result["thirdOptionalArg"]) assertFoo(result.third_optional_arg, "hello-opt", 142) self.assertIs(result.fourth_arg, result["fourthArg"]) assertFoo(result.fourth_arg["foo"], "hi", 41) self.assertIs(result.fourth_optional_arg, result["fourthOptionalArg"]) assertFoo(result.fourth_optional_arg["foo"], "hi-opt", 141) self.assertIs(result.fifth_arg, result["fifthArg"]) assertFoo(result.fifth_arg[0], "bye", 40) self.assertIs(result.fifth_optional_arg, result["fifthOptionalArg"]) assertFoo(result.fifth_optional_arg[0], "bye-opt", 140) self.assertIs(result.sixth_arg, result["sixthArg"]) assertFoo(result.sixth_arg["bar"][0], "goodbye", 39) self.assertIs(result.sixth_optional_arg, result["sixthOptionalArg"]) assertFoo(result.sixth_optional_arg["bar"][0], "goodbye-opt", 139) self.assertIs(result.sixth_optional_optional_arg, result["sixthOptionalOptionalArg"]) assertFoo(result.sixth_optional_optional_arg["bar"][0], "goodbye-opt-opt", 1139) self.assertIs(result.seventh_arg, result["seventhArg"]) assertFoo(result.seventh_arg[0]["baz"], "adios", 38) self.assertIs(result.seventh_optional_arg, result["seventhOptionalArg"]) assertFoo(result.seventh_optional_arg[0]["baz"], "adios-opt", 138) self.assertIs(result.seventh_optional_optional_arg, result["seventhOptionalOptionalArg"]) assertFoo(result.seventh_optional_optional_arg[0]["baz"], "adios-opt-opt", 1138) self.assertIs(result.eighth_arg, result["eighthArg"]) assertFoo(result.eighth_arg[0]["blah"][0], "farewell", 37) self.assertIs(result.eighth_optional_arg, result["eighthOptionalArg"]) assertFoo(result.eighth_optional_arg[0]["blah"][0], "farewell-opt", 137) self.assertIs(result.eighth_optional_optional_arg, result["eighthOptionalOptionalArg"]) assertFoo(result.eighth_optional_optional_arg[0]["blah"][0], "farewell-opt-opt", 1137) self.assertIs(result.eighth_optional_optional_optional_arg, result["eighthOptionalOptionalOptionalArg"]) assertFoo( result.eighth_optional_optional_optional_arg[0]["blah"][0], "farewell-opt-opt-opt", 11137)
def test_translate(self): output = { "firstArg": "hello", "secondArg": 42, } result = rpc.translate_output_properties(output, translate_output_property, Foo) self.assertIsInstance(result, Foo) self.assertEqual(result.first_arg, "hello") self.assertEqual(result["first_arg"], "hello") self.assertEqual(result.second_arg, 42) self.assertEqual(result["second_arg"], 42)
def test_int(self): @pulumi.output_type class OutputTypeWithInt(dict): value_dict: Dict[str, int] value_mapping: Mapping[str, int] value_list: List[int] value_sequence: Sequence[int] value_int: int output = { "value_dict": { "hello": 42.0 }, "value_mapping": { "world": 100.0 }, "value_list": [42.0], "value_sequence": [100.0], "value_int": 50.0, } result = rpc.translate_output_properties(output, translate_output_property, OutputTypeWithInt) self.assertIsInstance(result, OutputTypeWithInt) self.assertEqual({"hello": 42}, result.value_dict) self.assertIsInstance(result.value_dict["hello"], int) self.assertEqual({"world": 100}, result.value_mapping) self.assertIsInstance(result.value_mapping["world"], int) self.assertEqual([42], result.value_list) self.assertIsInstance(result.value_list[0], int) self.assertEqual([100], result.value_sequence) self.assertIsInstance(result.value_sequence[0], int) self.assertEqual(50, result.value_int) self.assertIsInstance(result.value_int, int)
def test_nested_types_raises(self): dict_value = { "firstArg": "hello", "secondArg": 42, } list_value = ["hello"] tests = [ (InvalidTypeStr, dict_value), (InvalidTypeDeclaredStr, dict_value), (InvalidTypeOptionalStr, dict_value), (InvalidTypeDeclaredOptionalStr, dict_value), (InvalidTypeStr, list_value), (InvalidTypeDeclaredStr, list_value), (InvalidTypeOptionalStr, list_value), (InvalidTypeDeclaredOptionalStr, list_value), (InvalidTypeDictStr, { "foo": dict_value }), (InvalidTypeDeclaredDictStr, { "foo": dict_value }), (InvalidTypeOptionalDictStr, { "foo": dict_value }), (InvalidTypeDeclaredOptionalDictStr, { "foo": dict_value }), (InvalidTypeDictOptionalStr, { "foo": dict_value }), (InvalidTypeDeclaredDictOptionalStr, { "foo": dict_value }), (InvalidTypeOptionalDictOptionalStr, { "foo": dict_value }), (InvalidTypeDeclaredOptionalDictOptionalStr, { "foo": dict_value }), (InvalidTypeMappingStr, { "foo": dict_value }), (InvalidTypeDeclaredMappingStr, { "foo": dict_value }), (InvalidTypeOptionalMappingStr, { "foo": dict_value }), (InvalidTypeDeclaredOptionalMappingStr, { "foo": dict_value }), (InvalidTypeMappingOptionalStr, { "foo": dict_value }), (InvalidTypeDeclaredMappingOptionalStr, { "foo": dict_value }), (InvalidTypeOptionalMappingOptionalStr, { "foo": dict_value }), (InvalidTypeDeclaredOptionalMappingOptionalStr, { "foo": dict_value }), (InvalidTypeDictStr, { "foo": list_value }), (InvalidTypeDeclaredDictStr, { "foo": list_value }), (InvalidTypeOptionalDictStr, { "foo": list_value }), (InvalidTypeDeclaredOptionalDictStr, { "foo": list_value }), (InvalidTypeDictOptionalStr, { "foo": list_value }), (InvalidTypeDeclaredDictOptionalStr, { "foo": list_value }), (InvalidTypeOptionalDictOptionalStr, { "foo": list_value }), (InvalidTypeDeclaredOptionalDictOptionalStr, { "foo": list_value }), (InvalidTypeMappingStr, { "foo": list_value }), (InvalidTypeDeclaredMappingStr, { "foo": list_value }), (InvalidTypeOptionalMappingStr, { "foo": list_value }), (InvalidTypeDeclaredOptionalMappingStr, { "foo": list_value }), (InvalidTypeMappingOptionalStr, { "foo": list_value }), (InvalidTypeDeclaredMappingOptionalStr, { "foo": list_value }), (InvalidTypeOptionalMappingOptionalStr, { "foo": list_value }), (InvalidTypeDeclaredOptionalMappingOptionalStr, { "foo": list_value }), (InvalidTypeListStr, [dict_value]), (InvalidTypeDeclaredListStr, [dict_value]), (InvalidTypeOptionalListStr, [dict_value]), (InvalidTypeDeclaredOptionalListStr, [dict_value]), (InvalidTypeListOptionalStr, [dict_value]), (InvalidTypeDeclaredListOptionalStr, [dict_value]), (InvalidTypeOptionalListOptionalStr, [dict_value]), (InvalidTypeDeclaredOptionalListOptionalStr, [dict_value]), (InvalidTypeSequenceStr, [dict_value]), (InvalidTypeDeclaredSequenceStr, [dict_value]), (InvalidTypeOptionalSequenceStr, [dict_value]), (InvalidTypeDeclaredOptionalSequenceStr, [dict_value]), (InvalidTypeSequenceOptionalStr, [dict_value]), (InvalidTypeDeclaredSequenceOptionalStr, [dict_value]), (InvalidTypeOptionalSequenceOptionalStr, [dict_value]), (InvalidTypeDeclaredOptionalSequenceOptionalStr, [dict_value]), (InvalidTypeListStr, [list_value]), (InvalidTypeDeclaredListStr, [list_value]), (InvalidTypeOptionalListStr, [list_value]), (InvalidTypeDeclaredOptionalListStr, [list_value]), (InvalidTypeListOptionalStr, [list_value]), (InvalidTypeDeclaredListOptionalStr, [list_value]), (InvalidTypeOptionalListOptionalStr, [list_value]), (InvalidTypeDeclaredOptionalListOptionalStr, [list_value]), (InvalidTypeSequenceStr, [list_value]), (InvalidTypeDeclaredSequenceStr, [list_value]), (InvalidTypeOptionalSequenceStr, [list_value]), (InvalidTypeDeclaredOptionalSequenceStr, [list_value]), (InvalidTypeSequenceOptionalStr, [list_value]), (InvalidTypeDeclaredSequenceOptionalStr, [list_value]), (InvalidTypeOptionalSequenceOptionalStr, [list_value]), (InvalidTypeDeclaredOptionalSequenceOptionalStr, [list_value]), ] for typ, value in tests: outputs = [ { "value": value }, { "value": { rpc._special_sig_key: rpc._special_secret_sig, "value": value } }, ] for output in outputs: with self.assertRaises(AssertionError): rpc.translate_output_properties(output, translate_output_property, typ)
def test_nested_types(self): def assertFoo(val, first_arg, second_arg): self.assertIsInstance(val, Foo) self.assertEqual(val.first_arg, first_arg) self.assertEqual(val["first_arg"], first_arg) self.assertEqual(val.second_arg, second_arg) self.assertEqual(val["second_arg"], second_arg) output = { "thirdArg": { "firstArg": "hello", "secondArg": 42, }, "thirdOptionalArg": { "firstArg": "hello-opt", "secondArg": 142, }, "fourthArg": { "foo": { "firstArg": "hi", "secondArg": 41, }, }, "fourthOptionalArg": { "foo": { "firstArg": "hi-opt", "secondArg": 141, }, }, "fifthArg": [{ "firstArg": "bye", "secondArg": 40, }], "fifthOptionalArg": [{ "firstArg": "bye-opt", "secondArg": 140, }], "sixthArg": { "bar": [{ "firstArg": "goodbye", "secondArg": 39, }], }, "sixthOptionalArg": { "bar": [{ "firstArg": "goodbye-opt", "secondArg": 139, }], }, "sixthOptionalOptionalArg": { "bar": [{ "firstArg": "goodbye-opt-opt", "secondArg": 1139, }], }, "seventhArg": [{ "baz": { "firstArg": "adios", "secondArg": 38, }, }], "seventhOptionalArg": [{ "baz": { "firstArg": "adios-opt", "secondArg": 138, }, }], "seventhOptionalOptionalArg": [{ "baz": { "firstArg": "adios-opt-opt", "secondArg": 1138, }, }], "eighthArg": [{ "blah": [{ "firstArg": "farewell", "secondArg": 37, }], }], "eighthOptionalArg": [{ "blah": [{ "firstArg": "farewell-opt", "secondArg": 137, }], }], "eighthOptionalOptionalArg": [{ "blah": [{ "firstArg": "farewell-opt-opt", "secondArg": 1137, }], }], "eighthOptionalOptionalOptionalArg": [{ "blah": [{ "firstArg": "farewell-opt-opt-opt", "secondArg": 11137, }], }], } for typ in [ Bar, BarMappingSequence, BarDeclared, BarMappingSequenceDeclared ]: result = rpc.translate_output_properties( output, translate_output_property, typ) self.assertIsInstance(result, typ) self.assertIs(result.third_arg, result["thirdArg"]) assertFoo(result.third_arg, "hello", 42) self.assertIs(result.third_optional_arg, result["thirdOptionalArg"]) assertFoo(result.third_optional_arg, "hello-opt", 142) self.assertIs(result.fourth_arg, result["fourthArg"]) assertFoo(result.fourth_arg["foo"], "hi", 41) self.assertIs(result.fourth_optional_arg, result["fourthOptionalArg"]) assertFoo(result.fourth_optional_arg["foo"], "hi-opt", 141) self.assertIs(result.fifth_arg, result["fifthArg"]) assertFoo(result.fifth_arg[0], "bye", 40) self.assertIs(result.fifth_optional_arg, result["fifthOptionalArg"]) assertFoo(result.fifth_optional_arg[0], "bye-opt", 140) self.assertIs(result.sixth_arg, result["sixthArg"]) assertFoo(result.sixth_arg["bar"][0], "goodbye", 39) self.assertIs(result.sixth_optional_arg, result["sixthOptionalArg"]) assertFoo(result.sixth_optional_arg["bar"][0], "goodbye-opt", 139) self.assertIs(result.sixth_optional_optional_arg, result["sixthOptionalOptionalArg"]) assertFoo(result.sixth_optional_optional_arg["bar"][0], "goodbye-opt-opt", 1139) self.assertIs(result.seventh_arg, result["seventhArg"]) assertFoo(result.seventh_arg[0]["baz"], "adios", 38) self.assertIs(result.seventh_optional_arg, result["seventhOptionalArg"]) assertFoo(result.seventh_optional_arg[0]["baz"], "adios-opt", 138) self.assertIs(result.seventh_optional_optional_arg, result["seventhOptionalOptionalArg"]) assertFoo(result.seventh_optional_optional_arg[0]["baz"], "adios-opt-opt", 1138) self.assertIs(result.eighth_arg, result["eighthArg"]) assertFoo(result.eighth_arg[0]["blah"][0], "farewell", 37) self.assertIs(result.eighth_optional_arg, result["eighthOptionalArg"]) assertFoo(result.eighth_optional_arg[0]["blah"][0], "farewell-opt", 137) self.assertIs(result.eighth_optional_optional_arg, result["eighthOptionalOptionalArg"]) assertFoo(result.eighth_optional_optional_arg[0]["blah"][0], "farewell-opt-opt", 1137) self.assertIs(result.eighth_optional_optional_optional_arg, result["eighthOptionalOptionalOptionalArg"]) assertFoo( result.eighth_optional_optional_optional_arg[0]["blah"][0], "farewell-opt-opt-opt", 11137)