[Zope3-checkins] CVS: Zope3/src/zope/modulealias/tests -
dummymodule.py:1.1.2.1 test_modulealias.py:1.1.2.2
Chris McDonough
chrism at plope.com
Wed Jan 14 11:46:42 EST 2004
Update of /cvs-repository/Zope3/src/zope/modulealias/tests
In directory cvs.zope.org:/tmp/cvs-serv7425/modulealias/tests
Modified Files:
Tag: steveachrismcd-securitypolicy-branch
test_modulealias.py
Added Files:
Tag: steveachrismcd-securitypolicy-branch
dummymodule.py
Log Message:
Write more tests, refactor, add importing functionality, rename schema elements.
=== Added File Zope3/src/zope/modulealias/tests/dummymodule.py ===
# dummy module for testing.
=== Zope3/src/zope/modulealias/tests/test_modulealias.py 1.1.2.1 => 1.1.2.2 ===
--- Zope3/src/zope/modulealias/tests/test_modulealias.py:1.1.2.1 Wed Jan 14 09:59:12 2004
+++ Zope3/src/zope/modulealias/tests/test_modulealias.py Wed Jan 14 11:46:11 2004
@@ -1,6 +1,23 @@
import unittest
import sys
-from zope.modulealias.metaconfigure import _defineModuleAlias
+from zope.configuration import xmlconfig
+from zope.configuration.config import ConfigurationContext
+# math is imported as an example module to test with
+import math
+
+stuff = """
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ i18n_domain="zope"
+ >
+
+ <include package="zope.modulealias" file="meta.zcml"/>
+
+ <modulealias module="unittest" alias="unittest_alias"/>
+
+</configure>
+"""
+
class Test(unittest.TestCase):
def setUp(self):
@@ -13,10 +30,46 @@
del sys.modules[key]
def test_definemodulealias(self):
- _defineModuleAlias('unittest_alias', 'unittest')
+ context = ConfigurationContext()
+ from zope.modulealias.metaconfigure import alias_module
+ alias_module(module='unittest', alias='unittest_alias',
+ context=context)
self.assert_('unittest_alias' in sys.modules.keys())
self.assertEqual(sys.modules['unittest_alias'],sys.modules['unittest'])
-
+
+ def test_cantoverride(self):
+ context = ConfigurationContext()
+ from zope.modulealias.metaconfigure import alias_module
+ from zope.modulealias.metaconfigure import ModuleAliasException
+ self.assertRaises(ModuleAliasException, alias_module,
+ module='unittest', alias='zope.modulealias.tests',
+ context=context)
+
+ def test_samemodule_doesntfail(self):
+ context = ConfigurationContext()
+ from zope.modulealias.metaconfigure import alias_module
+ self.assert_('math' in sys.modules)
+ sys.modules['zope.modulealias.tests.test_modulealias.math'] = math
+ alias_module(module='zope.modulealias.tests.test_modulealias.math',
+ alias='math',
+ context=context)
+
+ def test_module_not_imported(self):
+ context = ConfigurationContext()
+ from zope.modulealias.metaconfigure import alias_module
+ m1 = 'zope.modulealias.tests.dummymodule'
+ m2 = 'zope.modulealias.tests.dummymodule2'
+ self.assert_(m1 not in sys.modules)
+ alias_module(module=m1, alias=m2, context=context)
+ self.assert_(m1 in sys.modules)
+ self.assert_(sys.modules[m1] is sys.modules[m2])
+
+ def test_zcml(self):
+ context = xmlconfig.string(stuff)
+ self.assert_('unittest_alias' in sys.modules.keys())
+ self.assertEqual(sys.modules['unittest_alias'],sys.modules['unittest'])
+
+
def test_suite():
loader=unittest.TestLoader()
More information about the Zope3-Checkins
mailing list