From 149482208c430cbd9d730c35256430ea6cf58c3d Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Fri, 28 Jan 2011 23:54:50 -0800 Subject: [PATCH] Test import of all modules. --- pym/portage/_selinux.py | 6 ++-- .../test_lazy_import_portage_baseline.py | 1 + pym/portage/tests/lint/test_import_modules.py | 35 +++++++++++++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 pym/portage/tests/lint/test_import_modules.py diff --git a/pym/portage/_selinux.py b/pym/portage/_selinux.py index d86dd9594..9470978c4 100644 --- a/pym/portage/_selinux.py +++ b/pym/portage/_selinux.py @@ -1,4 +1,4 @@ -# Copyright 1999-2010 Gentoo Foundation +# Copyright 1999-2011 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # Don't use the unicode-wrapped os and shutil modules here since @@ -11,8 +11,8 @@ from portage import _encodings from portage import _unicode_decode from portage import _unicode_encode from portage.localization import _ - -import selinux +portage.proxy.lazyimport.lazyimport(globals(), + 'selinux') def copyfile(src, dest): src = _unicode_encode(src, encoding=_encodings['fs'], errors='strict') diff --git a/pym/portage/tests/lazyimport/test_lazy_import_portage_baseline.py b/pym/portage/tests/lazyimport/test_lazy_import_portage_baseline.py index 7c3b2f99a..28cf28436 100644 --- a/pym/portage/tests/lazyimport/test_lazy_import_portage_baseline.py +++ b/pym/portage/tests/lazyimport/test_lazy_import_portage_baseline.py @@ -19,6 +19,7 @@ class LazyImportPortageBaselineTestCase(TestCase): 'portage.const', 'portage.localization', 'portage.proxy', 'portage.proxy.lazyimport', 'portage.proxy.objectproxy', 'portage._ensure_encodings', + 'portage._selinux', ]) _baseline_import_cmd = [portage._python_interpreter, '-c', ''' diff --git a/pym/portage/tests/lint/test_import_modules.py b/pym/portage/tests/lint/test_import_modules.py new file mode 100644 index 000000000..cee579a3a --- /dev/null +++ b/pym/portage/tests/lint/test_import_modules.py @@ -0,0 +1,35 @@ +# Copyright 2011 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +from portage.const import PORTAGE_PYM_PATH +from portage.tests import TestCase +from portage import os +from portage import _encodings +from portage import _unicode_decode + +class ImportModulesTestCase(TestCase): + + def testImportModules(self): + for mod in self._list_modules(PORTAGE_PYM_PATH): + __import__(mod) + + def _list_modules(self, base_dir): + all_modules = [] + 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 + all_modules.append(x) + + return all_modules -- 2.26.2