提交 dc9250ea authored 作者: Olivier Delalleau's avatar Olivier Delalleau

Fixed syntax error in tests with Python 2.5-

Fix mostly written by Fred. Tested in Python 2.7 and Python 2.5.
上级 3849399c
...@@ -20,6 +20,7 @@ def test_remove_python_framework_dir(): ...@@ -20,6 +20,7 @@ def test_remove_python_framework_dir():
cmd.append( cmd.append(
'-L/opt/local/Library/Frameworks/Python.framework/Versions/2.7/Python') '-L/opt/local/Library/Frameworks/Python.framework/Versions/2.7/Python')
assert remove_python_framework_dir(cmd) == cmd[0:-2] + cmd[-1:] assert remove_python_framework_dir(cmd) == cmd[0:-2] + cmd[-1:]
# We test for the warning only if we can use 'catch_warnings' (Python 2.6+) # We test for the warning only if we can use 'catch_warnings' (Python 2.6+)
# as otherwise it is difficult to do it properly. # as otherwise it is difficult to do it properly.
try: try:
...@@ -27,7 +28,13 @@ def test_remove_python_framework_dir(): ...@@ -27,7 +28,13 @@ def test_remove_python_framework_dir():
except AttributeError: except AttributeError:
return return
cmd.append('Frameworks/Python.framework/Versions/2.6/Python') cmd.append('Frameworks/Python.framework/Versions/2.6/Python')
with warnings.catch_warnings(record=True) as record: # Python 2.4 "emulation" of `with` statement. It is necessary even if this
# code is not executed, because using `with` would result in a SyntaxError.
with_context = warnings.catch_warnings(record=True)
record = with_context.__enter__()
try:
assert remove_python_framework_dir(cmd) == cmd[0:-3] + cmd[-2:-1] assert remove_python_framework_dir(cmd) == cmd[0:-3] + cmd[-2:-1]
assert len(record) == 1 assert len(record) == 1
assert 'remove_python_framework_dir' in str(record[0].message) assert 'remove_python_framework_dir' in str(record[0].message)
finally:
with_context.__exit__(None, None, None)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论