def test_recursions_1(self):
# Testing recursion checks ...
class Letter(str):
def __new__(cls, letter):
if letter == 'EPS':
return str.__new__(cls)
return str.__new__(cls, letter)
def __str__(self):
if not self:
return 'EPS'
return self
# sys.stdout needs to be the original to trigger the recursion bug
test_stdout = sys.stdout
sys.stdout = test_support.get_original_stdout()
try:
# nothing should actually be printed, this should raise an exception
print Letter('w')
except RuntimeError:
pass
else:
self.fail("expected a RuntimeError for print recursion")
finally:
sys.stdout = test_stdout
评论列表
文章目录