2 # Unit tests for checking syntax of Python source code
4 # Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>
6 # This program and the accompanying materials
7 # are licensed and made available under the terms and conditions of the BSD License
8 # which accompanies this distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
24 class Tests(TestTools
.BaseToolsTest
):
27 TestTools
.BaseToolsTest
.setUp(self
)
29 def SingleFileTest(self
, filename
):
31 py_compile
.compile(filename
, doraise
=True)
33 self
.fail('syntax error: %s, Error is %s' % (filename
, str(e
)))
35 def MakePythonSyntaxCheckTests():
36 def GetAllPythonSourceFiles():
37 pythonSourceFiles
= []
38 for (root
, dirs
, files
) in os
.walk(TestTools
.PythonSourceDir
):
39 for filename
in files
:
40 if filename
.lower().endswith('.py'):
41 pythonSourceFiles
.append(
42 os
.path
.join(root
, filename
)
44 return pythonSourceFiles
46 def MakeTestName(filename
):
47 assert filename
.lower().endswith('.py')
49 name
= name
.replace(TestTools
.PythonSourceDir
, '')
50 name
= name
.replace(os
.path
.sep
, '_')
53 def MakeNewTest(filename
):
54 test
= MakeTestName(filename
)
55 newmethod
= lambda self
: self
.SingleFileTest(filename
)
62 for filename
in GetAllPythonSourceFiles():
65 MakePythonSyntaxCheckTests()
66 del MakePythonSyntaxCheckTests
68 TheTestSuite
= TestTools
.MakeTheTestSuite(locals())
70 if __name__
== '__main__':
71 allTests
= TheTestSuite()
72 unittest
.TextTestRunner().run(allTests
)