ó
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 e j	 f d     YZ
 e d k r e j   n  d S(	   s.   Test for google.protobuf.internal.wire_format.s#   robinson@google.com (Will Robinson)i˙˙˙˙N(   t   message(   t   wire_formatt   WireFormatTestc           B   s>   e  Z d    Z d   Z d   Z d   Z d   Z d   Z RS(   c         C   so   d } d } |  j  | d >| Bt j | |   t j } |  j t j | | d  |  j t j | | d  d  S(   Niź
  i   i   i   i˙˙˙˙(   t   assertEqualR   t   PackTagt   assertRaisesR    t   EncodeError(   t   selft   field_numbert   tag_typeR   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format_test.pyt   testPackTag0   s    	c         C   sČ   xf d	 D]^ } xU t  d  D]G } t j t j | |   \ } } |  j | |  |  j | |  q Wq W|  j t t j d   |  j t t j d  |  j t t j d  |  j t t j t    d  S(
   Ni   i   i   i˙  i   i   t   abcg        (   i   i   i   i˙  i   (	   t   rangeR   t	   UnpackTagR   R   R   t	   TypeErrort   Nonet   object(   R   t   expected_field_numbert   expected_wire_typeR   t	   wire_type(    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format_test.pyt   testUnpackTag;   s    c         C   s"  t  j } |  j d | d   |  j d | d   |  j d | d   |  j d | d   |  j d | d   |  j d | d	   |  j d
 | d   |  j d | d   |  j d | d   |  j t | d   |  j t | d  |  j t | d  |  j t | t    d  S(   Ni    i   i˙˙˙˙i   i   iţ˙˙˙i   Iţ˙˙˙    i˙˙˙I˙˙˙˙    i   l   ţ˙˙˙ I˙˙˙˙˙˙˙l   ˙˙˙˙ I       t   abcdg        (   R   t   ZigZagEncodeR   R   R   R   R   (   R   t   Z(    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format_test.pyt   testZigZagEncodeI   s    	c         C   s"  t  j } |  j d | d   |  j d | d   |  j d | d   |  j d | d   |  j d | d   |  j d | d	   |  j d
 | d   |  j d | d   |  j d | d   |  j t | d   |  j t | d  |  j t | d  |  j t | t    d  S(   Ni    i˙˙˙˙i   i   iţ˙˙˙i   i   i˙˙˙Iţ˙˙˙    i   I˙˙˙˙    I˙˙˙˙˙˙˙l   ţ˙˙˙ I       l   ˙˙˙˙ R   g        (   R   t   ZigZagDecodeR   R   R   R   R   (   R   R   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format_test.pyt   testZigZagDecodeZ   s    	c      
   C   sf   x_ d	 d
 d d f D]K \ } } | | } | | |  } |  j  | | d | | | | | f  q Wd  S(   Ni   i   i   i   i˙  i   i   sF   byte_size_fn: %s, field_number: %d, value: %r
Expected: %d, Actual: %d(   i   i   (   i   i   (   i˙  i   (   i   i   (   R   (   R   t   byte_size_fnt   valuet   expected_value_sizeR   t	   tag_bytest   expected_sizet   actual_size(    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format_test.pyt   NumericByteSizeTestHelperk   s    
c      6   C   sT  t  j d d g t  j d d g t  j d d g t  j d d g t  j d d g t  j d d g t  j d d g t  j d d g t  j d d g t  j d d g t  j d d g t  j t  j d g t  j d d g t  j d d g t  j d d g t  j t  j d g t  j d d g t  j d d g t  j d d g t  j d	 d g t  j d
 d g t  j d d g t  j d d g t  j d d g t  j d d g t  j d d g t  j d	 d g t  j d
 d g t  j d d g t  j d d g t  j	 d d g t  j	 t  j d g t  j
 d d g t  j
 t  j d g t  j d d g t  j t  j d g t  j t  j d g t  j d d g t  j t  j d g t  j t  j d g t  j d d g t  j d d g t  j d d g t  j d d g t  j d d g t  j d d g t  j t d g t  j t d g t  j d d g t  j d d g t  j d d g t  j t  j d g g4 } x | D] } |  j |   q4Wxi t  j t  j f D]U } |  j d | d d   |  j d | d d   |  j d | d d d   q^W|  j d t  j d d j d    d t f d     Y} d } | d |  } |  j d | t  j d |   |  j d | t  j d |   |  j d | j t  j d |   |  j d | j t  j d |   d | _ |  j d | j t  j d |   d | _ |  j | j d t  j  d |   d | _ |  j | j d t  j  d |   |  j | j d t  j  d |   |  j! t" j# t  j d d  d  S(   Ni    i   i   i   i   i˙˙˙˙i
   i   iÁ˙˙˙i?   iŔ˙˙˙i@   i   i   g        g    eÍÍAg    eÍÍÁR   i   i   i   t   as   Đ˘ĐľŃŃs   utf-8t   MockMessagec           B   s   e  Z d    Z d   Z RS(   c         S   s   | |  _  d  S(   N(   t	   byte_size(   R   R$   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format_test.pyt   __init__Í   s    c         S   s   |  j  S(   N(   R$   (   R   (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format_test.pyt   ByteSizeĎ   s    (   t   __name__t
   __module__R%   R&   (    (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format_test.pyR#   Ě   s   	R$   i   i   l	                    ($   R   t   Int32ByteSizet   Int64ByteSizet   UInt32ByteSizet
   UINT32_MAXt   UInt64ByteSizet
   UINT64_MAXt   SInt32ByteSizet   SInt64ByteSizet   Fixed32ByteSizet   Fixed64ByteSizet   SFixed32ByteSizet	   INT32_MINt	   INT32_MAXt   SFixed64ByteSizet	   INT64_MINt	   INT64_MAXt   FloatByteSizet   DoubleByteSizet   BoolByteSizet   Falset   Truet   EnumByteSizeR!   t   StringByteSizet   BytesByteSizeR   t   decodeR   t   GroupByteSizeR$   t   MessageByteSizet   MessageSetItemByteSizeR   R    R   (   R   t   NUMERIC_ARGSt   argsR   R#   t   message_byte_sizet   mock_message(    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format_test.pyt   testByteSizeFunctionsu   s¨    !			(   R'   R(   R
   R   R   R   R!   RI   (    (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format_test.pyR   .   s   					
t   __main__(   t   __doc__t
   __author__t	   unittest2t   unittestt   ImportErrort   google.protobufR    t   google.protobuf.internalR   t   TestCaseR   R'   t   main(    (    (    sK   /tmp/pip-build-h1VYrz/protobuf/google/protobuf/internal/wire_format_test.pyt   <module>!   s   Ň