Make temp attribute more solid and add unit test on regression

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2013-04-24 22:34:14 +02:00
parent 4447ac5f1a
commit 50daf1b4c8
3 changed files with 16 additions and 3 deletions

View File

@ -66,7 +66,7 @@ class HyTypeError(TypeError):
self.expression = expression
def __str__(self):
return (self.message + " (line %s, column %d)"
return (super(HyTypeError, self).__str__() + " (line %s, column %d)"
% (self.expression.start_line,
self.expression.start_column))

View File

@ -34,8 +34,10 @@ def temporary_attribute_value(obj, attribute, value):
"""Temporarily switch an object attribute value to another value."""
original_value = getattr(obj, attribute)
setattr(obj, attribute, value)
yield
setattr(obj, attribute, original_value)
try:
yield
finally:
setattr(obj, attribute, original_value)
def flatten_literal_list(entry):

View File

@ -391,3 +391,14 @@ def test_ast_unicode_strings():
assert _compile_string("test") == "test"
assert _compile_string("\u03b1\u03b2") == "\u03b1\u03b2"
assert _compile_string("\xc3\xa9") == "\xc3\xa9"
def test_compile_error():
"""Ensure we get compile error in tricky cases"""
try:
hy_compile(tokenize("(fn [] (= 1))"))
except HyCompileError as e:
assert(str(e)
== "`=' needs at least 2 arguments, got 1 (line 1, column 8)")
else:
assert(False)