This is a test suite project that is for scraping most common pypi packages and run syntax based analysis over them.
- First go to
test.pyand fill atest_package_impl. - Then download pypi packages by
python download.py [directory to download] - and finally run your
test_package_implbypython test.py [directory where downloads are]
You can specify worker process/thread count by --workers
Example implementation of test_packages_impl
deftest_package_impl(file: Path) ->List[Any]:
reports= []
try:
withtokenize.open(file) asf:
source=f.read()
source=ast.parse(source)
exceptSyntaxError:
returnreportsfornodeinast.walk(source):
ifisinstance(node, ast.Compare) andisinstance(node.left, ast.Constant):
forcomparatorinnode.comparators:
ifisinstance(comparator, (ast.Tuple, ast.List, ast.Set)) andall(isinstance(elt, ast.Constant) foreltincomparator.elts):
breakelse:
continuereports.append({"lineno": node.lineno, "source": ast.unparse(node)})
returnreportsAnd run
$ python test.py packages --workers 8
==================================================
Package: pytest
Report(filename=PosixPath('packages/pytest-5.3.5/packages/pytest-5.3.5/doc/en/example/assertion/failure_demo.py'), report={'lineno': 81, 'source': '1 in [0, 2, 3, 4, 5]'})