Make temp attribute more solid and add unit test on regression
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
4447ac5f1a
commit
50daf1b4c8
|
@ -66,7 +66,7 @@ class HyTypeError(TypeError):
|
||||||
self.expression = expression
|
self.expression = expression
|
||||||
|
|
||||||
def __str__(self):
|
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_line,
|
||||||
self.expression.start_column))
|
self.expression.start_column))
|
||||||
|
|
||||||
|
|
|
@ -34,8 +34,10 @@ def temporary_attribute_value(obj, attribute, value):
|
||||||
"""Temporarily switch an object attribute value to another value."""
|
"""Temporarily switch an object attribute value to another value."""
|
||||||
original_value = getattr(obj, attribute)
|
original_value = getattr(obj, attribute)
|
||||||
setattr(obj, attribute, value)
|
setattr(obj, attribute, value)
|
||||||
yield
|
try:
|
||||||
setattr(obj, attribute, original_value)
|
yield
|
||||||
|
finally:
|
||||||
|
setattr(obj, attribute, original_value)
|
||||||
|
|
||||||
|
|
||||||
def flatten_literal_list(entry):
|
def flatten_literal_list(entry):
|
||||||
|
|
|
@ -391,3 +391,14 @@ def test_ast_unicode_strings():
|
||||||
assert _compile_string("test") == "test"
|
assert _compile_string("test") == "test"
|
||||||
assert _compile_string("\u03b1\u03b2") == "\u03b1\u03b2"
|
assert _compile_string("\u03b1\u03b2") == "\u03b1\u03b2"
|
||||||
assert _compile_string("\xc3\xa9") == "\xc3\xa9"
|
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)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user