aboutsummaryrefslogtreecommitdiff
blob: 7a990ca874f630c125d6d78277747f0da488ccd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import unittest
import py_compile

import os
osp = os.path

"""Does a basic syntax check by compiling all modules. From Portage."""

pym_dirs = os.walk(osp.dirname(osp.dirname(osp.dirname(__file__))))
blacklist_dirs = frozenset(('.svn', 'test'))

class TestForSyntaxErrors(unittest.TestCase):

	def test_compileability(self):
		compileables = []
		for thisdir, subdirs, files in pym_dirs:
			if os.path.basename(thisdir) in blacklist_dirs:
				continue
			compileables.extend([
				osp.join(thisdir, f)
				for f in files
				if osp.splitext(f)[1] == '.py'
			])

		for c in compileables:
			py_compile.compile(c, doraise=True)


def test_main():
	suite = unittest.TestLoader().loadTestsFromTestCase(
		TestForSyntaxErrors)
	unittest.TextTestRunner(verbosity=2).run(suite)
test_main.__test__ = False


if __name__ == '__main__':
	test_main()