B l9KZ6åÝLã@sHddlZddlmZGdd„dƒZGdd„dejƒZedkrDe ¡dS)éN)Úmockc@s$eZdZdd„Zdd„Zdd„ZdS)Ú SampleObjectcCsd|_d|_dS)Né)Ú attr_sample1Ú attr_sample2)Úself©rúH/opt/alt/python37/lib64/python3.7/unittest/test/testmock/testsealable.pyÚ__init__szSampleObject.__init__cCsdS)Nr)rrrr Úmethod_sample1 szSampleObject.method_sample1cCsdS)Nr)rrrr Úmethod_sample2 szSampleObject.method_sample2N)Ú__name__Ú __module__Ú __qualname__r r r rrrr rsrc@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%S)&Ú TestSealablecCsDt ¡}| |jtj¡| | ¡tj¡| | ¡ ¡tj¡dS)N)rÚMockZassertIsInstanceÚtestÚtest2)rÚmrrr Ú,test_attributes_return_more_mocks_by_defaultsz9TestSealable.test_attributes_return_more_mocks_by_defaultc CsNt ¡}t |¡| t¡ |jWdQRX| t¡ |ƒWdQRXdS)N)rrÚsealÚ assertRaisesÚAttributeErrorr)rrrrr Ú.test_new_attributes_cannot_be_accessed_on_seals    z;TestSealable.test_new_attributes_cannot_be_accessed_on_sealc Cs2t ¡}t |¡| t¡ d|_WdQRXdS)Nr)rrrrrr)rrrrr Ú)test_new_attributes_cannot_be_set_on_seal#s  z6TestSealable.test_new_attributes_cannot_be_set_on_sealcCs6t ¡}d|j_t |¡d|j_| |jjd¡dS)Nré)rrrrrÚ assertEqual)rrrrr Ú+test_existing_attributes_can_be_set_on_seal*s  z8TestSealable.test_existing_attributes_can_be_set_on_sealc Cs<t ¡}d|j_t |¡| t¡d|j_WdQRXdS)Nr)rrrrrrrÚtest3)rrrrr Ú2test_new_attributes_cannot_be_set_on_child_of_seal2s   z?TestSealable.test_new_attributes_cannot_be_set_on_child_of_sealcCs.t ¡}d|j_t |¡| | ¡d¡dS)Né)rrrÚ return_valuerr)rrrrr Ú+test_existing_attributes_allowed_after_seal:s z8TestSealable.test_existing_attributes_allowed_after_sealcCs(tjdd}t |¡| |jd¡dS)Nr)Ú test_value)rrrrr#)rrrrr Ú.test_initialized_attributes_allowed_after_sealBs  z;TestSealable.test_initialized_attributes_allowed_after_sealc Cs2t ¡}t |¡| t¡ |ƒWdQRXdS)N)rrrrr)rrrrr Útest_call_on_sealed_mock_failsHs  z+TestSealable.test_call_on_sealed_mock_failscCs(tjdd}t |¡| |ƒd¡dS)Né)r!)rrrr)rrrrr Ú)test_call_on_defined_sealed_mock_succeedsOs  z6TestSealable.test_call_on_defined_sealed_mock_succeedsc Csvt ¡}d|j ¡_t |¡| |j ¡jd¡| t¡|j ¡j WdQRX| t¡|jjWdQRXdS)Né) rrÚtest1rrrrrrÚtest4)rrrrr Ú&test_seals_recurse_on_added_attributesUs    z3TestSealable.test_seals_recurse_on_added_attributesc Cs²t ¡}d|jjd_d|jjdd…_t |¡| |jjdjd¡| |jjdd…jd¡| t¡|jjdj WdQRX| t¡|jjdd…j WdQRXdS)Nr(Úarr&) rZ MagicMockr)rrrrrrr*)rrrrr Ú#test_seals_recurse_on_magic_methodsas   z0TestSealable.test_seals_recurse_on_magic_methodscCsZtjdd}tjdd|j_d|jj_t |¡| |jjjd¡|jjjd|jj_dS)NZ root_mock)ÚnameZ not_sealedr(r)rrr)rrrrr*)rrrrr Ú,test_seals_dont_recurse_on_manual_attributesos    z9TestSealable.test_seals_dont_recurse_on_manual_attributesc Cs\t t¡}d|_d|_t |¡| |jd¡| |jd¡| t¡ |j WdQRXdS)z0You are not restricted when using mock with specrr N) rrrrZ attr_sample3rrrrr)rrrrr Ú)test_integration_with_spec_att_definitionzs   z6TestSealable.test_integration_with_spec_att_definitionc CsNt t¡}d|j_t |¡| | ¡d¡| t¡|  ¡WdQRXdS)z;You need to defin the methods, even if they are in the specrN) rrrr r!rrrrr )rrrrr Ú,test_integration_with_spec_method_definition‡s    z9TestSealable.test_integration_with_spec_method_definitionc Cs,t t¡}| t¡d|j_WdQRXdS)z)You cannot define methods out of the specr N)rrrrrZmethod_sample3r!)rrrrr Ú:test_integration_with_spec_method_definition_respects_spec’s  zGTestSealable.test_integration_with_spec_method_definition_respects_specc CsDt ¡}t |¡| t¡ }|jWdQRX| dt|jƒ¡dS)NÚ SECRETE_name) rrrrrr3ÚassertInÚstrÚ exception)rrÚcmrrr Ú(test_sealed_exception_has_attribute_name™s   z5TestSealable.test_sealed_exception_has_attribute_namec Cs\tjdd}|jjjjt |¡| t¡}|jjjjj WdQRX|  dt |j ƒ¡dS)NZ mock_name)r.z&mock_name.test1.test2.test3.test4.boom) rrr)rrr*rrrZboomr4r5r6)rrr7rrr Ú"test_attribute_chain_is_maintained¡s     z/TestSealable.test_attribute_chain_is_maintainedc Cs`t ¡}| ¡j ¡jt |¡| t¡}| ¡j ¡ ¡WdQRX|  dt |j ƒ¡dS)Nz mock.test1().test2.test3().test4) rrr)rrr*rrrr4r5r6)rrr7rrr Útest_call_chain_is_maintainedªs   z*TestSealable.test_call_chain_is_maintainedN)r rrrrrrrr"r$r%r'r+r-r/r0r1r2r8r9r:rrrr rs$      rÚ__main__)ZunittestrrZTestCaserr Úmainrrrr Ús   $