a 4êdgã@sŽdZddlZddlZddlmZddlZddlZddlZe  ¡sJe  d¡‚eeee ƒƒƒZ ej  e d¡ZGdd„dejƒZedkrŠe ¡dS) z+Tests for the asdl parser in Parser/asdl.pyéN)Údirnamez'test irrelevant for an installed PythonZParserc@s\eZdZedd„ƒZedd„ƒZdd„Zdd„Zd d „Zd d „Z d d„Z dd„Z dd„Z dS)ÚTestAsdlParsercCsbtj dt¡tj dtj td¡¡}|  ¡|_ |j   tj td¡¡|_ |  |j  |j ¡d¡dS)NrÚasdlzasdl.pyz Python.asdlzModule validation failed)ÚsysÚpathÚinsertÚ parser_dirÚ importlibÚ machineryÚSourceFileLoaderÚosÚjoinÚ load_modulerÚparseÚmodÚ assertTrueÚcheck)ÚclsÚloader©rú1/usr/local/lib/python3.9/test/test_asdl_parser.pyÚ setUpClasssÿ zTestAsdlParser.setUpClasscCs tjd=dS)Nr)rr)rrrrÚ tearDownClass!szTestAsdlParser.tearDownClasscCstj|_tj|_|jj|_dS©N)rrrÚtypes©ÚselfrrrÚsetUp%szTestAsdlParser.setUpcCs>| |jjd¡| d|j¡| d|j¡| d|j¡dS)NÚPythonÚstmtÚexprr)Ú assertEqualrÚnameZassertInrrrrrÚ test_module+szTestAsdlParser.test_modulecCsb|jj}| |d|jj¡| |dj|jj¡| |jd|jj¡| |jd|jj¡dS)NrZwithitemÚalias) rÚdfnsÚassertIsInstancerÚTypeÚvalueZSumrZProduct)rZdefsrrrÚtest_definitions1s zTestAsdlParser.test_definitionscCs|jd}| t|ƒd¡dS)Nr$zGProduct([Field(identifier, name), Field(identifier, asname, opt=True)]))rr!Ústr)rr$rrrÚ test_product9s  þzTestAsdlParser.test_productcCsx|jd}| t|jƒd¡| t|jdƒd¡| t|jdƒd¡| t|jdƒd¡| t|jd ƒd ¡dS) NrérzField(int, lineno)ézField(int, col_offset)éz Field(int, end_lineno, opt=True)éz$Field(int, end_col_offset, opt=True))rr!ÚlenÚ attributesÚrepr)rrrrrÚtest_attributes?s  zTestAsdlParser.test_attributescCs|jd}| t|jƒd¡| t|jƒd¡|jd}| ||jj¡| t|jƒd¡|jd}| |jd¡| |j d¡|  |j ¡|jd}| |jd¡| |j d ¡|  |j ¡|jd }| |jd ¡| |j d ¡|  |j ¡|  |j ¡dS) NZ excepthandlerr-r,rr/r ÚtypeZ identifierr"r.rÚbody)rr!r0r1r&rZ ConstructorÚfieldsr4r"rÚoptZ assertFalseÚseq)rZehandlerÚconsZf0Úf1Úf2rrrÚtest_constructor_fieldsGs&        z&TestAsdlParser.test_constructor_fieldscCs@Gdd„d|jjƒ}|ƒ}| |jd¡| |jgd¢¡dS)Ncs<eZdZ‡fdd„Zdd„Zdd„Zdd„Zd d „Z‡ZS) z2TestAsdlParser.test_visitor..CustomVisitorcstƒ ¡g|_dSr)ÚsuperÚ__init__Únames_with_seqr©Ú __class__rrr>bs z;TestAsdlParser.test_visitor..CustomVisitor.__init__cSs|jD]}| |¡qdSr)r%Úvisit)rrZdfnrrrÚ visitModulefs z>TestAsdlParser.test_visitor..CustomVisitor.visitModulecSs| |j¡dSr)rBr()rr4rrrÚ visitTypejsz.CustomVisitor.visitTypecSs|jD]}| |¡qdSr)rrB)rÚsumÚtrrrÚvisitSumms z;TestAsdlParser.test_visitor..CustomVisitor.visitSumcSs$|jD]}|jr|j |j¡qdSr)r6r8r?Úappendr")rr9ÚfrrrÚvisitConstructorqs zCTestAsdlParser.test_visitor..CustomVisitor.visitConstructor) Ú__name__Ú __module__Ú __qualname__r>rCrDrGrJÚ __classcell__rrr@rÚ CustomVisitoras  rOr)ÚModulerPZ InteractiveÚ FunctionType)rZ VisitorBaserBrr!r?)rrOÚvrrrÚ test_visitor`s ÿzTestAsdlParser.test_visitorN) rKrLrMÚ classmethodrrrr#r)r+r3r<rSrrrrrs  rÚ__main__)Ú__doc__Zimportlib.machineryr r Zos.pathrrZ sysconfigZunittestZis_python_buildZSkipTestÚ__file__Zsrc_baserr rZTestCaserrKÚmainrrrrÚs  i