From 577e9a0c816d41a3b3427afd545d09c366a3b950 Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Wed, 13 Jun 2012 10:55:46 -0700 Subject: [PATCH] Run the tests in optimized mode too to ensure that things still work without assertions. Fix one assert that should have been a runtime error (there are probably more, but this is the only one currently covered by the test suite). --- .gitignore | 1 + tornado/simple_httpclient.py | 6 ++++-- tox.ini | 18 +++++++++++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 0e0a11e8d..c84e747f4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.pyc +*.pyo *.so *.class *~ diff --git a/tornado/simple_httpclient.py b/tornado/simple_httpclient.py index f5f075fa8..c6e8a3a7c 100644 --- a/tornado/simple_httpclient.py +++ b/tornado/simple_httpclient.py @@ -364,8 +364,10 @@ class _HTTPConnection(object): if 100 <= self.code < 200 or self.code in (204, 304): # These response codes never have bodies # http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.3 - assert "Transfer-Encoding" not in self.headers - assert content_length in (None, 0) + if ("Transfer-Encoding" in self.headers or + content_length not in (None, 0)): + raise ValueError("Response with code %d should not have body" % + self.code) self._on_body(b("")) return diff --git a/tox.ini b/tox.ini index 40909881c..27189a48e 100644 --- a/tox.ini +++ b/tox.ini @@ -13,7 +13,7 @@ [tox] # "-full" variants include optional dependencies, to ensure # that things work both in a bare install and with all the extras. -envlist = py27-full, py27-curl, py25-full, py32, pypy, py25, py26, py26-full, py27, py32-utf8, py33 +envlist = py27-full, py27-curl, py25-full, py32, pypy, py25, py26, py26-full, py27, py32-utf8, py33, py27-opt, py32-opt [testenv] commands = python -m tornado.test.runtests {posargs:} @@ -87,3 +87,19 @@ setenv = LANG=en_US.utf-8 [testenv:py33] # tox doesn't yet know "py33" by default basepython = python3.3 + +# Python's optimized mode disables the assert statement, so run the +# tests in this mode to ensure we haven't fallen into the trap of relying +# on an assertion's side effects or using them for things that should be +# runtime errors. +[testenv:py27-opt] +basepython = python2.7 +deps = + MySQL-python + pycurl + twisted>=12.0.0 +commands = python -O -m tornado.test.runtests {posargs:} + +[testenv:py32-opt] +basepython = python3.2 +commands = python -O -m tornado.test.runtests {posargs:} -- 2.47.2