ó
X¾÷Xc           @   sÒ   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
 e j f d „  ƒ  YZ e d k rÎ e j ƒ  n  d S(   s*   Tests for google.protobuf.message_factory.s"   matthewtoia@google.com (Matt Toia)iÿÿÿÿN(   t   descriptor_pb2(   t   factory_test1_pb2(   t   factory_test2_pb2(   t   descriptor_database(   t   descriptor_pool(   t   message_factoryt   MessageFactoryTestc           B   s5   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s:   t  j j t j j ƒ |  _ t  j j t j j ƒ |  _ d  S(   N(	   R    t   FileDescriptorProtot
   FromStringR   t
   DESCRIPTORt   serialized_pbt   factory_test1_fdR   t   factory_test2_fd(   t   self(    (    sO   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_factory_test.pyt   setUp4   s    		c         C   sÇ  | ƒ  } d | _  d | _ d | j _ d | j _ d | j _ d | j j _ d | j _ | j j	 j
 d d d g ƒ | j j	 j d	 ƒ d | _ d | _ d | j _ d | j _  d
 | j j _  d | j _ d | _ | j	 j
 d	 d d g ƒ | j	 j d ƒ | j j ƒ  d | j d _ d | j d _ | j j d d d d ƒ d
 | j j _  d | j j j j _  | j ƒ  } t j j | ƒ } | j ƒ  } |  j | | ƒ | j | ƒ } |  j | | ƒ d  S(   Ni*   i    s   nested message valuei   i   u   oneu   twou   threeu   fouri   s   one deeps	   zero deept   hellot   worldt   part_1t   testingt   part_2t   123i   (   t	   mandatoryt   nested_factory_2_enumt   nested_factory_2_messaget   valuet   factory_1_messaget   factory_1_enumt   nested_factory_1_enumt   nested_factory_1_messaget   scalar_valuet
   list_valuet   extendt   appendt   circular_messaget   groupedt   addR   R   t   loopt   SerializeToStringR   t   Factory2MessageR   t   assertEqual(   R   t   clst   msgt
   serializedt	   convertedt   reserializedt   result(    (    sO   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_factory_test.pyt   _ExerciseDynamicClass:   s>    						c         C   s±   t  j ƒ  } t j | ƒ } | j |  j ƒ | j |  j ƒ t j ƒ  } | j	 | j
 d ƒ ƒ } |  j | t j k ƒ |  j | ƒ | j	 | j
 d ƒ ƒ } |  j | | k ƒ d  S(   Ns/   google.protobuf.python.internal.Factory2Message(   R   t   DescriptorDatabaseR   t   DescriptorPoolt   AddR   R   R   t   MessageFactoryt   GetPrototypet   FindMessageTypeByNamet   assertFalseR   R&   R.   t
   assertTrue(   R   t   dbt   poolt   factoryR(   t   cls2(    (    sO   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_factory_test.pyt   testGetPrototype\   s    c         C   s?  x8t  d ƒ D]*} t j |  j |  j g ƒ } |  j t d d g ƒ j t | j ƒ  ƒ ƒ ƒ |  j	 | d ƒ | d } |  j t d d g ƒ j t d „  | j
 j j j | j
 ƒ Dƒ ƒ ƒ ƒ | d ƒ  } | j j d ƒ } | j j d ƒ } d | j | <d | j | <|  j d | j | ƒ |  j d | j | ƒ q Wd  S(	   Ni   s/   google.protobuf.python.internal.Factory2Messages/   google.protobuf.python.internal.Factory1Messages>   google.protobuf.python.internal.Factory2Message.one_more_fields-   google.protobuf.python.internal.another_fieldc         s   s   |  ] } | j  Vq d  S(   N(   t	   full_name(   t   .0t   ext(    (    sO   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_factory_test.pys	   <genexpr>y   s   t   test1t   test2(   t   rangeR   t   GetMessagesR   R   R6   t   sett   issubsett   keysR.   R	   t   fileR8   t   FindAllExtensionst
   Extensionst   _FindExtensionByNameR'   (   R   t   _t   messagest   factory_msg1t   msg1t   ext1t   ext2(    (    sO   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_factory_test.pyt   testGetMessagesj   s2    
					c   	      C   s>  t  j ƒ  } t j d | ƒ } t j ƒ  } d | _ d | _ | j j	 ƒ  } d | _ | j
 j	 ƒ  } d | _ d | _ | j | ƒ | j | j g ƒ } |  j d | ƒ t j ƒ  } d | _ d | _ | j j d ƒ | j j	 ƒ  } d	 | _ | j j	 ƒ  } d
 | _ d | _ t j j | _ d	 | _ d | _ | j | ƒ | j | j g ƒ } |  j d | ƒ t j ƒ  } d | _ d | _ | j j d ƒ | j j	 ƒ  } d | _ | j j	 ƒ  } d
 | _ d | _ t j j | _ d | _ d | _ | j | ƒ |  j t ƒ  } | j | j g ƒ Wd  QX|  j | j t t f ƒ d  S(   NR8   s(   google/protobuf/internal/container.protos   google.protobuf.python.internalt	   Containeri   i
   s)   google.protobuf.python.internal.Containers(   google/protobuf/internal/extension.protot	   Extensiont   extension_fieldi   s)   google.protobuf.python.internal.Extensions(   google/protobuf/internal/duplicate.protot	   Duplicate(   R   R0   R   R2   R    R   t   namet   packaget   message_typeR#   t   extension_ranget   startt   endR1   RB   t   assertInt
   dependencyR    t	   extensiont   numbert   FieldDescriptorProtot   LABEL_OPTIONALt   labelt	   type_namet   extendeet   assertRaisest	   Exceptiont   assertIsInstancet	   exceptiont   AssertionErrort
   ValueError(	   R   R8   R9   t   fR)   t   rngt   msgsR>   t   cm(    (    sO   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_factory_test.pyt   testDuplicateExtensionNumber†   sX    																			(   t   __name__t
   __module__R   R.   R;   RP   Rn   (    (    (    sO   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_factory_test.pyR   2   s
   		"		t   __main__(   t   __doc__t
   __author__t	   unittest2t   unittestt   ImportErrort   google.protobufR    t   google.protobuf.internalR   R   R   R   R   t   TestCaseR   Ro   t   main(    (    (    sO   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/message_factory_test.pyt   <module>!   s   ‹