mirror of https://github.com/django/django.git
Fixed #16780 -- Removed a timing sensitive test from the template test suite. Thanks to Alex for the lend of his eyeballs.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16735 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
0b174ccf0e
commit
dc3b2a0fdf
|
@ -84,6 +84,9 @@ class SomeOtherException(Exception):
|
||||||
class ContextStackException(Exception):
|
class ContextStackException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class ShouldNotExecuteException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
class SomeClass:
|
class SomeClass:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.otherclass = OtherClass()
|
self.otherclass = OtherClass()
|
||||||
|
@ -127,8 +130,7 @@ class TestObj(object):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def is_bad(self):
|
def is_bad(self):
|
||||||
time.sleep(0.3)
|
raise ShouldNotExecuteException()
|
||||||
return True
|
|
||||||
|
|
||||||
class SilentGetItemClass(object):
|
class SilentGetItemClass(object):
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
|
@ -456,24 +458,21 @@ class Templates(unittest.TestCase):
|
||||||
settings.TEMPLATE_DEBUG = template_debug
|
settings.TEMPLATE_DEBUG = template_debug
|
||||||
for is_cached in (False, True):
|
for is_cached in (False, True):
|
||||||
try:
|
try:
|
||||||
start = datetime.now()
|
try:
|
||||||
test_template = loader.get_template(name)
|
test_template = loader.get_template(name)
|
||||||
end = datetime.now()
|
except ShouldNotExecuteException:
|
||||||
if end-start > timedelta(seconds=0.2):
|
failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Template loading invoked method that shouldn't have been invoked." % (is_cached, invalid_str, template_debug, name))
|
||||||
failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Took too long to parse test" % (is_cached, invalid_str, template_debug, name))
|
|
||||||
|
|
||||||
start = datetime.now()
|
try:
|
||||||
output = self.render(test_template, vals)
|
output = self.render(test_template, vals)
|
||||||
end = datetime.now()
|
except ShouldNotExecuteException:
|
||||||
if end-start > timedelta(seconds=0.2):
|
failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Template rendering invoked method that shouldn't have been invoked." % (is_cached, invalid_str, template_debug, name))
|
||||||
failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Took too long to render test" % (is_cached, invalid_str, template_debug, name))
|
|
||||||
except ContextStackException:
|
except ContextStackException:
|
||||||
failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Context stack was left imbalanced" % (is_cached, invalid_str, template_debug, name))
|
failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Context stack was left imbalanced" % (is_cached, invalid_str, template_debug, name))
|
||||||
continue
|
continue
|
||||||
except Exception:
|
except Exception:
|
||||||
exc_type, exc_value, exc_tb = sys.exc_info()
|
exc_type, exc_value, exc_tb = sys.exc_info()
|
||||||
if exc_type != result:
|
if exc_type != result:
|
||||||
print "CHECK", name, exc_type, result
|
|
||||||
tb = '\n'.join(traceback.format_exception(exc_type, exc_value, exc_tb))
|
tb = '\n'.join(traceback.format_exception(exc_type, exc_value, exc_tb))
|
||||||
failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Got %s, exception: %s\n%s" % (is_cached, invalid_str, template_debug, name, exc_type, exc_value, tb))
|
failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Got %s, exception: %s\n%s" % (is_cached, invalid_str, template_debug, name, exc_type, exc_value, tb))
|
||||||
continue
|
continue
|
||||||
|
@ -921,9 +920,7 @@ class Templates(unittest.TestCase):
|
||||||
'if-tag-error12': ("{% if a not b %}yes{% endif %}", {}, template.TemplateSyntaxError),
|
'if-tag-error12': ("{% if a not b %}yes{% endif %}", {}, template.TemplateSyntaxError),
|
||||||
|
|
||||||
# If evaluations are shortcircuited where possible
|
# If evaluations are shortcircuited where possible
|
||||||
# These tests will fail by taking too long to run. When the if clause
|
# If is_bad is invoked, it will raise a ShouldNotExecuteException
|
||||||
# is shortcircuiting correctly, the is_bad() function shouldn't be
|
|
||||||
# evaluated, and the deliberate sleep won't happen.
|
|
||||||
'if-tag-shortcircuit01': ('{% if x.is_true or x.is_bad %}yes{% else %}no{% endif %}', {'x': TestObj()}, "yes"),
|
'if-tag-shortcircuit01': ('{% if x.is_true or x.is_bad %}yes{% else %}no{% endif %}', {'x': TestObj()}, "yes"),
|
||||||
'if-tag-shortcircuit02': ('{% if x.is_false and x.is_bad %}yes{% else %}no{% endif %}', {'x': TestObj()}, "no"),
|
'if-tag-shortcircuit02': ('{% if x.is_false and x.is_bad %}yes{% else %}no{% endif %}', {'x': TestObj()}, "no"),
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue