aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2018-07-17 21:50:45 +0200
committerZac Medico <zmedico@gentoo.org>2018-07-18 16:19:11 -0700
commitbc0fa8d3795ed7e40aaa00f579bb2977897bce25 (patch)
tree2a62c721ee8dec47ddb564254e1cbd967577d1f0 /lib/portage/tests/lint
parentEventLoop: raise TypeError for unexpected call_* keyword args (diff)
downloadportage-bc0fa8d3795ed7e40aaa00f579bb2977897bce25.tar.gz
portage-bc0fa8d3795ed7e40aaa00f579bb2977897bce25.tar.bz2
portage-bc0fa8d3795ed7e40aaa00f579bb2977897bce25.zip
Rename pym→lib, for better distutils-r1 interoperability
Closes: https://github.com/gentoo/portage/pull/343
Diffstat (limited to 'lib/portage/tests/lint')
-rw-r--r--lib/portage/tests/lint/__init__.py0
-rw-r--r--lib/portage/tests/lint/__test__.py0
-rw-r--r--lib/portage/tests/lint/metadata.py11
-rw-r--r--lib/portage/tests/lint/test_bash_syntax.py54
-rw-r--r--lib/portage/tests/lint/test_compile_modules.py67
-rw-r--r--lib/portage/tests/lint/test_import_modules.py44
6 files changed, 176 insertions, 0 deletions
diff --git a/lib/portage/tests/lint/__init__.py b/lib/portage/tests/lint/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/lib/portage/tests/lint/__init__.py
diff --git a/lib/portage/tests/lint/__test__.py b/lib/portage/tests/lint/__test__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/lib/portage/tests/lint/__test__.py
diff --git a/lib/portage/tests/lint/metadata.py b/lib/portage/tests/lint/metadata.py
new file mode 100644
index 000000000..e3f90cbf2
--- /dev/null
+++ b/lib/portage/tests/lint/metadata.py
@@ -0,0 +1,11 @@
+# Copyright 2015 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+module_metadata = {
+}
+
+script_metadata = {
+ 'socks5-server.py': {
+ 'required_python': '3.3',
+ },
+}
diff --git a/lib/portage/tests/lint/test_bash_syntax.py b/lib/portage/tests/lint/test_bash_syntax.py
new file mode 100644
index 000000000..fdbb6fe88
--- /dev/null
+++ b/lib/portage/tests/lint/test_bash_syntax.py
@@ -0,0 +1,54 @@
+# Copyright 2010-2013 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+from itertools import chain
+import stat
+import subprocess
+import sys
+
+from portage.const import BASH_BINARY, PORTAGE_BASE_PATH, PORTAGE_BIN_PATH
+from portage.tests import TestCase
+from portage import os
+from portage import _encodings
+from portage import _unicode_decode, _unicode_encode
+
+class BashSyntaxTestCase(TestCase):
+
+ def testBashSyntax(self):
+ locations = [PORTAGE_BIN_PATH]
+ misc_dir = os.path.join(PORTAGE_BASE_PATH, "misc")
+ if os.path.isdir(misc_dir):
+ locations.append(misc_dir)
+ for parent, dirs, files in \
+ chain.from_iterable(os.walk(x) for x in locations):
+ parent = _unicode_decode(parent,
+ encoding=_encodings['fs'], errors='strict')
+ for x in files:
+ x = _unicode_decode(x,
+ encoding=_encodings['fs'], errors='strict')
+ ext = x.split('.')[-1]
+ if ext in ('.py', '.pyc', '.pyo'):
+ continue
+ x = os.path.join(parent, x)
+ st = os.lstat(x)
+ if not stat.S_ISREG(st.st_mode):
+ continue
+
+ # Check for bash 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 \
+ 'bash' in line:
+ cmd = [BASH_BINARY, "-n", x]
+ cmd = [_unicode_encode(x,
+ encoding=_encodings['fs'], errors='strict') for x in cmd]
+ proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT)
+ output = _unicode_decode(proc.communicate()[0],
+ encoding=_encodings['fs'])
+ status = proc.wait()
+ self.assertEqual(os.WIFEXITED(status) and \
+ os.WEXITSTATUS(status) == os.EX_OK, True, msg=output)
diff --git a/lib/portage/tests/lint/test_compile_modules.py b/lib/portage/tests/lint/test_compile_modules.py
new file mode 100644
index 000000000..51eb8cd8a
--- /dev/null
+++ b/lib/portage/tests/lint/test_compile_modules.py
@@ -0,0 +1,67 @@
+# Copyright 2009-2014 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+import errno
+import itertools
+import stat
+import sys
+
+from portage.const import PORTAGE_BIN_PATH, PORTAGE_PYM_PATH, PORTAGE_PYM_PACKAGES
+from portage.tests import TestCase
+from portage.tests.lint.metadata import module_metadata, script_metadata
+from portage import os
+from portage import _encodings
+from portage import _unicode_decode, _unicode_encode
+
+class CompileModulesTestCase(TestCase):
+
+ def testCompileModules(self):
+ iters = [os.walk(os.path.join(PORTAGE_PYM_PATH, x))
+ for x in PORTAGE_PYM_PACKAGES]
+ iters.append(os.walk(PORTAGE_BIN_PATH))
+
+ for parent, _dirs, files in itertools.chain(*iters):
+ parent = _unicode_decode(parent,
+ encoding=_encodings['fs'], errors='strict')
+ for x in files:
+ x = _unicode_decode(x,
+ encoding=_encodings['fs'], errors='strict')
+ if x[-4:] in ('.pyc', '.pyo'):
+ continue
+ x = os.path.join(parent, x)
+ st = os.lstat(x)
+ if not stat.S_ISREG(st.st_mode):
+ continue
+
+ bin_path = os.path.relpath(x, PORTAGE_BIN_PATH)
+ mod_path = os.path.relpath(x, PORTAGE_PYM_PATH)
+
+ meta = module_metadata.get(mod_path) or script_metadata.get(bin_path)
+ if meta:
+ req_py = tuple(int(x) for x
+ in meta.get('required_python', '0.0').split('.'))
+ if sys.version_info < req_py:
+ continue
+
+ do_compile = False
+ if x[-3:] == '.py':
+ do_compile = True
+ else:
+ # 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:
+ with open(_unicode_encode(x,
+ encoding=_encodings['fs'], errors='strict'), 'rb') as f:
+ compile(f.read(), x, 'exec')
diff --git a/lib/portage/tests/lint/test_import_modules.py b/lib/portage/tests/lint/test_import_modules.py
new file mode 100644
index 000000000..fcdcb3b33
--- /dev/null
+++ b/lib/portage/tests/lint/test_import_modules.py
@@ -0,0 +1,44 @@
+# Copyright 2011-2012 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+from itertools import chain
+
+from portage.const import PORTAGE_PYM_PATH, PORTAGE_PYM_PACKAGES
+from portage.tests import TestCase
+from portage import os
+from portage import _encodings
+from portage import _unicode_decode
+
+class ImportModulesTestCase(TestCase):
+
+ def testImportModules(self):
+ expected_failures = frozenset((
+ ))
+
+ iters = (self._iter_modules(os.path.join(PORTAGE_PYM_PATH, x))
+ for x in PORTAGE_PYM_PACKAGES)
+ for mod in chain(*iters):
+ try:
+ __import__(mod)
+ except ImportError as e:
+ if mod not in expected_failures:
+ self.assertTrue(False, "failed to import '%s': %s" % (mod, e))
+ del e
+
+ def _iter_modules(self, base_dir):
+ for parent, dirs, files in os.walk(base_dir):
+ parent = _unicode_decode(parent,
+ encoding=_encodings['fs'], errors='strict')
+ parent_mod = parent[len(PORTAGE_PYM_PATH)+1:]
+ parent_mod = parent_mod.replace("/", ".")
+ for x in files:
+ x = _unicode_decode(x,
+ encoding=_encodings['fs'], errors='strict')
+ if x[-3:] != '.py':
+ continue
+ x = x[:-3]
+ if x[-8:] == '__init__':
+ x = parent_mod
+ else:
+ x = parent_mod + "." + x
+ yield x