diff options
Diffstat (limited to 'pym/portage/tests/lint/test_compile_modules.py')
-rw-r--r-- | pym/portage/tests/lint/test_compile_modules.py | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/pym/portage/tests/lint/test_compile_modules.py b/pym/portage/tests/lint/test_compile_modules.py index f90a6665a..ce7e3fb90 100644 --- a/pym/portage/tests/lint/test_compile_modules.py +++ b/pym/portage/tests/lint/test_compile_modules.py @@ -1,6 +1,7 @@ -# Copyright 2009-2010 Gentoo Foundation +# Copyright 2009-2014 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 +import errno import itertools import stat @@ -10,12 +11,10 @@ from portage import os from portage import _encodings from portage import _unicode_decode, _unicode_encode -import py_compile - class CompileModulesTestCase(TestCase): def testCompileModules(self): - for parent, dirs, files in itertools.chain( + for parent, _dirs, files in itertools.chain( os.walk(PORTAGE_BIN_PATH), os.walk(PORTAGE_PYM_PATH)): parent = _unicode_decode(parent, @@ -33,14 +32,21 @@ class CompileModulesTestCase(TestCase): if x[-3:] == '.py': do_compile = True else: - # Check for python shebang - f = open(_unicode_encode(x, - encoding=_encodings['fs'], errors='strict'), 'rb') - line = _unicode_decode(f.readline(), - encoding=_encodings['content'], errors='replace') - f.close() - if line[:2] == '#!' and \ - 'python' in line: + # Check for python shebang. + try: + with open(_unicode_encode(x, + encoding=_encodings['fs'], errors='strict'), 'rb') as f: + line = _unicode_decode(f.readline(), + encoding=_encodings['content'], errors='replace') + except IOError as e: + # Some tests create files that are unreadable by the + # user (by design), so ignore EACCES issues. + if e.errno != errno.EACCES: + raise + continue + if line[:2] == '#!' and 'python' in line: do_compile = True if do_compile: - py_compile.compile(x, cfile='/dev/null', doraise=True) + with open(_unicode_encode(x, + encoding=_encodings['fs'], errors='strict'), 'rb') as f: + compile(f.read(), x, 'exec') |