add python syntax checker
This commit is contained in:
@@ -1267,6 +1267,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR MINGW)
|
||||
)
|
||||
endif(CMAKE_COMPILER_IS_GNUCXX OR MINGW)
|
||||
|
||||
|
||||
# Print message to start build process
|
||||
if (${CMAKE_BUILD_TOOL} MATCHES "make")
|
||||
MESSAGE("=======================================\n"
|
||||
|
||||
@@ -13,6 +13,7 @@ SET(Test_SRCS
|
||||
unittestgui.py
|
||||
InitGui.py
|
||||
testmakeWireString.py
|
||||
TestPythonSyntax.py
|
||||
)
|
||||
SOURCE_GROUP("" FILES ${Test_SRCS})
|
||||
|
||||
|
||||
@@ -73,7 +73,8 @@ def All():
|
||||
"TestPartDesignApp",
|
||||
"TestSpreadsheet",
|
||||
"TestTechDrawApp",
|
||||
"TestPathApp" ]
|
||||
"TestPathApp",
|
||||
"TestPythonSyntax"]
|
||||
|
||||
# gui tests of modules
|
||||
if (FreeCAD.GuiUp == 1):
|
||||
|
||||
41
src/Mod/Test/TestPythonSyntax.py
Normal file
41
src/Mod/Test/TestPythonSyntax.py
Normal file
@@ -0,0 +1,41 @@
|
||||
import sys
|
||||
import os
|
||||
import ast
|
||||
import unittest
|
||||
import FreeCAD as App
|
||||
|
||||
def test_python_syntax(rootdir, whitelist=None):
|
||||
whitelist = whitelist or []
|
||||
log = []
|
||||
for sub_dir, dirs, files in os.walk(rootdir):
|
||||
for fn in files:
|
||||
if (not fn in whitelist) and os.path.splitext(fn)[1] == '.py':
|
||||
with open(os.path.join(sub_dir, fn), encoding='utf-8') as py_file:
|
||||
try:
|
||||
ast.parse(py_file.read())
|
||||
except SyntaxError:
|
||||
log.append(os.path.join(sub_dir, fn))
|
||||
message = "\n\n" + "#" * 30 + "\n"
|
||||
message += "{} python files are not parseable:\n\n".format(len(log))
|
||||
for i in log:
|
||||
message += i + "\n"
|
||||
message += "#" * 30 + "\n\n"
|
||||
if log:
|
||||
raise RuntimeError("there are some files not parse-able with the used python-interpreter" + message)
|
||||
else:
|
||||
return
|
||||
|
||||
|
||||
class PythonSyntaxTestCase(unittest.TestCase):
|
||||
"""
|
||||
Test Case to test python syntax of all python files in FreeCAD
|
||||
"""
|
||||
def setUp(self):
|
||||
self.whitelist = []
|
||||
self.whitelist += ["automotive_design.py"]
|
||||
self.whitelist += ["ifc2x3.py"]
|
||||
self.whitelist += ["ifc4.py"]
|
||||
|
||||
|
||||
def testAll(self):
|
||||
test_python_syntax(App.getHomePath(), self.whitelist)
|
||||
Reference in New Issue
Block a user