
XXc           @   s|  d  Z  d Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l 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 d d l m Z d d l m Z d d l m Z e j rre Z n  d   Z d   Z d   Z  d   Z! e j" Z" e j# d e f d e f  d e" f d     Y Z$ d e" f d     YZ% d e" f d     YZ& d e" f d     YZ' d e" f d      YZ( e
 j) e j*   d! k d"  d# e" f d$     Y Z+ e, d% k rxe
 j-   n  d S(&   s  Tests python protocol buffers against the golden message.

Note that the golden messages exercise every known field type, thus this
test ends up exercising and verifying nearly all of the parsing and
serialization code in the whole library.

TODO(kenton):  Merge with wire_format_test?  It doesn't make a whole lot of
sense to call this a test of the "message" module, which only declares an
abstract interface.
s!   gps@google.com (Gregory P. Smith)iN(   t   map_unittest_pb2(   t   unittest_pb2(   t   unittest_proto3_arena_pb2(   t   descriptor_pb2(   t   descriptor_pool(   t   message_factory(   t   text_format(   t   api_implementation(   t   packed_field_test_pb2(   t	   test_util(   t   testing_refleaks(   t   message(   t   _parameterizedc         C   s
   |  |  k S(   N(    (   t   val(    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   isnanP   s    c         C   s   t  |   o t  |  d  S(   Ni    (   R   (   R   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   isinfS   s    c         C   s   t  |   o |  d k S(   Ni    (   R   (   R   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   IsPosInfV   s    c         C   s   t  |   o |  d k  S(   Ni    (   R   (   R   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   IsNegInfX   s    t   _proto2t   _proto3t   MessageTestc        
   B   sI  e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z  d   Z! d    Z" d!   Z# d"   Z$ d#   Z% d$   Z& d%   Z' d&   Z( d'   Z) d(   Z* d)   Z+ d? e- d* d+ d, d- e.   g  i  e/   g
 Z0 d.   Z1 d/   Z2 d0   Z3 d1   Z4 d2   Z5 d3   Z6 d4   Z7 d5 e8 f d6     YZ9 d7   Z: d8   Z; d9   Z< d:   Z= d;   Z> d<   Z? d=   Z@ d>   ZA RS(@   c         C   sv   t  j   d k r" |  j d  n  t j d  } |  j t   } | j j |  Wd  QX|  j	 d t
 | j   d  S(   Nt   pythons   Skipping testBadUtf8String, currently only the python api implementation raises UnicodeDecodeError when a string field contains bad utf-8.t   bad_utf8_strings   TestAllTypes.optional_string(   R   t   Typet   skipTestR	   t   GoldenFileDatat   assertRaisest   UnicodeDecodeErrort   TestAllTypest
   FromStringt   assertInt   strt	   exception(   t   selft   message_modulet   bad_utf8_datat   context(    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testBadUtf8Stringd   s    c         C   s   | t  k r t j d  } n t j d  } | j   } | j |  | t  k re t j |  |  n  |  j | | j    t j	 |  } |  j | | j    d  S(   Nt    golden_message_oneof_implementedt   golden_message_proto3(
   R   R	   R   R   t   ParseFromStringt   ExpectAllFieldsSett   assertEqualt   SerializeToStringt   copyt   deepcopy(   R!   R"   t   golden_datat   golden_messaget   golden_copy(    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testGoldenMessagen   s    c         C   s   t  j d  } | j   } | j |  | j   } t  j |  |  j | |  |  j | | j    t j |  } |  j | | j    d  S(   Nt   golden_packed_fields_message(	   R	   R   t   TestPackedTypesR(   t   SetAllPackedFieldsR*   R+   R,   R-   (   R!   R"   R.   R/   t   all_setR0   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testGoldenPackedMessage   s    c         C   sZ   t  j d  } | j   } | j |  t j |  } t j |  } |  j | |  d  S(   NR/   (   R	   R   R   R(   t   picklet   dumpst   loadsR*   (   R!   R"   R.   R/   t   pickled_messaget   unpickled_message(    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testPickleSupport   s    c         C   s   | t  k r d } n d } | j   } | j |  |  j t | j   |  j t | j   |  j t | j d   |  j t | j d   |  j	 | | j
    d  S(   Ns   ]  a              s    ]  a              i    (   R   R   R(   t
   assertTrueR   t   optional_floatt   optional_doublet   repeated_floatt   repeated_doubleR*   R+   (   R!   R"   R.   R/   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testPositiveInfinity   s    	c         C   s   | t  k r d } n d } | j   } | j |  |  j t | j   |  j t | j   |  j t | j d   |  j t | j d   |  j	 | | j
    d  S(   Ns   ]  a              s    ]  a              i    (   R   R   R(   R=   R   R>   R?   R@   RA   R*   R+   (   R!   R"   R.   R/   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testNegativeInfinity   s    	c         C   s  d } | j    } | j |  |  j t | j   |  j t | j   |  j t | j d   |  j t | j d   | j   } | j    } | j |  |  j t | j   |  j t | j   |  j t | j d   |  j t | j d   d  S(   Ns   ]  a              i    (	   R   R(   R=   R   R>   R?   R@   RA   R+   (   R!   R"   R.   R/   t
   serializedR   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testNotANumber   s    c         C   sm   d } | j    } | j |  |  j t | j d   |  j t | j d   |  j | | j    d  S(   Ns           i    (   R3   R(   R=   R   t   packed_floatt   packed_doubleR*   R+   (   R!   R"   R.   R/   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testPositiveInfinityPacked   s    c         C   sm   d } | j    } | j |  |  j t | j d   |  j t | j d   |  j | | j    d  S(   Ns           i    (   R3   R(   R=   R   RF   RG   R*   R+   (   R!   R"   R.   R/   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testNegativeInfinityPacked   s    c         C   s   d } | j    } | j |  |  j t | j d   |  j t | j d   | j   } | j    } | j |  |  j t | j d   |  j t | j d   d  S(   Ns           i    (   R3   R(   R=   R   RF   RG   R+   (   R!   R"   R.   R/   RD   R   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testNotANumberPacked   s    c         C   s  | j    } t j d d  } | | _ | j | j    |  j | j | k  d t j d d  } | | _ | j | j    |  j | j | k  | | _ | j | j    |  j | j | k  | | _ | j | j    |  j | j | k  t j d d  } | | _ | j | j    |  j | j | k  d t j d d  } | | _ | j | j    |  j | j | k  | | _ | j | j    |  j | j | k  | | _ | j | j    |  j | j | k  d  S(   Ni   i   g      ?i(   R   t   matht   powR>   R(   R+   R=   (   R!   R"   R   t   kMostPosExponentNoSigBitst   kMostPosExponentOneSigBitt   kMostNegExponentNoSigBitst   kMostNegExponentOneSigBit(    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testExtremeFloatValues   s:    		

		

c         C   s  | j    } t j d d  } | | _ | j | j    |  j | j | k  d t j d d  } | | _ | j | j    |  j | j | k  | | _ | j | j    |  j | j | k  | | _ | j | j    |  j | j | k  t j d d  } | | _ | j | j    |  j | j | k  d t j d d  } | | _ | j | j    |  j | j | k  | | _ | j | j    |  j | j | k  | | _ | j | j    |  j | j | k  d  S(   Ni   i  g      ?i(   R   RK   RL   R?   R(   R+   R=   (   R!   R"   R   RM   RN   RO   RP   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testExtremeDoubleValues!  s:    		

		

c         C   s/   | j    } d | _ |  j t |  d  d  S(   Ng       @s   optional_float: 2.0
(   R   R>   R*   R   (   R!   R"   R   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testFloatPrintingN  s    	c         C   sW   | j    } d | _ t j d k r= |  j t |  d  n |  j t |  d  d  S(   Ng^!7ݚ?i   s%   optional_double: 0.12345678912345678
s    optional_double: 0.123456789123
(   i   (   R   R?   t   syst   version_infoR*   R   (   R!   R"   R   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testHighPrecisionFloatPrintingS  s
    	c         C   sR   | j    } t j |  | j   } | j | j    |  j t |  d  d  S(   Nt    (   R   R	   t   SetAllNonLazyFieldst   TestEmptyMessageR(   R+   R*   R   (   R!   R"   t	   populatedt   empty(    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testUnknownFieldPrinting[  s
    c         C   s  | j    } | j j d d  | j j d d  | j j d d  | j j d d  |  j d d d d g g  | j D] } | j ^ qw  |  j d d d d g g  t | j  D] } | j ^ q  |  j d d d d g g  | j d  d  d  D] } | j ^ q  d  S(   Nt   bbi   i   i   i   i(   R   t   repeated_nested_messaget   addR*   R]   t   reversed(   R!   R"   t   msgt   m(    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt    testRepeatedNestedFieldIterationb  s     &c         C   s  | j    } | j j d  | j j d  | j j d  | j j   |  j | j d d  |  j | j d d  |  j | j d d  | j j d  | j j d  | j j d  | j j   |  j | j d d  |  j | j d d  |  j | j d d  | j j d  | j j d	  | j j d
  | j j   |  j | j d d  |  j | j d d
  |  j | j d d	  | j j d  | j j d	  | j j d
  | j j   |  j | j d d  |  j | j d d
  |  j | j d d	  d S(   s7   Check some different types with the default comparator.i   i   i   i    g?g?g333333?t   at   ct   bN(	   R   t   repeated_int32t   appendt   sortR*   R@   t   assertAlmostEqualt   repeated_stringt   repeated_bytes(   R!   R"   R   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt0   testSortingRepeatedScalarFieldsDefaultComparatorp  s:    c         C   s   | j    } | j j d  | j j d  | j j d  | j j d t  |  j | j d d  |  j | j d d  |  j | j d d  | j j d  | j j d	  | j j d
  | j j d t  |  j | j d d
  |  j | j d d	  |  j | j d d  d S(   s2   Check some different types with custom comparator.iiit   keyi    i   i   t   aaaR]   Re   N(   R   Rg   Rh   Ri   t   absR*   Rk   t   len(   R!   R"   R   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt/   testSortingRepeatedScalarFieldsCustomComparator  s    c         C   s4  | j    } d | j j   _ d | j j   _ d | j j   _ d | j j   _ d | j j   _ d | j j   _ | j j d t j d   |  j | j d	 j d  |  j | j d j d  |  j | j d j d  |  j | j d j d  |  j | j d j d  |  j | j d j d  d
 S(   sE   Check passing a custom comparator to sort a repeated composite field.i   i   i   i   i   i   Rn   R]   i    N(   R   R^   R_   R]   Ri   t   operatort
   attrgetterR*   (   R!   R"   R   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt2   testSortingRepeatedCompositeFieldsCustomComparator  s    c         C   sC  | j    } d | j j   _ d | j j   _ d | j j   _ d | j j   _ d | j j   _ d | j j   _ d | j j   _ | j j d d	    |  j d d d d d d d g g  | j D] } | j ^ q  | j   } | j   | j |  |  j d d d d d d d g g  | j D] } | j ^ q) d
 S(   sE   Check passing a custom comparator to sort a repeated composite field.i   i   i   i!   i   i   i
   Rn   c         S   s   |  j  d S(   Ni
   (   R]   (   t   z(    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   <lambda>  s    N(	   R   R^   R_   R]   Ri   R*   R+   t   Cleart   MergeFromString(   R!   R"   R   t   nt   pb(    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt(   testSortingRepeatedCompositeFieldsStable  s$     
c         C   s  | j    } t j d  } d   } d | j j   _ d | j j   _ d | j j   _ d | j j   _ d | j j   _ d | j j   _ | j j d	 |  |  j g  | j D] } | j ^ q d d d d d d g  | j j d	 | d
 t  |  j g  | j D] } | j ^ qd d d d d d g  t	 j
 d k rEd S| j j d |  |  j g  | j D] } | j ^ qhd d d d d d g  | j j d | d
 t  |  j g  | j D] } | j ^ qd d d d d d g  d S(   sE   Check sorting a repeated composite field using list.sort() arguments.R]   c         S   s   t  |  j | j  S(   N(   t   cmpR]   (   Rd   Rf   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyRw     s    i   i   i   i   i   i   Rn   t   reverseNt   sort_functionR}   (   i   (   R   Rs   Rt   R^   R_   R]   Ri   R*   t   TrueRT   RU   (   R!   R"   R   t   get_bbt   cmp_bbt   k(    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt'   testRepeatedCompositeFieldSortArguments  s.    	"" ""c         C   sf  | j    } | j j d  | j j d  | j j d  | j j d t  |  j t | j  d d d g  | j j d t d t  |  j t | j  d d d g  t j	 d k  r7d   } | j j d |  |  j t | j  d d d g  | j j d	 | d t  |  j t | j  d d d g  n  | j
 j d
  | j
 j d  | j
 j d  | j
 j d t  |  j t | j
  d d d
 g  | j
 j d t d t  |  j t | j
  d
 d d g  t j	 d k  rbd   } | j
 j d |  |  j t | j
  d d d
 g  | j
 j d	 | d t  |  j t | j
  d
 d d g  n  d S(   s9   Check sorting a scalar field using list.sort() arguments.iiiRn   R~   i   c         S   s   t  t |   t |   S(   N(   R}   Rp   (   Rd   Rf   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyRw     s    R   R}   Ro   R]   Re   c         S   s   t  t |   t |   S(   N(   R}   Rq   (   Rd   Rf   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyRw     s    N(   i   (   i   (   R   Rg   Rh   Ri   Rp   R*   t   listR   RT   RU   Rk   Rq   (   R!   R"   R   t   abs_cmpt   len_cmp(    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt$   testRepeatedScalarFieldSortArguments  s6    ""	"%""	"c         C   s  | j    } | j    } | j j d  | j j d  | j j d  | j j d  | j j d  | j j d  d | j j   _ d | j j   _ d | j j   _ d | j j   _ d | j j   _ d | j j   _ t j d k r d  S| | k  } | j | j k  } |  j t	 | |  d  |  j t	 | j | j  d  |  j t	 | j d d d g  d  |  j t	 | j | j  d  |  j
 t   t	 | j | j  Wd  QXd  S(   Ni    i   i   i   (   i   (   R   Rg   Rh   R^   R_   R]   RT   RU   R*   R}   R   t	   TypeError(   R!   R"   t   m1t   m2t   _(    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testRepeatedFieldsComparable  s2     %c         C   s<   | j    } |  j | j t j  |  j | j t j  d  S(   N(   R   t   assertIsInstanceRg   t   collectionst   MutableSequenceR^   (   R!   R"   Rb   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testRepeatedFieldsAreSequences1  s    c         C   s'   t  | |  |  j | j |   d S(   s   Make sure that a nested message object exists.

    As soon as a nested message attribute is accessed, it will be present in the
    _fields dict, without being marked as actually being set.
    N(   t   getattrt   assertFalset   HasField(   R!   Ra   t	   attribute(    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   ensureNestedMessageExists7  s    c         C   s&   | j    } |  j t | j d  d  S(   Nt   no_such_oneof_field(   R   R   t
   ValueErrort
   WhichOneof(   R!   R"   Rb   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt    testOneofGetCaseNonexistingField@  s    c         C   s   | j    } |  j d  | j d   |  j | j d   d | _ |  j d | j d   |  j | j d   |  j | j d   d | _	 |  j d | j d   |  j | j d   |  j | j d   d  S(   Nt   oneof_fieldt   oneof_uint32i    t   oneof_stringRW   (
   R   t   assertIst   NoneR   R   R   R   R*   R=   R   (   R!   R"   Rb   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testOneofDefaultValuesD  s    		c         C   s  | j    } |  j d  | j d   d | _ |  j d | j d   |  j | j d   d | _ |  j d | j d   |  j	 | j d   |  j | j d   | j
 |  j d | j d   |  j | j d   |  j	 | j d   | j
 j |  j d | j d   |  j | j d   |  j	 | j d   d | j
 _ |  j d | j d   |  j	 | j d   |  j | j d   d | _ |  j d | j d   |  j	 | j d   |  j | j d   d  S(	   NR   i   R   u   fooR   t   oneof_nested_messageR]   t   oneof_bytes(   R   R   R   R   R   R*   R=   R   R   R   R   R]   R   (   R!   R"   Rb   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testOneofSemanticsT  s2    		
	c         C   sU   | j    } d | _ |  j | d  |  j d | j d   |  j d | j  d  S(   Ni   R   R   R   (   R   R   R   R*   R   (   R!   R"   Rb   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt!   testOneofCompositeFieldReadAccessw  s
    	c         C   s  | j    } |  j d  | j d   | t k rJ |  j | j d   n  d | _ |  j d | j d   | t k r |  j	 | j d   n  d | _
 |  j d | j d   | j d  |  j d  | j d   | t k r |  j | j d   n  d  S(   NR   i   R   R]   R   (   R   R   R   R   R   R   R   R   R*   R=   R   t
   ClearField(   R!   R"   Rb   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testOneofWhichOneof  s    		c         C   sz   | j    } d | _ | j d  | t k rG |  j | j d   n  |  j | j d   |  j d  | j d   d  S(   Ni   R   R   (	   R   R   R   R   R   R   R   R   R   (   R!   R"   Rb   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testOneofClearField  s    	c         C   sz   | j    } d | _ | j d  | t k rG |  j | j d   n  |  j | j d   |  j d  | j d   d  S(   Ni   R   R   (	   R   R   R   R   R   R   R   R   R   (   R!   R"   Rb   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testOneofClearSetField  s    	c         C   s   | j    } d | _ |  j | d  | j d  |  j d | j  | t k rj |  j | j d   n  |  j | j d   |  j d | j d   d  S(   Ni   R   R   R   (	   R   R   R   R   R*   R   R=   R   R   (   R!   R"   Rb   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testOneofClearUnsetField  s    	c         C   sQ   | j    } d | _ | j    } | j | j    |  j d | j d   d  S(   Ni   R   R   (   R   R   R(   R+   R*   R   (   R!   R"   Rb   R   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testOneofDeserialize  s
    	c         C   sK   | j    } d | _ | j    } | j |  |  j d | j d   d  S(   Ni   R   R   (   R   R   t   CopyFromR*   R   (   R!   R"   Rb   R   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testOneofCopyFrom  s
    	c         C   s   | j    } d | j _ | j    } d | j _ d | j j _ | j |  |  j d | j j d   |  j d | j j j d   d  S(   Ni   R]   R   R   R   (   t   NestedTestAllTypest   payloadR   R   t   childt	   MergeFromR*   R   (   R!   R"   Rb   R   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testOneofNestedMergeFrom  s    c         C   s   | j    } d | j j _ d | j j j _ | j    } d | j _ | j |  |  j d | j j d   |  j d | j j j d   d  S(   Ni   i   i   R   R   (	   R   R   R   R]   R   R   R   R*   R   (   R!   R"   Rb   R   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testOneofMessageMergeFrom  s    		c         C   s8   | j  d | j  j    } |  j d | j d   d  S(   NR   R   (   R   t   NestedMessageR*   R   (   R!   R"   Rb   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testOneofNestedMessageInit  s    	c         C   s[   | j    } d | _ | j   |  j | j d   d | _ |  j d | j d   d  S(   Ni   R   R]   R   (   R   R   Rx   t   assertIsNoneR   R   R*   (   R!   R"   Rb   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testOneofClear  s    	
	c         C   s5   | j    } t d  | _ |  j | j t j  d S(   sm   Assigning a byte string to a string field should result
    in the value being converted to a Unicode string.RW   N(   R   R   t   optional_stringR   t   sixt	   text_type(   R!   R"   Rb   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt"   testAssignByteStringToUnicodeField  s    c         C   s   | j    } | j j d  | j t d  t t | j   !} |  j t | j  t |   d | j j   _ | j t d  t t | j   !} |  j t | j  t |   d S(   s|   It should be possible to use long-valued indicies in slices

    This didn't used to work in the v2 C++ implementation.
    i   i    i   N(	   R   Rg   Rh   t   longRq   R*   R^   R_   R]   (   R!   R"   Rb   t   sl(    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testLongValuedSlice  s    %%c      	   C   s   | j    } |  j t  ' } | j j d   t d  D  Wd QX|  j t  ' } | j j d   t d  D  Wd QXd S(   s5   This didn't use to work in the v2 C++ implementation.c         s   s   |  ] } t  Vq d  S(   N(   Rd   (   t   .0t   i(    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pys	   <genexpr>  s    i
   Nc         s   s   |  ] } t  Vq d  S(   N(   Rd   (   R   R   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pys	   <genexpr>  s    (   R   R   t	   NameErrorRg   t   extendt   ranget   repeated_nested_enum(   R!   R"   Rb   R   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt$   testExtendShouldNotSwallowExceptions  s    &	i    g        RW   u    c         C   s}   | j    } |  j g  | j  x4 t j D]) } | j j |  |  j g  | j  q) W| j j g   |  j g  | j  d S(   s,   Test no-ops extending repeated int32 fields.N(   R   t   assertSequenceEqualRg   R   t   FALSY_VALUESR   (   R!   R"   Rb   t   falsy_value(    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testExtendInt32WithNothing  s    c         C   s}   | j    } |  j g  | j  x4 t j D]) } | j j |  |  j g  | j  q) W| j j g   |  j g  | j  d S(   s,   Test no-ops extending repeated float fields.N(   R   R   R@   R   R   R   (   R!   R"   Rb   R   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testExtendFloatWithNothing  s    c         C   s}   | j    } |  j g  | j  x4 t j D]) } | j j |  |  j g  | j  q) W| j j g   |  j g  | j  d S(   s-   Test no-ops extending repeated string fields.N(   R   R   Rk   R   R   R   (   R!   R"   Rb   R   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testExtendStringWithNothing  s    c         C   s   | j    } |  j g  | j  | j j d g  |  j d g | j  | j j d d g  |  j d d d g | j  | j j d d g  |  j d d d d d g | j  d S(   s7   Test extending repeated int32 fields with python lists.i    i   i   i   i   N(   R   R   Rg   R   (   R!   R"   Rb   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testExtendInt32WithPythonList*  s    c         C   s   | j    } |  j g  | j  | j j d g  |  j d g | j  | j j d d g  |  j d d d g | j  | j j d d g  |  j d d d d d g | j  d S(   s7   Test extending repeated float fields with python lists.g        g      ?g       @g      @g      @N(   R   R   R@   R   (   R!   R"   Rb   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testExtendFloatWithPythonList5  s    c         C   s   | j    } |  j g  | j  | j j d g  |  j d g | j  | j j d d g  |  j d d d g | j  | j j d d g  |  j d d d d d g | j  d S(   s8   Test extending repeated string fields with python lists.RW   t   11t   22t   33t   44N(   R   R   Rk   R   (   R!   R"   Rb   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testExtendStringWithPythonList@  s    c         C   sO   | j    } |  j g  | j  | j j d  |  j d d d g | j  d S(   sD   Test extending repeated string fields with characters from a string.t   abcRd   Rf   Re   N(   R   R   Rk   R   (   R!   R"   Rb   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testExtendStringWithStringK  s    t   TestIterablec           B   s5   e  Z d  Z d d  Z d   Z d   Z d   Z RS(   s   This iterable object mimics the behavior of numpy.array.

    __nonzero__ fails for length > 1, and returns bool(item[0]) for length == 1.

    c         C   s   | p	 g  |  _  d  S(   N(   t   _list(   R!   t   values(    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   __init__Y  s    c         C   sL   t  |  j  } | d k r t S| d k r< t |  j d  St d   d  S(   Ni    i   s   Truth value is ambiguous.(   Rq   R   t   Falset   boolR   (   R!   t   size(    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   __nonzero__\  s    c         C   s   t  |  j  S(   N(   Rq   R   (   R!   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   __len__d  s    c         C   s   |  j  j   S(   N(   R   t   __iter__(   R!   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyR   g  s    N(   t   __name__t
   __module__t   __doc__R   R   R   R   R   (    (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyR   R  s
   		c         C   s   | j    } |  j g  | j  | j j t j g    |  j g  | j  | j j t j d g   |  j d g | j  | j j t j d d g   |  j d d d g | j  | j j t j d d g   |  j d d d d d g | j  d S(   s3   Test extending repeated int32 fields with iterable.i    i   i   i   i   N(   R   R   Rg   R   R   R   (   R!   R"   Rb   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testExtendInt32WithIterablej  s    c         C   s   | j    } |  j g  | j  | j j t j g    |  j g  | j  | j j t j d g   |  j d g | j  | j j t j d d g   |  j d d d g | j  | j j t j d d g   |  j d d d d d g | j  d S(   s3   Test extending repeated float fields with iterable.g        g      ?g       @g      @g      @N(   R   R   R@   R   R   R   (   R!   R"   Rb   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testExtendFloatWithIterablew  s    c         C   s   | j    } |  j g  | j  | j j t j g    |  j g  | j  | j j t j d g   |  j d g | j  | j j t j d d g   |  j d d d g | j  | j j t j d d g   |  j d d d d d g | j  d S(   s4   Test extending repeated string fields with iterable.RW   t   1t   2t   3t   4N(   R   R   Rk   R   R   R   (   R!   R"   Rb   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testExtendStringWithIterable  s    c         C   si   t  j   d k s$ t  j   d k r( d  S| j   } |  j t j   } t j | j t j	  Wd  QXd  S(   Nt   cppi   (
   R   R   t   VersionR   R   R7   t   PickleErrorR8   Rg   t   HIGHEST_PROTOCOL(   R!   R"   Rb   R   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt!   testPickleRepeatedScalarContainer  s    c         C   s   | j    } | j j   d S(   s?   Exercise a scenario that has led to segfaults in the past.
    N(   R   R^   Ri   (   R!   R"   Rb   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt'   testSortEmptyRepeatedCompositeContainer  s    c         C   s5   | j    } |  j t   } | j d  Wd QXd S(   sB   Using HasField on a repeated field should raise an exception.
    Rg   N(   R   R   R   R   (   R!   R"   Rb   R   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testHasFieldOnRepeatedField  s    c         C   s   | j    } |  j t   } | j j   Wd  QX| j j t d   |  j d | j j    |  j d | j j d   |  j d | j j d   |  j d d g | j  d  S(   Ni   i   i    i   i   i   (   R   R   t
   IndexErrorRg   t   popR   R   R*   (   R!   R"   Rb   R   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testRepeatedScalarFieldPop  s    c         C   s   | j    } |  j t   } | j j   Wd  QXx, t d  D] } | j j   } | | _ q> W|  j d | j j   j  |  j d | j j d  j  |  j d | j j d  j  |  j d d g g  | j D] } | j ^ q  d  S(   Ni   i   i    i   i   i   (	   R   R   R   R^   R   R   R_   R]   R*   (   R!   R"   Rb   R   R   Rz   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testRepeatedCompositeFieldPop  s    N(B   R   R   R%   R1   R6   R<   RB   RC   RE   RH   RI   RJ   RQ   RR   RS   RV   R\   Rc   Rm   Rr   Ru   R|   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   t	   bytearrayt   setR   R   R   R   R   R   R   R   t   objectR   R   R   R   R   R   R   R   R   (    (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyR   _   sv   	
													-	-					%					 	#						#										
							*														
t
   Proto2Testc           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 | j d   |  j | j d   |  j | j d   |  j t   | j d  Wd  QX|  j t   | j d  Wd  QX|  j t   | j d  Wd  QX|  j d | j  |  j t | j	  |  j d | j
 j  d | _ t | _	 d | j
 _ |  j | j d   |  j | j d   |  j | j d   d | _ t | _	 d	 | j
 _ |  j | j d   |  j | j d   |  j | j d   | j d  | j d  | j d  |  j | j d   |  j | j d   |  j | j d   |  j d | j  |  j t | j	  |  j d | j
 j  d  S(
   Nt   optional_int32t   optional_boolt   optional_nested_messaget   field_doesnt_existRg   R^   i    i   i   (   R   R   R   R   R   R   R*   R   R   R   R   R]   R=   R   R   (   R!   R   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testFieldPresence  sD    				c         C   sJ   t  j   } |  j t   } d | _ Wd QX|  j t | j j d  d S(   sP   It should not be possible to assign an invalid enum number to an
    enum field.i N(   R   R   R   R   t   optional_nested_enumR   Rh   (   R!   Rb   R   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testAssignInvalidEnum  s    c         C   s   t  j d  } t j   } | j |  t j   } t  j |  |  j | |  |  j | | j    t j	 |  } |  j | | j    d  S(   NR/   (
   R	   R   R   t   TestAllExtensionsR(   t   SetAllExtensionsR*   R+   R,   R-   (   R!   R.   R/   R5   R0   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testGoldenExtensions  s    c         C   s   t  j d  } t j   } | j |  t j   } t  j |  |  j | |  |  j | | j    t j	 |  } |  j | | j    d  S(   NR2   (
   R	   R   R   t   TestPackedExtensionsR(   t   SetAllPackedExtensionsR*   R+   R,   R-   (   R!   R.   R/   R5   R0   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testGoldenPackedExtensions  s    c         C   sm   t  j d d  } t j |  } t j |  } |  j | |  |  j | j d  |  j t j	 | j
  d  S(   NRd   i   (   R   t   TestRequiredR7   R8   R9   R*   Rd   R   R   t   EncodeErrorR+   (   R!   R/   R:   R;   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testPickleIncompleteProto  s    c         C   s`  t  j   t  j   t  j   g } d | d _ d | d _ d | d _ d | d _ t  j   } d | _ d | _ d | _ t  j j   } | j j |  | j	 j |  | j
 j |  | j j |  | j j |  | j j   j j | d  | j j   j j | d  | j j   j j | d  | j j   j j | d  | j j   j j | d  | j j   j j | d  | j   } t  j   } | j |  |  j | j |  |  j | j |  |  j | j j |  |  j | j t  j j |  |  j t | j  d  |  j t | j  d  |  j t | j t  j j  d  d S(   sc   Check the merge behavior when a required or optional field appears
    multiple times in the input.i   i    i   i   t   helloN(   R   R   R   t   optional_int64R   t   TestParsingMerget   RepeatedFieldsGeneratort   field1R   t   field2t   field3t   ext1t   ext2t   group1R_   R   t   group2R+   R(   R*   t   required_all_typest   optional_all_typest   optionalgroupt   optional_group_all_typest
   Extensionst   optional_extRq   t   repeated_all_typest   repeatedgroupt   repeated_ext(   R!   t   messagest   merged_messaget	   generatort   datat   parsing_merge(    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testParsingMerge'  sJ    					
c         C   sK  t  j d d d d d d d d d	 i d
 d 6d i d d 6d i  d d d i d d 6i d d 6g d d t  j j g d d d d  } |  j | t  j  |  j d | j  |  j d | j  |  j d | j  |  j d | j  |  j d
 | j	 j
  |  j | j t  j j  |  j d | j j  |  j | j d   |  j | j t  j    |  j t  j j | j  |  j d t | j   |  j d | j d j
  |  j d | j d j
  |  j d t | j   |  j t  j j | j d  |  j t  j j | j d  |  j d | j  |  j d | j  |  j | j d   |  j d t | j   |  j d | j  t  j d d   } |  j t  j j | j  |  j t   t  j d i d! d" 6 Wd  QX|  j t   t  j d i d# d 6 Wd  QX|  j t   t  j d d$  Wd  QX|  j t   t  j d d  Wd  QXd  S(%   NR   id   t   optional_fixed32i   R>   g     r@t   optional_bytest   xR  i  Rd   R   i  R]   t   optional_foreign_messageR   t   BAZR  iX  i  R   t   FOOt   default_int32i   R   t   yi   i    i   R  i*   u   BAZi   t   INVALID_NESTED_FIELDt   INVALID_VALUE_TYPEt   INVALID_LABEL(    R   R   t   BARR   R*   R   R!  R>   R"  R  Rd   R   R   R]   R=   R   R$  t   ForeignMessageR%  R   Rq   R  R   R&  R'  R   R   R@   t   default_int64R   R   R   (   R!   R   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testPythonicInitX  sl    	
	

		(	   R   R   R   R   R   R  R  R   R/  (    (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyR     s   	4						1t
   Proto3Testc           B   s   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   c         C   sR   t  |  } x/ | D]' \ } } |  j | | |  | | =q W|  j i  |  d  S(   N(   t   dictR*   (   R!   t   map_itert
   dict_valueR   t   v(    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   assertMapIterEquals  s
    c         C   sr  t  j   } |  j t   | j d  Wd  QX|  j t   | j d  Wd  QX|  j t   | j d  Wd  QX|  j t   | j d  Wd  QX|  j | j d   |  j t   | j d  Wd  QX|  j t   | j d  Wd  QX|  j t   | j d  Wd  QX|  j d	 | j  |  j d	 | j  |  j d
 | j	  |  j t
 | j  |  j d	 | j j  d	 | j _ |  j | j d   d | _ d | _ d | _	 t | _ d | j _ | j d  | j d  | j d  | j d  | j d  |  j d	 | j  |  j d	 | j  |  j d
 | j	  |  j t
 | j  |  j d	 | j j  d  S(   NR   R>   R   R   R   R   Rg   R^   i    RW   i   g?R   i   (   R   R   R   R   R   R   R*   R   R>   R   R   R   R   R]   R=   R   R   (   R!   R   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyR     sL    				c         C   s   t  j   } d | _ |  j d | j  | j j d  |  j d | j d  d | j d <|  j d | j d  | j   } t  j   } | j |  |  j d | j  |  j d | j d  d S(   sC   Assigning an unknown enum value is allowed and preserves the value.i iTi    it N(   R   R   R   R*   R   Rh   R+   R(   (   R!   Rb   RD   R   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testAssignUnknownEnum  s    	c         C   s  t  j   } |  j d | j k  |  j d | j k  |  j d | j k  |  j d | j k  |  j d | j k  |  j t | j	 k  |  j d | j
 k  |  j d | j k  |  j d | j k  |  j d | j d  |  j d | j d  |  j d | j d  |  j d | j d  |  j d	 | j d  |  j t | j d t   |  j t | j	 t  |  j t | j	 t t   |  j d
 | j
 d  |  j d
 | j d  |  j d | j d  |  j d | j k  |  j d | j k  |  j d | j k  |  j d | j k  |  j d | j k  |  j t | j	 k  |  j d | j
 k  |  j d | j k  |  j d | j k  |  j | j
 d t j  |  j t   | j
 d Wd  QX|  j t   d | j
 k Wd  QXd  S(   Nii   i!   i{   R   io   ix  i    g        RW   I       I    I       I       I    I       I       I    I       (   R    t   TestMapR   t   map_int32_int32t   map_int64_int64t   map_uint32_uint32t   map_uint64_uint64t   map_int32_doubleR   t   map_bool_boolt   map_string_stringt   map_int32_bytest   map_int32_enumR*   R=   t
   isinstancet   floatR   R   R   R   R   R   (   R!   Ra   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testScalarMapDefaults  sF    c         C   s   t  j   } |  j | j j d   |  j d | j j d d   |  j | j j d   d | j d <|  j d | j j d   |  j | j j d   |  j d | j j d d   | j d } |  j | | j j d   d  S(   Ni   i
   i   (   R    R7  R   R8  t   getR*   t   map_int32_foreign_messageR   (   R!   Ra   t   submsg(    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt
   testMapGet%  s    c      
   C   s  t  j   } |  j d t | j   |  j d | j k  d | j d <d | j d <d | j d	 <d | j d <d
 | j	 d <d | j
 d <|  j g  | j    |  j d t | j	   |  j t   d
 | j	 d	 <Wd  QX|  j d t | j	   |  j t   d	 | j	 d
 <Wd  QX| j   } t  j   } | j |  |  j t   d
 | j	 d	 <Wd  QX|  j t   d	 | j	 d
 <Wd  QX|  j d | j d  |  j d | j d  |  j d | j d	  |  j d | j d  |  j d
 | j	 d  |  j d | j
 d  d  S(   Ni    i   i8ii   i"   i!   i  i{   t   123R   ix  i   I       I    I       I    I       I       I       I    I       I    I       I       (   R    R7  R*   Rq   R8  R   R9  R:  R;  R>  R@  t   FindInitializationErrorsR   R   R+   R(   (   R!   Ra   RD   t   msg2(    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testScalarMap7  s:    c         C   s   t  j   } d } | j d  } | | j | <t | j j    d \ } } |  j | |  |  j | |  |  j | t j	  |  j | t j	  d  S(   Nu   ሴt   utf8i    (
   R    R7  t   encodeR>  R   t   itemsR*   R   R   R   (   R!   Ra   t   unicode_objt	   bytes_objRn   t   value(    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt    testStringUnicodeConversionInMapg  s    c         C   s  t  j   } |  j d t | j   |  j d | j k  | j d | j j d  |  j d t | j   |  j d | j  |  j d | j  |  j d t | j   |  j t	   | j d Wd  QX|  j t
   | j d | j d <Wd  QX|  j d t | j   | j   } t  j   } | j |  |  j d t | j   |  j d | j  |  j d | j  |  j d t | j   d  S(   Ni    i   i{   i8i   RH  i  (   R    R7  R*   Rq   RE  R   t   get_or_createR   R   R   R   R+   R(   (   R!   Ra   RD   RJ  (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testMessageMapw  s*    c         C   s  t  j   } d | j d <d | j d <d | j d <d | j d _ d	 | j d
 _ t  j   } d | j d <d | j d <d | j d
 _ d | j d
 _ | j d
 } | j |  |  j d | j d  |  j d | j d  |  j d | j d  |  j d | j d  |  j d | j d j  |  j d	 | j d
 j  |  j	 | j d
 j
 d   |  j d | j  i  } x8 | j D]- } |  j	 | | k  | j | j | | <qW|  j i d d 6d	 d
 6|  | j d =|  j	 d | j k  | j d
 =|  j	 d
 | j k  d  S(   Ni"   i   iN   i8   i!   i   i   io   i
   i   i7   ic   iX   i   i   t   d(   R    R7  R8  R9  RE  Re   RU  R   R*   R   R   (   R!   Ra   RJ  t   old_map_valuet   as_dictRn   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testMergeFrom  s<    

c         C   s6   t  j   } |  j t d   | j d  Wd  QXd  S(   NsW   Parameter to MergeFrom\(\) must be instance of same class: expected .*TestMap got int\.i   (   R    R7  t   assertRaisesRegexpR   R   (   R!   Ra   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testMergeFromBadType  s
    
c         C   s6   t  j   } |  j t d   | j d  Wd  QXd  S(   Ns[   Parameter to [A-Za-z]*From\(\) must be instance of same class: expected .*TestMap got int\.i   (   R    R7  RY  R   R   (   R!   Ra   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testCopyFromBadType  s
    
c         C   s   t  j   } t d  | j t d  <t d	  | j t d  <t d  | j t d  <t d  | j t d  <| j   } t  j   } | j |  |  j	 d | j d  |  j	 d | j d  |  j	 d | j d  |  j	 d | j d  d  S(   Ni8ii   i"   i!   i  i{   I       I    I       I    I       I       I       I    I       I    I       I       (
   R    R7  R   R8  R9  R:  R;  R+   R(   R*   (   R!   Ra   RD   RJ  (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testIntegerMapWithLongs  s    c         C   s   t  j   } d | j j d <| j   } t  j   } | j |  |  j | |  d | j j d <| j   } | j |  |  j | |  | j j j   | j   } | j |  |  j | |  d  S(   Ni  i{   i  ix  (   R    t   TestMapSubmessaget   test_mapR8  R+   R(   R*   t   clear(   R!   Ra   RD   RJ  (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testMapAssignmentCausesPresence  s    c         C   s  t  j   } d | j j d _ | j   } t  j   } | j |  |  j | |  d | j j d _ | j   } | j |  |  j | |  | j j d j | j j d  | j   } | j |  |  j | |  | j j j	   | j   } | j |  |  j | |  d  S(   Ni   i{   i   ix  (
   R    R]  R^  RE  Re   R+   R(   R*   R   R_  (   R!   Ra   RD   RJ  (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt-   testMapAssignmentCausesPresenceForSubmessages  s&    c         C   s   t  j   } t | j  } t | j  } d | j d <d | j d _ |  j t   x | D] } q^ WWd  QX|  j t   x | D] } q WWd  QXd  S(   NRH  R   i   (   R    R7  t   iterR>  RE  Re   R   t   RuntimeError(   R!   Ra   t   string_string_itert   int32_foreign_iterRn   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testModifyMapWhileIterating  s    
c         C   s   t  j   } | j d } |  j | | j d  |  j | t j  d | _ | j   } t  j   } | j	 |  |  j
 d | j d j  |  j t   t j   | j d <Wd  QXd  S(   Nio   i   iX   (   R    R7  RE  R   R   R   R-  Re   R+   R(   R*   R   R   (   R!   Ra   RF  RD   RJ  (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testSubmessageMap,  s    	c         C   s   t  j   } x* | j j   D] \ } } |  j t  q Wd | j d <d | j d <d | j d <|  j d t | j   i d d 6d d 6d d 6} |  j | j j   |  d  S(   Ni   i   i   i   i   (	   R    R7  R8  RN  R=   R   R*   Rq   R5  (   R!   Ra   R   R4  t   matching_dict(    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testMapIteration?  s    c         C   s   t  j   } d | j d <d | j d <d | j d <d | j d <d | j d <| j j   } | j j   } |  j | |  d  S(   NRW   t   local_init_opt   trainable_variablest	   variablest   init_opt	   summaries(   R    R7  R>  RN  R*   (   R!   Ra   t   items1t   items2(    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testMapItemsN  s    c         C   st   t  j   } d | j d <d | j d <d | j d <| j j   } ~ i d d 6d d 6d d 6} |  j | |  d  S(   Ni   i   i   i   i   (   R    R7  R8  RN  R5  (   R!   Ra   t   itRh  (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testMapIterationClearMessage]  s    c         C   s   t  j d i d d 6d d 6 } |  j d | j d  |  j d | j d  t  j d i t j d d  d 6 } |  j d | j d j  d  S(	   NR8  i   i   i   i   RE  Re   i   (   R    R7  R*   R8  R   R-  RE  Re   (   R!   Ra   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testMapConstructionk  s     	c         C   s   t  j   } | j } d | d <d | d <d | d <| j d  |  j d | j    i d d 6d d 6d d 6} |  j | j   |  d  S(   Ni   i   i   i   i   R8  RW   (   R    R7  R8  R   R*   R+   R5  RN  (   R!   Ra   t	   int32_mapRh  (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testMapValidAfterFieldClearedt  s    	


c         C   sb   t  j   } | j } d | d _ | j d  |  j d | j    |  j d | j   k  d  S(   Ni   i   RE  RW   (	   R    R7  RE  Re   R   R*   R+   R=   t   keys(   R!   Ra   t   int32_foreign_message(    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt$   testMessageMapValidAfterFieldCleared  s    	c         C   s   t  j   } t | j  } | j d  |  j t   x | D] } q? WWd  QXt | j  } | j d  |  j t   x | D] } q WWd  QXd  S(   NR8  RE  (   R    R7  Rb  R8  R   R   Rc  RE  (   R!   Ra   Rr  R   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt"   testMapIterInvalidatedByClearField  s    
c         C   s   t  j   } |  j d t | j   d | j d <|  j d t | j   |  j t   | j d =Wd  QX| j d =|  j d t | j   d  S(   Ni    i   i   i   iX   (   R    R7  R*   Rq   R8  R   t   KeyError(   R!   Ra   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testMapDelete  s    
c         C   sh   t  j   } |  j | j t j  |  j | j t j  |  j | j t j  |  j | j t j  d  S(   N(   R    R7  R   R8  R   t   Mappingt   MutableMappingRE  (   R!   Ra   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testMapsAreMapping  s    c         C   sV   t  j   } d | j d <d | j d <d | j d _ |  j d t | j     d  S(   NRH  R   i@   i#   i   t   fooi    (	   R    R7  R>  R8  t   map_string_foreign_messageRe   R*   Rq   RI  (   R!   Ra   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt(   testMapFindInitializationErrorsSmokeTest  s
    (   R   R   R5  R   R6  RC  RG  RK  RR  RT  RX  RZ  R[  R\  R`  Ra  Rf  Rg  Ri  Rq  Rs  Rt  Rv  Ry  Rz  R|  R  R  (    (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyR0    s4   	
	9		0		0		$	.																	t   ValidTypeNamesTestc           B   s   e  Z d    Z d   Z RS(   c            s   t  t |   j d  d   d | d | f } |  j t   f d   | D  d   | f    j d  } | d } d j | d   } t | d	 | g d  S(
   Nt   'i   s   Repeated%sContainers   Repeated%sFieldContainerc         3   s   |  ] }   j  |  Vq d  S(   N(   t   endswith(   R   R4  (   t   tp_name(    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pys	   <genexpr>  s    s   %r does end with any of %rt   .it   fromlist(   R   t   typet   splitR=   t   anyt   joint
   __import__(   R!   Ra   t	   base_namet   valid_namest   partst
   class_namet   module_name(    (   R  sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   assertImportFromName  s    
c         C   s6   t  j   } |  j | j d  |  j | j d  d  S(   Nt   Scalart	   Composite(   R   R   R  Rg   R^   (   R!   R{   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testTypeNamesCanBeImported  s    (   R   R   R  R  (    (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyR    s   	t   PackedFieldTestc           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s   | j  j d  | j j d  | j j d  | j j d  | j j d  | j j d  | j j d  | j j d  | j	 j d  | j
 j d  | j j d  | j j d  | j j t  | j j d  d  S(   Ni   g      ?(   Rg   Rh   t   repeated_int64t   repeated_uint32t   repeated_uint64t   repeated_sint32t   repeated_sint64t   repeated_fixed32t   repeated_fixed64t   repeated_sfixed32t   repeated_sfixed64R@   RA   t   repeated_boolR   R   (   R!   R   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt
   setMessage  s    c         C   s9   t  j   } |  j |  d } |  j | | j    d  S(   NsH   
"*2:   B       J   R       Z  ?b      ?jr(   R   R3   R  R*   R+   (   R!   R   R.   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testPackedFields  s    c         C   s9   t  j   } |  j |  d } |  j | | j    d  S(   Ns:    (0=   A       M   Q       ]  ?a      ?hp(   R   t   TestUnpackedTypesR  R*   R+   (   R!   R   R.   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testUnpackedFields  s    (   R   R   R  R  R  (    (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyR    s   		R   s(   explicit tests of the C++ implementationt   OversizeProtosTestc           B   s2   e  Z e d     Z d   Z d   Z d   Z RS(   c         C   sc   d } t  j   } t j   } t j | |  | j |  t j |  j	 | j
 d   |  _ d  S(   Ns  
      name: "f/f.msg2"
      package: "f"
      message_type {
        name: "msg1"
        field {
          name: "payload"
          number: 1
          label: LABEL_OPTIONAL
          type: TYPE_STRING
        }
      }
      message_type {
        name: "msg2"
        field {
          name: "field"
          number: 1
          label: LABEL_OPTIONAL
          type: TYPE_MESSAGE
          type_name: "msg1"
        }
      }
    s   f.msg2(   R   t   DescriptorPoolR   t   FileDescriptorProtoR   t   Parset   AddR   t   MessageFactoryt   GetPrototypet   FindMessageTypeByNamet	   proto_cls(   t   clst	   file_desct   poolt   desc(    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt
   setUpClass  s    c         C   s8   |  j    |  _ d d |  j j _ |  j j   |  _ d  S(   NRe   i   i@   i   i   i   i  (   R  t   pt   fieldR   R+   t   p_serialized(   R!   (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   setUp9  s    c         C   sm   d d l  m } | t  |  j   } y | j |  j  Wn, t j k
 rh } |  j t	 |  d  n Xd  S(   Ni(   t   SetAllowOversizeProtoss   Error parsing message(
   t   google.protobuf.pyext._messageR  R   R  R(   R  R   t   DecodeErrorR*   R   (   R!   R  t   qt   e(    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testAssertOversizeProto>  s    
c         C   sY   d d l  m } | t  |  j   } | j |  j  |  j |  j j j	 | j j	  d  S(   Ni(   R  (
   R  R  R   R  R(   R  R*   R  R  R   (   R!   R  R  (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   testSucceedOversizeProtoG  s
    
(   R   R   t   classmethodR  R  R  R  (    (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyR    s   #			t   __main__(.   R   t
   __author__R   R,   RK   Rs   R7   R   RT   t	   unittest2t   unittestt   ImportErrort   google.protobufR    R   R   R   R   R   R   t   google.protobuf.internalR   R   R	   R
   R   R   t   PY3t   intR   R   R   R   R   t   BaseTestCaset   NamedParametersR   R   R0  R  R  t   skipIfR   R  R   t   main(    (    (    sG   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_test.pyt   <module>*   sd   								   e  .9	: