3 L(Y@sFddlZddlmZddlmZGdddejZedkrBejdS)N)Mock)Watchc@s,eZdZddZddZddZddZd S) WatchTestscCst}t|_t|_tddddgd|_t}t|d|_d|j_t}d}xT|j|jD]D}|jd|d |jd ||d j j |d7}|d kr\|j q\W|jj d dd|jj d d|jj |jj dS)NzV{"type": "ADDED", "object": {"metadata": {"name": "test1"},"spec": {}, "status": {}}} zK{"type": "ADDED", "object": {"metadata": {"name": "test2"},"spec": {}, "stazatus": {}}} {"type": "ADDED", "object": {"metadata": {"name": "test3"},"spec": {}, "status": {}}} zshould_not_happened ) return_valuez:return: V1NamespaceListrADDEDtypeztest%dobjectFT)_preload_contentwatch)decode_content)rclose release_conn read_chunkedZget_namespaces__doc__rstream assertEqualmetadatanamestopassert_called_once_withassert_called_once)self fake_respfake_apiwcounterI/private/tmp/pip-build-nl73fm5q/kubernetes/kubernetes/watch/watch_test.pytest_watch_with_decodes0     z!WatchTests.test_watch_with_decodecCsZt}|jdd}|jd|d|jd|d|jt|dt|jd|ddS) Nz{"type": "ADDED", "object": 1}floatrrg?r r raw_object)runmarshal_eventrZ assertTrue isinstancer")rreventrrr test_unmarshal_with_float_object=s  z+WatchTests.test_unmarshal_with_float_objectcCsJt}|jdd}|jd|d|jdg|d|jdg|ddS)Nz&{"type": "ADDED", "object": ["test1"]}rrZtest1r r#)rr$r)rrr&rrr "test_unmarshal_with_no_return_typeEs z-WatchTests.test_unmarshal_with_no_return_typec Cst}t|_t|_ttdd|_t}t|d|_t}y&x |j|jD]}|j|dqNWWntk rxYnX|jj ddd|jj dd|jj |jj dS) Nexpected)Z side_effect)rzShould fail on exception.FT)r r )r ) rrrKeyErrorrZ get_thingrrZfailrr)rrrr_rrr test_watch_with_exceptionMs"   z$WatchTests.test_watch_with_exceptionN)__name__ __module__ __qualname__r!r'r(r,rrrr rs%r__main__) ZunittestZmockrr rZTestCaserr-mainrrrr s   O