[Python-checkins] r55655 - python/branches/bcannon-objcap/tests/fail/sys_inaccessible.py
brett.cannon
python-checkins at python.org
Tue May 29 21:18:55 CEST 2007
Author: brett.cannon
Date: Tue May 29 21:18:55 2007
New Revision: 55655
Added:
python/branches/bcannon-objcap/tests/fail/sys_inaccessible.py (contents, props changed)
Log:
Thoroughly check that no modules that are required to exist for the interpreter
to work (and thus imported before importlib takes over) exposes the 'sys'
module.
Added: python/branches/bcannon-objcap/tests/fail/sys_inaccessible.py
==============================================================================
--- (empty file)
+++ python/branches/bcannon-objcap/tests/fail/sys_inaccessible.py Tue May 29 21:18:55 2007
@@ -0,0 +1,70 @@
+"""None of the modules required for the interpreter to work should expose the
+'sys' module (nor the modules that they import)."""
+import encodings
+module_type = type(encodings)
+examined = set()
+def check_imported_modules(module):
+ """Recursively check that the module (and the modules it imports) do not
+ expose the 'sys' module."""
+ assert isinstance(module, module_type)
+ if module.__name__ == 'sys':
+ raise Exception
+ for attr in module.__dict__.values():
+ if isinstance(attr, module_type) and attr.__name__ not in examined:
+ examined.add(attr.__name__)
+ check_imported_modules(attr)
+
+
+try:
+ import __builtin__
+ __builtin__.sys
+ check_imported_modules(__builtin__)
+except AttributeError:
+ pass
+else:
+ raise Exception
+
+try:
+ import __main__
+ __main__.sys
+ check_imported_modules(__main__)
+except AttributeError:
+ pass
+else:
+ raise Exception
+
+try:
+ import exceptions
+ exceptions.sys
+ check_imported_modules(exceptions)
+except AttributeError:
+ pass
+else:
+ raise Exception
+
+try:
+ import encodings
+ encodings.sys
+ check_imported_modules(encodings)
+except AttributeError:
+ pass
+else:
+ raise Exception
+
+try:
+ import codecs
+ codecs.sys
+ check_imported_modules(codecs)
+except AttributeError:
+ pass
+else:
+ raise Exception
+
+try:
+ import _codecs
+ _codecs.sys
+ check_imported_modules(_codecs)
+except AttributeError:
+ pass
+else:
+ raise Exception
More information about the Python-checkins
mailing list