a ze<@sddlZddlmZddlZddlZddlZddlZedZej ej e dddddZ ej ej e dddd Zd ZGd d d ejZed kredS)N)supportz symbol.pyz..ZToolsZscriptszgenerate_symbol_py.pyZIncludez graminit.hzsymbol_test.pyc@s<eZdZddZddZddZee ddd Z d S) TestSymbolGenerationcCst|}|}Wdn1s&0Yt|dD}||d|dd|||ddWdn1s0YdS)Nwz#--start constants-- z#--end constants-- )open readlines writelinesindex)selfZ source_fileZ dest_filefplinesr D/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_symbol.py$_copy_file_without_generated_symbolss  & z9TestSymbolGeneration._copy_file_without_generated_symbolscCs0tjtjt||gtjd}|d}|j|fS)N)stderrr) subprocessPopensys executableGEN_SYMBOL_FILEPIPE communicate returncode)r Z grammar_fileZtarget_symbol_py_fileprocrr r r_generate_symbolss z&TestSymbolGeneration._generate_symbolscCspt|}|}Wdn1s&0Yt|}|}Wdn1sV0Y|||dS)N)rr assertEqual)r Zfile1Zfile2r Zlines1Zlines2r r r compare_files#s  & &z"TestSymbolGeneration.compare_filesz+test only works from source build directorycCsXtj}|tj||t||t|\}}|d||d|| t|dS)Nr) rZTESTFNZ addCleanupunlinkr SYMBOL_FILEr GRAMMAR_FILErr)r outputexitcoderr r r!test_real_grammar_and_symbol_file*s   z6TestSymbolGeneration.test_real_grammar_and_symbol_fileN) __name__ __module__ __qualname__rrrunittestZ skipUnless sysconfigZis_python_buildr#r r r rrs r__main__)r'testrosrr(rZfindfilerpathjoindirname__file__rr Z TEST_PY_FILEZTestCaserr$mainr r r rs"  '