a  zeA@sddlZddlmZddlmZddlZddlZddlZddlmZGdddZGdddej Z Gd d d ej ej Z Gd d d ej Zed kredS)N)abc)utilc@seZdZddZddZdS) CollectInitcOs||_||_dSN)argskwargs)selfrrr Q/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_importlib/test_lazy.py__init__ szCollectInit.__init__cCs|Srr r moduler r r exec_moduleszCollectInit.exec_moduleN)__name__ __module__ __qualname__r rr r r r r src@seZdZddZddZdS)LazyLoaderFactoryTestscCsDtjt}|dddd}|j}|d|j|ddi|jdS)N module name module pathkw)r)rr)r LazyLoaderfactoryrloader assertEqualrr)r rZ lazy_loaderrr r r test_inits  z LazyLoaderFactoryTests.test_initcCs:|ttjtWdn1s,0YdSr) assertRaises TypeErrorrrrobjectr r r r test_validation s z&LazyLoaderFactoryTests.test_validationN)rrrrr r r r r rs rc@s4eZdZdZdZdZdeZd ddZddZ dS) TestingImporterZlazy_loader_testchangedNzattr = 42; __name__ = {!r}cCs ||jkrdSt|t|Sr) module_namerspec_from_loaderr)r namepathtargetr r r find_spec-s zTestingImporter.find_speccCst|j|j||_dSr)exec source_code__dict__loadedr r r r r2szTestingImporter.exec_module)N) rrrr# mutated_namer,formatr*r(rr r r r r!&s   r!c@sfeZdZddZdddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ dS)LazyLoaderTestscCs8|tttWdn1s*0YdSr)rrrrrrr r r r9s zLazyLoaderTests.test_initNcCsrt}|dur||_ttjt|}|j|}|durHt tj}||_ |j|_ |j || |j|Sr)r!r*rr$r#rr create_moduletypes ModuleType__spec__ __loader__r assertIsNoner,)r r*rspecrr r r new_module>s    zLazyLoaderTests.new_modulec Cst}|jdusJt|jJtj|gdt|j}Wdn1sR0YWdn1sp0Y||j| |j || |j| ||jdS)N) meta_path) r!r, test_utiluncacher#Z import_state importlib import_moduler5rr4ZassertIsNotNone)r Zimporterrr r r test_e2eNsH  zLazyLoaderTests.test_e2ecCs|}|tj|jdSr)r7rr!r-rr r r r test_attr_unchanged[sz#LazyLoaderTests.test_attr_unchangedcCs |}d|_|d|jdS)N*)r7Znew_attrrr r r r test_new_attraszLazyLoaderTests.test_new_attrcCs |}d|_|d|jdS)NZbogus)r7rrr r r r test_mutated_preexisting_attrgsz-LazyLoaderTests.test_mutated_preexisting_attrcCs |}d|_|d|jdS)N)r7attrrr r r r test_mutated_attrnsz!LazyLoaderTests.test_mutated_attrcCs |}|`|t|ddS)NrC)r7rC assertFalsehasattrr r r r test_delete_eventual_attrusz)LazyLoaderTests.test_delete_eventual_attrcCs |}|`|t|ddS)Nr)r7rrErFr r r r test_delete_preexisting_attr{sz,LazyLoaderTests.test_delete_preexisting_attrc Csttjbttj}|tjtj<|}| t d|j Wdn1sV0YWdn1st0YdS)NZ substituted) r9r:r!r#r1r2sysmodulesr7ZassertRaisesRegex ValueErrorr)r Z fresh_modulerr r r test_module_substitution_errors   z.LazyLoaderTests.test_module_substitution_errorcCsJttj*|}|tjtj<|jWdn1s<0YdSr)r9r:r!r#r7rIrJrr r r r test_module_already_in_syss z*LazyLoaderTests.test_module_already_in_sys)N)rrrrr7r=r>r@rArDrGrHrLrMr r r r r/7s  r/__main__)r;rrrIr1Zunittestr9rZTestCaserMetaPathFinderLoaderr!r/rmainr r r r s    Y