[Checkins] SVN: zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/ Full coverage for z.c.xmlconfig.openInOrPlain.
Tres Seaver
cvs-admin at zope.org
Thu May 10 23:26:17 UTC 2012
Log message for revision 125827:
Full coverage for z.c.xmlconfig.openInOrPlain.
Also, simplified implementation.
Changed:
U zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/test_xmlconfig.py
U zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/xmlconfig.py
-=-
Modified: zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/test_xmlconfig.py
===================================================================
--- zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/test_xmlconfig.py 2012-05-10 23:26:09 UTC (rev 125826)
+++ zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/test_xmlconfig.py 2012-05-10 23:26:13 UTC (rev 125827)
@@ -422,13 +422,35 @@
self.assertEqual(data.basepath, None)
-class Test_openInOrPlain(unittest.TestCase):
+class Test_openInOrPlain(_Catchable, unittest.TestCase):
def _callFUT(self, *args, **kw):
from zope.configuration.xmlconfig import openInOrPlain
return openInOrPlain(*args, **kw)
+ def _makeFilename(self, fn):
+ import os
+ from zope.configuration.tests.samplepackage import __file__
+ return os.path.join(os.path.dirname(__file__), fn)
+ def test_file_present(self):
+ import os
+ fp = self._callFUT(self._makeFilename('configure.zcml'))
+ self.assertEqual(os.path.basename(fp.name), 'configure.zcml')
+
+ def test_file_missing_but_dot_in_present(self):
+ import os
+ fp = self._callFUT(self._makeFilename('foo.zcml'))
+ self.assertEqual(os.path.basename(fp.name), 'foo.zcml.in')
+
+ def test_file_missing_and_dot_in_not_present(self):
+ import errno
+ exc = self.assertRaises(
+ IOError,
+ self._callFUT, self._makeFilename('nonesuch.zcml'))
+ self.assertEqual(exc.errno, errno.ENOENT)
+
+
class Test_include(unittest.TestCase):
def _callFUT(self, *args, **kw):
Modified: zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/xmlconfig.py
===================================================================
--- zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/xmlconfig.py 2012-05-10 23:26:09 UTC (rev 125826)
+++ zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/xmlconfig.py 2012-05-10 23:26:13 UTC (rev 125827)
@@ -305,19 +305,16 @@
any other reason, allow the failure to propogate.
"""
try:
- fp = open(filename)
+ return open(filename)
except IOError as e:
code, msg = e.args
if code == errno.ENOENT:
fn = filename + ".in"
if os.path.exists(fn):
- fp = open(fn)
- else:
- raise
- else:
- raise
- return fp
+ return open(fn)
+ raise
+
class IInclude(Interface):
"""The ``include``, ``includeOverrides`` and ``exclude`` directives
More information about the checkins
mailing list