[Checkins] SVN: zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/ Cover __repr__ and __str__ of z.c.xmlconfig.ParserInfo as well as feasible.
Tres Seaver
cvs-admin at zope.org
Wed May 9 23:47:15 UTC 2012
Log message for revision 125805:
Cover __repr__ and __str__ of z.c.xmlconfig.ParserInfo as well as feasible.
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-09 23:47:08 UTC (rev 125804)
+++ zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/test_xmlconfig.py 2012-05-09 23:47:12 UTC (rev 125805)
@@ -62,6 +62,13 @@
class ParserInfoTests(unittest.TestCase):
+ _tempdir = None
+
+ def tearDown(self):
+ if self._tempdir is not None:
+ import shutil
+ shutil.rmtree(self._tempdir)
+
def _getTargetClass(self):
from zope.configuration.xmlconfig import ParserInfo
return ParserInfo
@@ -69,7 +76,37 @@
def _makeOne(self, *args, **kw):
return self._getTargetClass()(*args, **kw)
+ def test___repr___w_eline_ecolumn_match_line_column(self):
+ pi = self._makeOne('filename.xml', 24, 32)
+ pi.end(24, 32)
+ self.assertEqual(repr(pi), 'File "filename.xml", line 24.32')
+ def test___repr___w_eline_ecolumn_dont_match_line_column(self):
+ pi = self._makeOne('filename.xml', 24, 32)
+ pi.end(33, 21)
+ self.assertEqual(repr(pi), 'File "filename.xml", line 24.32-33.21')
+
+ def test___str___w_eline_ecolumn_match_line_column(self):
+ pi = self._makeOne('filename.xml', 24, 32)
+ pi.end(24, 32)
+ self.assertEqual(str(pi), 'File "filename.xml", line 24.32')
+
+ def test___str___w_eline_ecolumn_dont_match_line_column_bad_file(self):
+ pi = self._makeOne('/path/to/nonesuch.xml', 24, 32)
+ pi.end(33, 21)
+ self.assertEqual(str(pi),
+ 'File "/path/to/nonesuch.xml", line 24.32-33.21\n'
+ ' Could not read source.')
+
+ def test___str___w_good_file(self):
+ pi = self._makeOne('tests//sample.zcml', 3, 2)
+ pi.end(3, 57)
+ self.assertEqual(
+ str(pi),
+ 'File "tests//sample.zcml", line 3.2-3.57\n'
+ ' <directives namespace="http://namespaces.zope.org/zope">')
+
+
class ConfigurationHandlerTests(unittest.TestCase):
def _getTargetClass(self):
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-09 23:47:08 UTC (rev 125804)
+++ zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/xmlconfig.py 2012-05-09 23:47:12 UTC (rev 125805)
@@ -121,17 +121,17 @@
else:
lines = f.readlines()[self.line-1:self.eline]
ecolumn = self.ecolumn
- if lines[-1][ecolumn:ecolumn+2] == '</':
+ if lines[-1][ecolumn:ecolumn+2] == '</': #pragma NO COVER
# We're pointing to the start of an end tag. Try to find
# the end
l = lines[-1].find('>', ecolumn)
if l >= 0:
lines[-1] = lines[-1][:l+1]
- else:
+ else: #pragma NO COVER
lines[-1] = lines[-1][:ecolumn+1]
column = self.column
- if lines[0][:column].strip():
+ if lines[0][:column].strip(): #pragma NO COVER
# Remove text before start if it's noy whitespace
lines[0] = lines[0][self.column:]
@@ -139,7 +139,7 @@
blank = u('')
try:
src = blank.join([pad + l for l in lines])
- except UnicodeDecodeError:
+ except UnicodeDecodeError: #pragma NO COVER
# XXX:
# I hope so most internation zcml will use UTF-8 as encoding
# otherwise this code must be made more clever
More information about the checkins
mailing list