3 SLj9 @sdZdZy ddlZWnek r0ddlZYnXddlmZddlmZddlm Z ddlm Z ddlm Z dd lm Z dd lm Z dd lmZdd lmZdd lmZdZGdddejZGdddejZedkrejdS)zUnittest that directly tests the output of the pure-Python protocol compiler. See //google/protobuf/internal/reflection_test.py for a test which further ensures that we can use Python protocol message objects as we expect. z#robinson@google.com (Will Robinson)N)test_bad_identifiers_pb2)unittest_custom_options_pb2)unittest_import_pb2)unittest_import_public_pb2)unittest_mset_pb2)unittest_mset_wire_format_pb2) unittest_no_generic_services_pb2) unittest_pb2)service)symbol_databasei c@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-S). GeneratorTestcCs(d}tj}|j|jj|jj|jdS)Noptional_nested_message)r TestAllTypes assertEqual NestedMessage DESCRIPTORfields_by_nameZ message_type)self field_nameZ proto_typer$/usr/lib/python3.6/generator_test.pytestNestedMessageDescriptor@s z)GeneratorTest.testNestedMessageDescriptorcCs|jdtj|jdtj|jdtjtj}|jd|j|jdtjj|jd|j|jdtjj|jd|j|jdtjjdS)N) rr Z FOREIGN_FOOZ FOREIGN_BARZ FOREIGN_BAZrFOOZBARZBAZ)rprotorrr testEnumsGszGeneratorTest.testEnumscstj}ddfdd}|j||j|j|jdk|j||j|j|jdk|j|j|j||j|j|jdk|j||j|j|jdk|j|j|j d|j dS)NcSs||kS)Nr)valrrrisnan\sz5GeneratorTest.testExtremeDefaultValues..isnancs| o|dS)Nrr)r!)r"rrisinf_sz5GeneratorTest.testExtremeDefaultValues..isinfrz? ? ?? ?? ??? ??/ ??-) r ZTestExtremeDefaultValues assertTrueZ inf_doubleZneg_inf_doubleZ nan_doubleZ inf_floatZ neg_inf_floatZ nan_floatrZ cpp_trigraph)rmessager#r)r"rtestExtremeDefaultValuesWs z&GeneratorTest.testExtremeDefaultValuescs>tjj}dddddtfdd|jD}|j|dS)NFT)Zoptional_int32Zrepeated_int32r Z default_int32cs"g|]}|jkr|j|jfqSr)nameZhas_default_value).0f)expected_has_default_by_namerr {sz6GeneratorTest.testHasDefaultValues..)r rrdictfieldsr)rdescZhas_default_by_namer)r*rtestHasDefaultValuesps  z"GeneratorTest.testHasDefaultValuescCs.|jtjjtjj|jtjjjtjjdS)N)rr optional_int32_extensioncontaining_typeTestAllExtensionsr TestRequiredsingle)rrrr'testContainingTypeBehaviorForExtensionss   z5GeneratorTest.testContainingTypeBehaviorForExtensionscCs*|jtjjd|jtjjjtjjdS)N)rr r0Zextension_scoper3r4r)rrrrtestExtensionScopes  z GeneratorTest.testExtensionScopecCsB|jtjj|jtjjjtjj}|jd}|j|j dS)Na)r$r r0Z is_extensionr3r4rr)rZmessage_descriptorZnon_extension_descriptorrrrtestIsExtensions  zGeneratorTest.testIsExtensioncCstj}|j|jjjdS)N)rZTestMessageSetr$r GetOptionsZmessage_set_wire_format)rrrrr testOptionsszGeneratorTest.testOptionscCs*tj}|jjdj}|j|dk dS)NZAnEnum)rZTestMessageWithCustomOptionsrenum_types_by_namer9r$)rrZ enum_optionsrrrtestMessageWithCustomOptionssz*GeneratorTest.testMessageWithCustomOptionscCs\|jttjjjttjjjtjjjtjjjg|jtj jjg|jtjjjjgdS)N) rsetr rrZ nested_typesr OptionalGroup RepeatedGroupTestEmptyMessage)rrrrtestNestedTypess zGeneratorTest.testNestedTypescCst|jtjjjdk|jtjjjdk|jtjjjjtjj|jtjjjjtjj|jtjjjjtjjdS)N) r$r r@rr1rrrr?)rrrrtestContainingTypes     z GeneratorTest.testContainingTypecCs*|jtjjdk|jtjjtjjdS)N)r$r _FOREIGNENUMr1r_TESTALLTYPES_NESTEDENUMrr)rrrr"testContainingTypeInEnumDescriptors z0GeneratorTest.testContainingTypeInEnumDescriptorcCs||jtjjjjdtjjj}|j|jjd|jtjjjjd|jtj jjd|jtj jjd|jtj jjddS)Nprotobuf_unittestZprotobuf_unittest_import) rr rrfilepackagerrZ ImportMessagerCrDZ _IMPORTENUM)rr.rrr testPackages    zGeneratorTest.testPackagecCsJ|jtjjjg|jtjjjdtfg|jtjjjdddtfgdS) Nr*+/i)rJrK)rLrM)rr rrZextension_rangesr2 MAX_EXTENSIONZTestMultipleExtensionRanges)rrrrtestExtensionRanges z GeneratorTest.testExtensionRangecCsr|jtjjd|jtjjd|jtjjdk|jtjjtjg|jtjjt jg|jtjj t jgdS)Nzgoogle/protobuf/unittest.protorF) rr rr'rH assertFalseZ serialized_pbZ dependenciesrrZpublic_dependencies)rrrrtestFileDescriptors      z GeneratorTest.testFileDescriptorcCsR|jttd|jttd|jttdttdrN|jttjtjdS)NZ TestMessagerZtest_extension TestService)r$hasattrrrP issubclassrRr ZService)rrrrtestNoGenericServicess   z#GeneratorTest.testNoGenericServicescCs6tj}|jtj|jtjj|jtjj|jkdS)N)r rrZ _TESTALLTYPESZmessage_types_by_namer'rPZ_TESTALLTYPES_NESTEDMESSAGE)r file_typerrrtestMessageTypesByNamesz$GeneratorTest.testMessageTypesByNamecCs"tj}|jtj|jtjjdS)N)r rrrCr;r')rrVrrrtestEnumTypesByNamesz!GeneratorTest.testEnumTypesByNamecCs"tj}|jtj|jtjjdS)N)r rrZmy_extension_stringZextensions_by_namer')rrVrrrtestExtensionsByNamesz"GeneratorTest.testExtensionsByNamecCsDtj}|jd|jjtj}|jd|j|jtjtjkdS)Nr) r rrZoptional_public_import_messageerZPublicImportMessager$r)rZall_type_protoZpublic_import_protorrrtestPublicImports s zGeneratorTest.testPublicImportscCs\tj}|j|jtjd|j|jtjd|j|jtjd|j|jtjddS)NZfooZbarZbazZqux)rZTestBadIdentifiersrZ Extensionsr%Z descriptorZ reflectionr )rr%rrrtestBadIdentifierssz GeneratorTest.testBadIdentifierscCstjj}|jdt|j|jd|jdj|jd|jdj|j||jdj |j|jd|j dt ddddg}|j|t dd |jdj Dx@|j jD]2\}}||kr|j|jd|jq|j|jqWdS) NrZ oneof_fieldrZ oneof_uint32Zoneof_nested_messageZ oneof_stringZ oneof_bytescSsg|] }|jqSr)r')r(Zfieldrrrr+-sz+GeneratorTest.testOneof..)r rrrlenZoneofsr'indexZassertIsr1Zoneofs_by_namer=r-ritemsZcontaining_oneofZ assertIsNone)rr.Z nested_namesrZ field_descrrr testOneof"s zGeneratorTest.testOneofN)__name__ __module__ __qualname__rr r&r/r5r6r8r:r<rArBrErIrOrQrUrWrXrYr[r\r`rrrrr >s,       r c@s(eZdZdZddZddZddZdS) SymbolDatabaseRegistrationTestz?Checks that messages, enums and files are correctly registered.c Cs|jtjtjjd|jtjjtjjd|jttjjdWdQRX|jtjj tjjd|jtjj tjjddS)Nzprotobuf_unittest.TestAllTypesz,protobuf_unittest.TestAllTypes.NestedMessagezprotobuf_unittest.NestedMessagez,protobuf_unittest.TestAllTypes.OptionalGroupz,protobuf_unittest.TestAllTypes.RepeatedGroup) rr rr DefaultZ GetSymbolrZ assertRaisesKeyErrorr>r?)rrrr testGetSymbol8s"  z,SymbolDatabaseRegistrationTest.testGetSymbolcCs8|jdtjjjdj|jdtjjjdjdS)Nzprotobuf_unittest.ForeignEnumz)protobuf_unittest.TestAllTypes.NestedEnum)rr repoolZFindEnumTypeByNameZ full_name)rrrrr Ks   z(SymbolDatabaseRegistrationTest.testEnumscCs|jdtjjjdjdS)Nzgoogle/protobuf/unittest.proto)rr rerhZFindFileByNamer')rrrrtestFindFileByNameUs z1SymbolDatabaseRegistrationTest.testFindFileByNameN)rarbrc__doc__rgr rirrrrrd5s rd__main__)rj __author__Z unittest2Zunittest ImportErrorZgoogle.protobuf.internalrZgoogle.protobufrrrrrrr r r rNZTestCaser rdramainrrrr's*           x&