ó
X¾÷Xc           @   sM  d  Z  d Z y d d l Z Wn e k
 r; d d l Z n Xd d l m Z d d l m Z d d l m Z d d l	 m
 Z
 d d l	 m Z d d	 l	 m Z d d
 l	 m Z d d l	 m Z d d l	 m Z d d l	 m Z e j Z d „  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ e d k rIe j ƒ  n  d S(   sJ   Test for preservation of unknown fields in the pure Python implementation.s!   bohdank@google.com (Bohdan Koval)iÿÿÿÿN(   t   unittest_mset_pb2(   t   unittest_pb2(   t   unittest_proto3_arena_pb2(   t   api_implementation(   t   encoder(   t   message_set_extensions_pb2(   t   missing_enum_values_pb2(   t	   test_util(   t   testing_refleaks(   t   type_checkersc         C   s4   t  j t j ƒ  d k o' t j ƒ  d k d ƒ |  ƒ S(   Nt   cppi   s;   C++ implementation does not expose unknown fields to Python(   t   unittestt   skipIfR   t   Typet   Version(   t   func(    (    sN   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/unknown_fields_test.pyt   SkipIfCppImplementation9   s    !t   UnknownFieldsTestc           B   sP   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   c         C   sf   t  j j |  _ t  j ƒ  |  _ t j |  j ƒ |  j j ƒ  |  _ t  j	 ƒ  |  _
 |  j
 j |  j ƒ d  S(   N(   R   t   TestAllTypest
   DESCRIPTORt
   descriptort
   all_fieldsR   t   SetAllFieldst   SerializeToStringt   all_fields_datat   TestEmptyMessaget   empty_messaget   ParseFromString(   t   self(    (    sN   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/unknown_fields_test.pyt   setUpA   s    c         C   s)   |  j  j ƒ  } |  j | |  j k ƒ d  S(   N(   R   R   t
   assertTrueR   (   R   t   data(    (    sN   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/unknown_fields_test.pyt   testSerializeI   s    c         C   s<   t  j ƒ  } | j |  j ƒ |  j d t | j ƒ  ƒ ƒ d  S(   Ni    (   R   R   R   R   t   assertEqualt   lenR   (   R   t   message(    (    sN   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/unknown_fields_test.pyt   testSerializeProto3P   s    c         C   s&   |  j  |  j j ƒ  |  j j ƒ  ƒ d  S(   N(   R!   R   t   ByteSizeR   (   R   (    (    sN   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/unknown_fields_test.pyt   testByteSizeV   s    c         C   s#   |  j  d t |  j j ƒ  ƒ ƒ d  S(   Ni    (   R!   R"   R   t
   ListFields(   R   (    (    sN   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/unknown_fields_test.pyt   testListFieldsY   s    c         C   s¦   t  j ƒ  } | j j ƒ  } d | _ t j ƒ  } d | _ | j ƒ  | _	 | j ƒ  } t j
 ƒ  } | j | ƒ | j ƒ  } t  j ƒ  } | j | ƒ |  j | | ƒ d  S(   Ni«¿Ýi90  (   R    t   RawMessageSett   itemt   addt   type_idR   t   TestMessageSetExtension1t   iR   R#   t   TestMessageSett   MergeFromStringR!   (   R   t   rawR*   t   message1t
   serializedt   protot   reserializedt   new_raw(    (    sN   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/unknown_fields_test.pyt1   testSerializeMessageSetWireFormatUnknownExtension]   s    		c         C   sl   t  j ƒ  } | j |  j ƒ |  j |  j | ƒ |  j j d ƒ | j |  j j ƒ  ƒ |  j	 |  j | ƒ d  S(   Nt   optional_string(
   R   R   R   R   R!   R   R   t
   ClearFieldR   t   assertNotEqual(   R   R#   (    (    sN   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/unknown_fields_test.pyt
   testEqualsu   s    c         C   só   |  j  j ƒ  |  j d |  j  j ƒ  ƒ t j ƒ  } t j ƒ  } d | _ | j j | j ƒ  ƒ | j	 j
 ƒ  j | j ƒ  ƒ |  j d | j j ƒ  ƒ |  j d | j	 d j ƒ  ƒ | j ƒ  |  j d | j j ƒ  ƒ |  j d | j	 d j ƒ  ƒ d  S(   Nt    t   discardi    (   R   t   DiscardUnknownFieldsR!   R   R   R   R8   t   optional_nested_messageR   t   repeated_nested_messageR+   R:   (   R   R#   t   other_message(    (    sN   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/unknown_fields_test.pyt   testDiscardUnknownFields~   s"    		
(
   t   __name__t
   __module__R   R    R$   R&   R(   R7   R;   RB   (    (    (    sN   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/unknown_fields_test.pyR   ?   s   								t   UnknownFieldsAccessorsTestc           B   s§   e  Z d  „  Z d „  Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z	 e d „  ƒ Z
 e d „  ƒ Z d	 „  Z d
 „  Z d „  Z d „  Z RS(   c         C   sf   t  j j |  _ t  j ƒ  |  _ t j |  j ƒ |  j j ƒ  |  _ t  j	 ƒ  |  _
 |  j
 j |  j ƒ d  S(   N(   R   R   R   R   R   R   R   R   R   R   R   R   (   R   (    (    sN   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/unknown_fields_test.pyR   •   s    c   	      C   s¢   |  j  j | } t j | j } t j | j | ƒ } i  } x\ |  j j	 D]N \ } } | | k rH t
 j j | d } | | d t | ƒ |  j | ƒ qH qH W| | S(   Ni    (   R   t   fields_by_nameR	   t   FIELD_TYPE_TO_WIRE_TYPEt   typeR   t   TagBytest   numberR   t   _unknown_fieldsR   R   t   _decoders_by_tagR"   R   (	   R   t   namet   field_descriptort	   wire_typet	   field_tagt   result_dictt	   tag_bytest   valuet   decoder(    (    sN   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/unknown_fields_test.pyt   GetUnknownField¢   s    &c         C   s)   |  j  d ƒ } |  j |  j j | ƒ d  S(   Nt   optional_nested_enum(   RU   R!   R   RV   (   R   RS   (    (    sN   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/unknown_fields_test.pyt   testEnum­   s    c         C   s)   |  j  d ƒ } |  j |  j j | ƒ d  S(   Nt   repeated_nested_enum(   RU   R!   R   RX   (   R   RS   (    (    sN   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/unknown_fields_test.pyt   testRepeatedEnum²   s    c         C   s)   |  j  d ƒ } |  j |  j j | ƒ d  S(   Nt   optional_int32(   RU   R!   R   RZ   (   R   RS   (    (    sN   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/unknown_fields_test.pyt
   testVarint·   s    c         C   s)   |  j  d ƒ } |  j |  j j | ƒ d  S(   Nt   optional_fixed32(   RU   R!   R   R\   (   R   RS   (    (    sN   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/unknown_fields_test.pyt   testFixed32¼   s    c         C   s)   |  j  d ƒ } |  j |  j j | ƒ d  S(   Nt   optional_fixed64(   RU   R!   R   R^   (   R   RS   (    (    sN   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/unknown_fields_test.pyt   testFixed64Á   s    c         C   s)   |  j  d ƒ } |  j |  j j | ƒ d  S(   NR8   (   RU   R!   R   R8   (   R   RS   (    (    sN   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/unknown_fields_test.pyt   testLengthDelimitedÆ   s    c         C   s)   |  j  d ƒ } |  j |  j j | ƒ d  S(   Nt   optionalgroup(   RU   R!   R   Ra   (   R   RS   (    (    sN   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/unknown_fields_test.pyt	   testGroupË   s    c         C   s9   t  j ƒ  } | j |  j ƒ |  j | j ƒ  |  j ƒ d  S(   N(   R   R   t   CopyFromR   R!   R   R   (   R   R#   (    (    sN   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/unknown_fields_test.pyt   testCopyFromÐ   s    c         C   sØ   t  j ƒ  } d | _ d | _ t  j ƒ  } | j | j ƒ  ƒ | j d ƒ d | _ d | _ t  j ƒ  } | j | j ƒ  ƒ | j	 | ƒ | j | j ƒ  ƒ |  j
 | j d ƒ |  j
 | j d ƒ |  j
 | j d ƒ d  S(   Ni   i   RZ   i   i   (   R   R   RZ   t   optional_uint32R   R   R   R9   t   optional_int64t	   MergeFromR!   (   R   R#   t   sourcet   destination(    (    sN   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/unknown_fields_test.pyt   testMergeFromÕ   s    				c         C   s*   |  j  j ƒ  |  j |  j  j ƒ  d ƒ d  S(   NR<   (   R   t   ClearR!   R   (   R   (    (    sN   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/unknown_fields_test.pyt	   testClearê   s    c         C   s9   t  j ƒ  } | j |  j ƒ |  j | j ƒ  |  j ƒ d  S(   N(   R   t   TestEmptyMessageWithExtensionsR   R   R!   R   (   R   R#   (    (    sN   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/unknown_fields_test.pyt   testUnknownExtensionsï   s    (   RC   RD   R   RU   R   RW   RY   R[   R]   R_   R`   Rb   Rd   Rj   Rl   Rn   (    (    (    sN   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/unknown_fields_test.pyRE   “   s   					t   UnknownEnumValuesTestc           B   sG   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s²   t  j j |  _ t  j ƒ  |  _ t  j j |  j _ |  j j j t  j j t  j j	 g ƒ |  j j
 j t  j j t  j j	 g ƒ |  j j ƒ  |  _ t  j ƒ  |  _ |  j j |  j ƒ d  S(   N(   R   t   TestEnumValuesR   R   R#   t   ZERORV   RX   t   extendt   ONEt   packed_nested_enumR   t   message_datat   TestMissingEnumValuest   missing_messageR   (   R   (    (    sN   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/unknown_fields_test.pyR   ÷   s    		c   	      C   s¢   |  j  j | } t j | j } t j | j | ƒ } i  } x\ |  j j	 D]N \ } } | | k rH t
 j j | d } | | d t | ƒ |  j | ƒ qH qH W| | S(   Ni    (   R   RF   R	   RG   RH   R   RI   RJ   Rw   RK   R   Rp   RL   R"   R#   (	   R   RM   RN   RO   RP   RQ   RR   RS   RT   (    (    sN   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/unknown_fields_test.pyRU     s    	&c         C   sK   t  j ƒ  } d | _ t  j ƒ  } | j | j ƒ  ƒ |  j | j d ƒ d  S(   Nt   blahi    (   R   t
   JustStringt   dummyRp   R   R   R!   RV   (   R   t   just_stringt   missing(    (    sN   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/unknown_fields_test.pyt!   testUnknownParseMismatchEnumValue  s
    	c         C   sµ   t  j ƒ  d k rJ |  j |  j j d ƒ ƒ |  j |  j j |  j j ƒ n> |  j |  j j d ƒ ƒ |  j	 d ƒ } |  j |  j j | ƒ |  j j
 d ƒ |  j |  j j d ƒ ƒ d  S(   NR
   RV   (   R   R   R   Rw   t   HasFieldR!   R#   RV   t   assertFalseRU   R9   (   R   RS   (    (    sN   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/unknown_fields_test.pyt   testUnknownEnumValue(  s    c         C   sj   t  j ƒ  d k r+ |  j g  |  j j ƒ n; |  j g  |  j j ƒ |  j d ƒ } |  j |  j j | ƒ d  S(   NR
   RX   (   R   R   R!   Rw   RX   RU   R#   (   R   RS   (    (    sN   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/unknown_fields_test.pyt   testUnknownRepeatedEnumValue8  s
    c         C   sj   t  j ƒ  d k r+ |  j g  |  j j ƒ n; |  j g  |  j j ƒ |  j d ƒ } |  j |  j j | ƒ d  S(   NR
   Rt   (   R   R   R!   Rw   Rt   RU   R#   (   R   RS   (    (    sN   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/unknown_fields_test.pyt   testUnknownPackedEnumValueA  s
    c         C   s9   t  j ƒ  } | j |  j j ƒ  ƒ |  j |  j | ƒ d  S(   N(   R   Rp   R   Rw   R   R!   R#   (   R   t   new_message(    (    sN   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/unknown_fields_test.pyt   testRoundTripJ  s    (	   RC   RD   R   RU   R}   R€   R   R‚   R„   (    (    (    sN   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/unknown_fields_test.pyRo   õ   s   								t   __main__(   t   __doc__t
   __author__t	   unittest2R   t   ImportErrort   google.protobufR    R   R   t   google.protobuf.internalR   R   R   R   R   R   R	   t   BaseTestCaseR   R   RE   Ro   RC   t   main(    (    (    sN   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/unknown_fields_test.pyt   <module>"   s,   		Tb[