a ze@sdZddlZddlZddlmZddlZddlZddlZe sJe deeee Z ej e dZGdddejZedkredS) z+Tests for the asdl parser in Parser/asdl.pyN)dirnamez'test irrelevant for an installed PythonZParserc@s\eZdZeddZeddZddZddZd d Zd d Z d dZ ddZ ddZ dS)TestAsdlParsercCsbtjdttjdtjtd}| |_ |j tjtd|_ | |j |j ddS)Nrasdlzasdl.pyz Python.asdlzModule validation failed)syspathinsert parser_dir importlib machinerySourceFileLoaderosjoin load_modulerparsemod assertTruecheck)clsloaderrI/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_asdl_parser.py setUpClasss zTestAsdlParser.setUpClasscCs tjd=dS)Nr)rr)rrrr tearDownClass!szTestAsdlParser.tearDownClasscCstj|_tj|_|jj|_dSN)rrrtypesselfrrrsetUp%szTestAsdlParser.setUpcCs>||jjd|d|j|d|j|d|jdS)NPythonstmtexprr) assertEqualrnameZassertInrrrrr test_module+szTestAsdlParser.test_modulecCsb|jj}||d|jj||dj|jj||jd|jj||jd|jjdS)NrZwithitemalias) rdfnsassertIsInstancerTypevalueZSumrZProduct)rZdefsrrrtest_definitions1s zTestAsdlParser.test_definitionscCs|jd}|t|ddS)Nr$zGProduct([Field(identifier, name), Field(identifier, asname, opt=True)]))rr!str)rr$rrr test_product9s  zTestAsdlParser.test_productcCsx|jd}|t|jd|t|jdd|t|jdd|t|jdd|t|jd d dS) NrrzField(int, lineno)zField(int, col_offset)z Field(int, end_lineno, opt=True)z$Field(int, end_col_offset, opt=True))rr!len attributesrepr)rrrrrtest_attributes?s  zTestAsdlParser.test_attributescCs|jd}|t|jd|t|jd|jd}|||jj|t|jd|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.rbody)rr!r0r1r&rZ Constructorfieldsr4r"roptZ assertFalseseq)rZehandlerconsZf0f1f2rrrtest_constructor_fieldsGs&        z&TestAsdlParser.test_constructor_fieldscCs@Gddd|jj}|}||jd||jgddS)Ncs<eZdZfddZddZddZddZd d ZZS) z2TestAsdlParser.test_visitor..CustomVisitorcstg|_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||jdSr)rBr()rr4rrr visitTypejsz.CustomVisitor.visitTypecSs|jD]}||qdSr)rrB)rsumtrrrvisitSumms z;TestAsdlParser.test_visitor..CustomVisitor.visitSumcSs$|jD]}|jr|j|jqdSr)r6r8r?appendr")rr9frrrvisitConstructorqs zCTestAsdlParser.test_visitor..CustomVisitor.visitConstructor) __name__ __module__ __qualname__r>rCrDrGrJ __classcell__rrr@r CustomVisitoras  rOr)ModulerPZ Interactive FunctionType)rZ VisitorBaserBrr!r?)rrOvrrr 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 rZTestCaserrKmainrrrrs  i