a  ze@sHddlZddlmZGdddZGdddejZedkrDedS)N)mockc@seZdZddZddZdS) SampleObjectcCsdSNselfrrW/opt/bitninja-python-dojo/embedded/lib/python3.9/unittest/test/testmock/testsealable.pymethod_sample1zSampleObject.method_sample1cCsdSrrrrrrmethod_sample2 r zSampleObject.method_sample2N)__name__ __module__ __qualname__r r rrrrrsrc@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_defaultcCsvt}t||t|jWdn1s80Y|t|Wdn1sh0YdSrrrseal assertRaisesAttributeErrorrrrrr.test_new_attributes_cannot_be_accessed_on_seals   $ z;TestSealable.test_new_attributes_cannot_be_accessed_on_sealcCsFt}t||td|_Wdn1s80YdSNrrrrr)test_new_attributes_cannot_be_set_on_seals  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_sealcCsPt}d|j_t||td|j_Wdn1sB0YdSr)rrrrrrrtest3rrrr2test_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|||ddSN)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=s  z;TestSealable.test_initialized_attributes_allowed_after_sealcCsFt}t||t|Wdn1s80YdSr)rrrrrrrrrtest_call_on_sealed_mock_failsCs  z+TestSealable.test_call_on_sealed_mock_failscCs(tjdd}t|||ddS)N)r&)rrrr rrrr)test_call_on_defined_sealed_mock_succeedsJs  z6TestSealable.test_call_on_defined_sealed_mock_succeedscCst}d|j_t|||jjd|t|jj Wdn1s^0Y|t|jjWdn1s0YdSN) 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 Wdn1s0Y|t"|jjddj Wdn1s0YdS)Nr.arr+) r MagicMockr/rr"rr rrr0rrrr#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_sealedr.r)rrr/rr"rr r0rrrr,test_seals_dont_recurse_on_manual_attributesjs    z9TestSealable.test_seals_dont_recurse_on_manual_attributescCsptt}d|_d|_t|||jd||jd|t|j Wdn1sb0YdS)Nrr%) rrrZ attr_sample1Z attr_sample3rr rrZ attr_sample2rrrr)test_integration_with_spec_att_definitionus   z6TestSealable.test_integration_with_spec_att_definitioncCsbtt}d|j_t|||d|t| Wdn1sT0YdSr) rrrr r&rr rrr rrrr,test_integration_with_spec_method_definitions    z9TestSealable.test_integration_with_spec_method_definitioncCs@tt}|td|j_Wdn1s20YdSr$)rrrrrZmethod_sample3r&rrrr:test_integration_with_spec_method_definition_respects_specs  zGTestSealable.test_integration_with_spec_method_definition_respects_speccCsXt}t||t}|jWdn1s80Y|dt|jdS)N SECRETE_name) rrrrrr;assertInstr exceptionrrcmrrr(test_sealed_exception_has_attribute_names   $z5TestSealable.test_sealed_exception_has_attribute_namecCsptjdd}|jjjjt||t}|jjjjj Wdn1sP0Y| dt |j dS)NZ mock_namer5z&mock_name.test1.test2.test3.test4.boom) rrr/rr"r0rrrZboomr<r=r>r?rrr"test_attribute_chain_is_maintaineds     ,z/TestSealable.test_attribute_chain_is_maintainedcCstt}|jjt||t"}|jWdn1sT0Y| dt |j dS)Nz mock.test1().test2.test3().test4) rrr/rr"r0rrrr<r=r>r?rrrtest_call_chain_is_maintaineds   0z*TestSealable.test_call_chain_is_maintainedc CsPGddd}dD]6}|j|dtj||d}d|j_d|jj_t|||j tj ||jtj ||j tj ||jtj ||jj tj ||jjtj ||dd|j_||d||jdd|jj_||jd|t| Wdn1s60Y|td |_Wdn1sh0Y|t| Wdn1s0Yd |j _|| d |t|jWdn1s0Y|td |_Wdn1s0Y|t|Wdn1sL0Y|t|j Wdn1s0Y|t|jjWdn1s0Y|td |j_Wdn1s0Y|t|jWdn1s 0YWdq1s@0YqdS) Nc@s.eZdZdZddZddZGdddZdS) z1TestSealable.test_seal_with_autospec..FoorcSsdSrrrrrrbar1sz6TestSealable.test_seal_with_autospec..Foo.bar1cSsdS)Nrrrrrrbar2sz6TestSealable.test_seal_with_autospec..Foo.bar2c@seZdZdZddZdS)z5TestSealable.test_seal_with_autospec..Foo.Bazr%cSsdSr-rrrrrbansz9TestSealable.test_seal_with_autospec..Foo.Baz.banN)r r rbazrFrrrrBazsrHN)r r rfoorDrErHrrrrFoosrJ)TF)spec_setr2bZnew_aZnew_brrE)ZsubTestrZcreate_autospecrDr&rHrFrrrIZNonCallableMagicMockr3rErGr r TypeErrorrZbarZ missing_attrZmissing_method)rrJrKrIrrrtest_seal_with_autospecsR     ( & ( & & ( * ( ( z$TestSealable.test_seal_with_autospecN)r r rrrrr!r#r'r)r*r,r1r4r7r8r9r:rArBrCrNrrrrr s&       r__main__)ZunittestrrZTestCaserr mainrrrrs  a