
    e                         d dl Z d dlZd dlmZ d dlZd dlmZ d dl	m
Z
 dZd dlmZ d dlmZ dZ G d d	e      Z G d
 de      Z G d de      Zd Z G d dej,                        Zy)    N)client)base)timezone)msgpackutils)	uuidutilsz%Y-%m-%d %H:%M:%S %Z%zc                       e Zd Zd Zy)Colorc                 .    || _         || _        || _        y N)rgb)selfr   r   r   s       L/usr/lib/python3/dist-packages/oslo_serialization/tests/test_msgpackutils.py__init__zColor.__init__!   s        N)__name__
__module____qualname__r    r   r   r	   r	       s    r   r	   c                   x    e Zd ZefZej                  j                  j                  dz   Z	e
d        Ze
d        Zy)ColorHandler   c                 x    | j                   d| j                  d| j                  }|j                  d      }|S )Nz, ascii)r   r   r   encode)objblobs     r   	serializezColorHandler.serialize-   s-    "uuceeSUU3{{7#r   c                     | j                  d      D cg c]  }t        |j                                }}t        |d   |d   |d         S c c}w )N   ,r   r      )splitintstripr	   )datacchunkss      r   deserializezColorHandler.deserialize3   sH    *.**T*:;Q#aggi.;;VAYq	6!955 <s    AN)r   r   r   r	   handlesr   HandlerRegistrynon_reserved_extension_range	min_valueidentitystaticmethodr   r)   r   r   r   r   r   '   sP    hG$$AAKKaO   
 6 6r   r   c                   >    e Zd ZefZej                  j                  Zy)MySpecialSetHandlerN)r   r   r   setr*   r   
SetHandlerr.   r   r   r   r1   r1   9   s    fG&&//Hr   r1   c                 V    t        j                  |       } t        j                  |       S r   )r   dumpsloads)r   s    r   _dumps_loadsr7   >   s#    


S
!Cc""r   c                       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y)MsgPackUtilsTestc                 B    | j                  g dt        g d             y Nr   r"      assertEqualr7   r   s    r   	test_listzMsgPackUtilsTest.test_listD   s    L$;<r   c                 :    | j                  g t        g              y r   r>   r@   s    r   test_empty_listz MsgPackUtilsTest.test_empty_listG       \"-.r   c                 >    | j                  g dt        d             y r;   r>   r@   s    r   
test_tuplezMsgPackUtilsTest.test_tupleJ   s     	L$;<r   c           
      j    | j                  t        ddd      t        t        ddd                   y )Nr   r"   r=   )ar   r'   )r?   dictr7   r@   s    r   	test_dictzMsgPackUtilsTest.test_dictR   s,    Q!,%dQ!q&9:	<r   c                 :    | j                  i t        i              y r   r>   r@   s    r   test_empty_dictz MsgPackUtilsTest.test_empty_dictV   rD   r   c                 *   t        j                   ddddddd      t        j                   ddddddd	      d
dg t        g d      t        j                         ddt         j                  j                         d
}| j                  |t        |             y )N  r"   r=               i  	   r   g       @r<   yyys   bbb)
nowlaterrH   r   r'   dzzzrT   dddtoday)datetimer2   r   generate_uuiddaterZ   r?   r7   )r   srcs     r   test_complex_dictz"MsgPackUtilsTest.test_complex_dictY   s    $$T1aAq!<&&tQ1aA>Y**,]]((*
 	l3/0r   c                 @   t        j                  d      }t        |       t        |       t        |      }| j	                  t        |      t        |             t        j                  d      }t        |      }| j	                  t        |      t        |             y )Nr   r   )	itertoolscountnextr7   r?   r   itit2s      r   test_itercountzMsgPackUtilsTest.test_itercounth   sp    __QRR2b49-__Q2b49-r   c                     t        j                  dd      }t        |      }| j                  t	        |      t	        |             y )Nr   r=   )ra   rb   r7   r?   rc   rd   s      r   test_itercount_stepz$MsgPackUtilsTest.test_itercount_steps   s4    __Q"2b49-r   c           	      f    | j                  t        ddg      t        t        ddg                   y Nr   r"   r?   r2   r7   r@   s    r   test_setzMsgPackUtilsTest.test_setx   s'    aVl31v;&?@r   c                 ^    | j                  t        g       t        t        g                    y r   rl   r@   s    r   test_empty_setzMsgPackUtilsTest.test_empty_set{   s    R,s2w"78r   c           	      f    | j                  t        ddg      t        t        ddg                   y rk   r?   	frozensetr7   r@   s    r   test_frozensetzMsgPackUtilsTest.test_frozenset~   s)    Aq6*LAq69J,KLr   c                 ^    | j                  t        g       t        t        g                    y r   rq   r@   s    r   test_empty_frozensetz%MsgPackUtilsTest.test_empty_frozenset   s    2Yr](CDr   c           	      p    t        j                   ddddddd      }| j                  |t        |             y )NrN   r"   r=   rO   rP   rQ   rR   )r[   r?   r7   r   xs     r   test_datetime_preservez'MsgPackUtilsTest.test_datetime_preserve   s2    dAq!Q15LO,r   c                     t        j                         }|j                  d       | j                  |t	        |             y )Nz19710203T04:05:06)	xmlrpclibDateTimedecoder?   r7   rw   s     r   test_datetimezMsgPackUtilsTest.test_datetime   s1     	$%LO,r   c                 h    dt        j                  d      i}| j                  |t        |             y )Nip_addrz1.2.3.4)netaddr	IPAddressr?   r7   )r   things     r   test_ipaddrzMsgPackUtilsTest.test_ipaddr   s,    G--i89U 34r   c                 v    t         j                  j                         }| j                  |t	        |             y r   )r[   r]   rZ   r?   r7   )r   rZ   s     r   
test_todayzMsgPackUtilsTest.test_today   s)    ##%U 34r   c                 ~   t         j                   j                         }t        r(t        j                  d      }|j	                  |      }nt        d      }|j                  |      }t        |      }| j                  ||       | j                  |j                  t              |j                  t                     y )NAmerica/New_Yorktzinfo)r[   rU   zoneinfoZoneInforeplacer   localizer7   r?   strftime_TZ_FMT)r   rU   easterne_dte_dt2s        r   test_datetime_tz_clonez'MsgPackUtilsTest.test_datetime_tz_clone   s    ##%''(:;G;;g;.D12G##C(DT"u%w/1HIr   c                    t         j                   j                         }t        rSt        j                  d      }t        j                  d      }|j	                  |      }|}|j	                  |      }|}n8t        d      }t        d      }|j                  |      }|j                  |      }| j                  ||       | j                  |j                  t              |j                  t                     t        |      }t        |      }| j                  ||       | j                  |j                  t              |j                  t                     | j                  ||       | j                  ||       y )Nr   zAmerica/Los_Angelesr   )r[   rU   r   r   r   r   r   assertNotEqualr   r   r7   r?   )r   rU   r   pacificr   p_dtr   p_dt2s           r   test_datetime_tz_differentz+MsgPackUtilsTest.test_datetime_tz_different   s3   ##%''(:;G''(=>G++W+-CD++W+-CD12G45G##C(D##C(DD$'DMM'2DMM'4JKT"T"E5)ENN73U^^G5LMu%u%r   c                 6   t         j                  }| j                  t        |j                  t               dd       |j                  d      }|j	                  t               dd       |j                  t                     }| j                  |t
               y NT)reservedoverrideunfreeze)
r   default_registryassertRaises
ValueErrorregisterr1   copymatchr2   assertIsInstance)r   registryhs      r   test_copy_then_registerz(MsgPackUtilsTest.test_copy_then_register   s    00*"++-@-B#'$ 	 	8 ==$=/-/#'$ 	 	8NN35!a!45r   c                 v   t         j                  }| j                  t        |j                  t               dd       | j                  t        |j                  t                      |j                  d      }|j	                  t                      | j                  t        |j                  t                      y r   )r   r   r   r   r   r1   r   r   )r   r   s     r   test_bad_registerz"MsgPackUtilsTest.test_bad_register   s    00*"++-@-B#'$ 	 	8 	*"++-@-B	D==$=/,.)*"++\^	=r   c                    t         j                  j                  d      }|j                  t	                      t        ddd      }t        j                  ||      }t        j                  ||      }| j                  d|j                         | j                  d|j                         | j                  d|j                         y )NTr            )r   )r   r   r   r   r   r	   r5   r6   r?   r   r   r   )r   r   r'   c_bs       r   test_custom_registerz%MsgPackUtilsTest.test_custom_register   s    0055t5D,.)#sC   X6sX6acc"acc"acc"r   c                 ^    | j                  t        t        j                  t	                      y r   )r   r   r   r5   objectr@   s    r   test_objectzMsgPackUtilsTest.test_object   s    *l&8&8&(Cr   N)r   r   r   rA   rC   rF   rJ   rL   r_   rg   ri   rm   ro   rs   ru   ry   r~   r   r   r   r   r   r   r   r   r   r   r   r9   r9   C   su    =/=</1	..
A9ME--
55
J&6	6=
#Dr   r9   )r[   ra   xmlrpcr   r{   r   oslotestr   	test_basepytzr   r   oslo_serializationr   
oslo_utilsr   r   r   r	   r   r1   r7   BaseTestCaser9   r   r   r   <module>r      sj      &  &  +   #F 66 6$0& 0
#
^Dy-- ^Dr   