a XC?hÉã@sHddlZddlmZGdd„dƒZGdd„dejƒZedkrDe ¡dS)éN)Úmockc@seZdZdd„Zdd„ZdS)Ú SampleObjectcCsdS©N©©ÚselfrrúH/opt/alt/python39/lib64/python3.9/unittest/test/testmock/testsealable.pyÚmethod_sample1ózSampleObject.method_sample1cCsdSrrrrrrÚmethod_sample2 r zSampleObject.method_sample2N)Ú__name__Ú __module__Ú __qualname__r r rrrrrsrc@s¤eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zd'S)(Ú TestSealablecCsDt ¡}| |jtj¡| | ¡tj¡| | ¡ ¡tj¡dSr)rÚMockÚassertIsInstanceÚtestÚtest2©rÚmrrrÚ,test_attributes_return_more_mocks_by_defaultsz9TestSealable.test_attributes_return_more_mocks_by_defaultcCsvt ¡}t |¡| t¡|jWdƒn1s80Y| t¡|ƒWdƒn1sh0YdSr©rrÚsealÚ assertRaisesÚAttributeErrorrrrrrÚ.test_new_attributes_cannot_be_accessed_on_seals   $ z;TestSealable.test_new_attributes_cannot_be_accessed_on_sealcCsFt ¡}t |¡| t¡d|_Wdƒn1s80YdS©NérrrrrÚ)test_new_attributes_cannot_be_set_on_seals  z6TestSealable.test_new_attributes_cannot_be_set_on_sealcCs6t ¡}d|j_t |¡d|j_| |jjd¡dS)Nré)rrrrrÚ assertEqualrrrrÚ+test_existing_attributes_can_be_set_on_seal%s  z8TestSealable.test_existing_attributes_can_be_set_on_sealcCsPt ¡}d|j_t |¡| t¡d|j_Wdƒn1sB0YdSr)rrrrrrrÚtest3rrrrÚ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 |¡| | ¡d¡dS)Né)rrrÚ return_valuerr rrrrÚ+test_existing_attributes_allowed_after_seal5s z8TestSealable.test_existing_attributes_allowed_after_sealcCs(tjdd}t |¡| |jd¡dS)Nr)Ú test_value)rrrr r'rrrrÚ.test_initialized_attributes_allowed_after_seal=s  z;TestSealable.test_initialized_attributes_allowed_after_sealcCsFt ¡}t |¡| t¡|ƒWdƒn1s80YdSr)rrrrrrrrrÚtest_call_on_sealed_mock_failsCs  z+TestSealable.test_call_on_sealed_mock_failscCs(tjdd}t |¡| |ƒd¡dS)Né)r%)rrrr rrrrÚ)test_call_on_defined_sealed_mock_succeedsJs  z6TestSealable.test_call_on_defined_sealed_mock_succeedscCsžt ¡}d|j ¡_t |¡| |j ¡jd¡| t¡|j ¡j Wdƒn1s^0Y| t¡|jjWdƒn1s0YdS©Né) rrÚtest1rr"rr rrÚtest4rrrrÚ&test_seals_recurse_on_added_attributesPs   * z3TestSealable.test_seals_recurse_on_added_attributescCsÚt ¡}d|jjd_d|jjdd…_t |¡| |jjdjd¡| |jjdd…jd¡| t¡|jjdj Wdƒn1s0Y| t¡"|jjdd…j Wdƒn1sÌ0YdS)Nr-Úarr*) rÚ MagicMockr.rr"rr rrr/rrrrÚ#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_mock©ÚnameZ not_sealedr-r)rrr.rr"rr r/rrrrÚ,test_seals_dont_recurse_on_manual_attributesjs    z9TestSealable.test_seals_dont_recurse_on_manual_attributescCspt t¡}d|_d|_t |¡| |jd¡| |jd¡| t¡|j Wdƒn1sb0YdS)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_definitioncCsbt t¡}d|j_t |¡| | ¡d¡| t¡|  ¡Wdƒn1sT0YdS)zrrrÚ"test_attribute_chain_is_maintainedœs     ,z/TestSealable.test_attribute_chain_is_maintainedcCstt ¡}| ¡j ¡jt |¡| t¡"}| ¡j ¡ ¡Wdƒn1sT0Y|  dt |j ƒ¡dS)Nz mock.test1().test2.test3().test4) rrr.rr"r/rrrr;r<r=r>rrrÚtest_call_chain_is_maintained¥s   0z*TestSealable.test_call_chain_is_maintainedc CsPGdd„dƒ}dD]6}|j|dtj||d}d|j_d|jj_t |¡| |j tj ¡| |jtj ¡| |j tj ¡| |jtj ¡| |jj tj ¡| |jjtj ¡| | ¡d¡d|j_| | ¡d¡| |j ¡d¡d|jj_| |j ¡d¡| t¡|  ¡Wdƒn1s60Y| t¡d |_Wdƒn1sh0Y| t¡|  ¡Wdƒn1sœ0Yd |j _| |  ¡d ¡| t¡|jWdƒn1sæ0Y| t¡d |_Wdƒn1s0Y| t¡| ¡Wdƒn1sL0Y| t¡|j  ¡Wdƒn1s‚0Y| t¡|jjWdƒn1s¶0Y| t¡d |j_Wdƒn1sê0Y| t¡|j ¡Wdƒn1s 0YWdƒq1s@0YqdS) Nc@s.eZdZdZdd„Zdd„ZGdd„dƒZdS) z1TestSealable.test_seal_with_autospec..FoorcSsdSrrrrrrÚbar1²sz6TestSealable.test_seal_with_autospec..Foo.bar1cSsdS)NrrrrrrÚbar2´sz6TestSealable.test_seal_with_autospec..Foo.bar2c@seZdZdZdd„ZdS)z5TestSealable.test_seal_with_autospec..Foo.Bazr$cSsdSr,rrrrrÚban¹sz9TestSealable.test_seal_with_autospec..Foo.Baz.banN)r r rÚbazrErrrrÚBaz·srGN)r r rÚfoorCrDrGrrrrÚFoo°srI)TF)Úspec_setr1ÚbZnew_aZnew_brrD)ZsubTestrZcreate_autospecrCr%rGrErrrHZNonCallableMagicMockr2rDrFr rÚ TypeErrorrZbarZ missing_attrZmissing_method)rrIrJrHrrrÚtest_seal_with_autospec®sR     ( & ( & & ( * ( ( z$TestSealable.test_seal_with_autospecN)r r rrrrr!r#r&r(r)r+r0r3r6r7r8r9r@rArBrMrrrrr s&       rÚ__main__)ZunittestrrZTestCaserr ÚmainrrrrÚs  a