Browse files

- Show only line numbers in error reports on console (previously both

  line numbers and column numbers were reported, but the column
  numbers seem to be meaningless in most debugging scenarios).

- Fix an off by one error in line number reporting in errors.
  • Loading branch information...
1 parent 8b1b4ba commit 374d7afdf536a31eda5d35fd2d0d8145061c21ff @mcdonc mcdonc committed Jul 26, 2009
View
6 CHANGES.txt
@@ -4,6 +4,12 @@ repoze.configuration Changelog
Next release
------------
+- Show only line numbers in error reports on console (previously both
+ line numbers and column numbers were reported, but the column
+ numbers seem to be meaningless in most debugging scenarios).
+
+- Fix an off by one error in line number reporting in errors.
+
- Interpolation variables now try to use the registry first, but fall
back to "stack" values; the most important of which is ``%(here)s``;
this interpolation variable can be used in any config file. It will
View
10 repoze/configuration/declaration.py
@@ -200,15 +200,13 @@ def lineinfo(node):
try:
f = open(filename, 'r')
f.seek(start_mark.index)
- data = f.read(end_mark.index - start_mark.index) + 'in '
+ data = f.read(end_mark.index - start_mark.index) + ' in '
except (OSError, IOError):
data = ''
- msg = ('%slines %s:%s-%s:%s of file "%s"' % (
+ msg = ('%slines %s-%s of file "%s"' % (
data,
- start_mark.line,
- start_mark.column,
- end_mark.line,
- end_mark.column,
+ start_mark.line+1,
+ end_mark.line+1,
start_mark.name,
)
)
View
4 repoze/configuration/loader.py
@@ -27,8 +27,8 @@ def interpolate_str(self, loader, node):
try:
value = self.context.interpolate(value)
except KeyError, why:
- msg = 'Cannot interpolate %%(%s)s\n' % why[0]
- msg = msg + lineinfo(node)
+ li = lineinfo(node)
+ msg = 'Cannot interpolate %%(%s)s found in %s' % (why[0], li)
raise ConfigurationError(msg)
return value
View
55 repoze/configuration/tests/test_declaration.py
@@ -186,7 +186,7 @@ def test_lineinfo(self):
node = DummyNode()
decl = self._makeOne(context, loader, node)
line = decl.lineinfo
- self.assertEqual(line, 'lines 1:1-1:1 of file "dummy"')
+ self.assertEqual(line, 'lines 2-2 of file "dummy"')
def test_get_structure_deep(self):
context = DummyContext()
@@ -244,64 +244,15 @@ def test_withfile(self):
self.assertEqual(len(lines), 3)
self.assertEqual(lines[0], '--- !abc')
self.assertEqual(lines[1], 'foo: 1')
- self.assertEqual(lines[2], 'in lines 1:2-1:2 of file "%s"' % filename)
+ self.assertEqual(lines[2], ' in lines 2-2 of file "%s"' % filename)
def test_file_exception(self):
node = DummyNode()
msg = self._callFUT(node)
lines = msg.split('\n')
self.assertEqual(len(lines), 1)
- self.assertEqual(lines[0], 'lines 1:1-1:1 of file "dummy"')
-
-## class DummyDirective:
-## def __init__(self, result, raise_exc=False):
-## self.result = result
-## self.raise_exc = raise_exc
-
-## def __call__(self, declaration):
-## if self.raise_exc:
-## raise KeyError('yo')
-## return self.result
-
-## def action(self, callback, discriminator=None, override=False):
-## self.actions.append((callback, discriminator, override))
-
-## def test_directive_calls_action(self):
-## directive = DummyDirective([('a', 'b')])
-## constructor = self._callFUT(directive)
-## node = DummyNode()
-## context = DummyContext()
-## loader = DummyLoader(context)
-## constructor(loader, node)
-## self.assertEqual(context.actions, [(('a', 'b'), node)] )
-
-## def test_directive_returns_dict(self):
-## directive = DummyDirective({'a':'1'})
-## constructor = self._callFUT(directive)
-## node = DummyNode()
-## context = DummyContext()
-## loader = DummyLoader(context)
-## result = constructor(loader, node)
-## self.assertEqual(context.actions, [({'a':'1'}, node)] )
-
-## def test_withexception(self):
-## directive = DummyDirective([('a', 'b')], raise_exc=True)
-## constructor = self._callFUT(directive)
-## node = DummyNode()
-## context = DummyContext()
-## loader = DummyLoader(context)
-## self.assertRaises(KeyError, constructor, loader, node)
-
-## def test_construct_mapping_uses_deep(self):
-## directive = DummyDirective({'a':1})
-## constructor = self._callFUT(directive)
-## node = DummyNode('mapping')
-## context = DummyContext()
-## loader = DummyLoader(context)
-## constructor(loader, node)
-## self.assertEqual(context.actions, [({'a':1}, node)] )
-## self.assertEqual(loader.deep, True)
+ self.assertEqual(lines[0], 'lines 2-2 of file "dummy"')
class DummyNode:
def __init__(self, id='theid'):

0 comments on commit 374d7af

Please sign in to comment.