o =?h@sLddlZddlmZGdddZGdddejZedkr$edSdS)N)mockc@seZdZddZddZdS) SampleObjectcCdSNselfrrJ/opt/alt/python310/lib64/python3.10/unittest/test/testmock/testsealable.pymethod_sample1zSampleObject.method_sample1cCrrrrrrr method_sample2 r zSampleObject.method_sample2N)__name__ __module__ __qualname__r r rrrr rs rc@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'S)( TestSealablecCsDt}||jtj||tj||tjdSr)rMockassertIsInstancetesttest2rmrrr ,test_attributes_return_more_mocks_by_defaultsz9TestSealable.test_attributes_return_more_mocks_by_defaultcCsxt}t||t |jWdn1swY|t |WddS1s5wYdSrrrseal assertRaisesAttributeErrorrrrrr .test_new_attributes_cannot_be_accessed_on_seals   "z;TestSealable.test_new_attributes_cannot_be_accessed_on_sealcCsHt}t||t d|_WddS1swYdSNrrrrr )test_new_attributes_cannot_be_set_on_seal   "z6TestSealable.test_new_attributes_cannot_be_set_on_sealcCs6t}d|j_t|d|j_||jjddS)Nr)rrrrr assertEqualrrrr +test_existing_attributes_can_be_set_on_seal%s  z8TestSealable.test_existing_attributes_can_be_set_on_sealcCsRt}d|j_t||t d|j_WddS1s"wYdSr)rrrrrrrtest3rrrr 2test_new_attributes_cannot_be_set_on_child_of_seal-s    "z?TestSealable.test_new_attributes_cannot_be_set_on_child_of_sealcCs.t}d|j_t|||ddS)N)rrr return_valuerr"rrrr +test_existing_attributes_allowed_after_seal5s z8TestSealable.test_existing_attributes_allowed_after_sealcCs(tjdd}t|||jddS)Nr) test_value)rrrr"r)rrrr .test_initialized_attributes_allowed_after_seal=  z;TestSealable.test_initialized_attributes_allowed_after_sealcCsHt}t||t |WddS1swYdSr)rrrrrrrrr test_call_on_sealed_mock_failsCr z+TestSealable.test_call_on_sealed_mock_failscCs(tjdd}t|||ddS)N)r')rrrr"rrrr )test_call_on_defined_sealed_mock_succeedsJr+z6TestSealable.test_call_on_defined_sealed_mock_succeedscCst}d|j_t|||jjd|t|jj Wdn1s/wY|t |jjWddS1sIwYdSN) rrtest1rr$rr"rrtest4rrrr &test_seals_recurse_on_added_attributesPs     "z3TestSealable.test_seals_recurse_on_added_attributescCst}d|jjd_d|jjdd_t|||jjdjd||jjddjd|t|jjdj Wdn1sHwY|t|jjddj WddS1sgwYdS)Nr0ar!r-) r MagicMockr1rr$rr"rrr2rrrr #test_seals_recurse_on_magic_methods\s   "z0TestSealable.test_seals_recurse_on_magic_methodscCsZtjdd}tjdd|j_d|jj_t|||jjjd|jjjd|jj_dS)NZ root_mocknameZ not_sealedr0r)rrr1rr$rr"r2rrrr ,test_seals_dont_recurse_on_manual_attributesjs    z9TestSealable.test_seals_dont_recurse_on_manual_attributescCsrtt}d|_d|_t|||jd||jd|t |j WddS1s2wYdS)z0You are not restricted when using mock with specrr&N) rrrZ attr_sample1Z attr_sample3rr"rrZ attr_sample2rrrr )test_integration_with_spec_att_definitionus   "z6TestSealable.test_integration_with_spec_att_definitioncCsdtt}d|j_t|||d|t | WddS1s+wYdS)zr?r@rArrr "test_attribute_chain_is_maintaineds    z/TestSealable.test_attribute_chain_is_maintainedcCstt}|jjt||t}|jWdn1s*wY| dt |j dS)Nz mock.test1().test2.test3().test4) rrr1rr$r2rrrr>r?r@rArrr test_call_chain_is_maintaineds  z*TestSealable.test_call_chain_is_maintainedc CsHGddd}dD]}|j|dtj||d}d|j_d|jj_t|||j tj ||jtj ||j tj ||jtj ||jj tj ||jjtj ||dd|j_||d||jdd|jj_||jd|t | Wdn1swY|t d |_Wdn1swY|t | Wdn1swYd |j _|| d |t |jWdn1swY|t d |_Wdn 1swY|t |Wdn 1s"wY|t |j Wdn 1s=wY|t |jjWdn 1sWwY|t d |j_Wdn 1sqwY|t |jWdn 1swYWdn 1swYq dS) Nc@s.eZdZdZddZddZGdddZdS) z1TestSealable.test_seal_with_autospec..FoorcSdSrrrrrr bar1z6TestSealable.test_seal_with_autospec..Foo.bar1cSrF)Nr!rrrrr bar2rHz6TestSealable.test_seal_with_autospec..Foo.bar2c@seZdZdZddZdS)z5TestSealable.test_seal_with_autospec..Foo.Bazr&cSrFr/rrrrr banrHz9TestSealable.test_seal_with_autospec..Foo.Baz.banN)r rrbazrJrrrr Bazs rLN)r rrfoorGrIrLrrrr Foos rN)TF)spec_setr4bZnew_aZnew_brrI)ZsubTestrZcreate_autospecrGr'rLrJrrrMZNonCallableMagicMockr5rIrKr"r TypeErrorrZbarZ missing_attrZmissing_method)rrNrOrMrrr test_seal_with_autospecsn                     z$TestSealable.test_seal_with_autospecN)r rrrrrr#r%r(r*r,r.r3r6r9r:r;r<rCrDrErRrrrr r s(      r__main__)ZunittestrrZTestCaserr mainrrrr s a