Permalink
Browse files

Moved a few generic asserts to assert_equal

  • Loading branch information...
1 parent 639f35b commit c53d3fd439c32e8c5c4a2bf817501aeaee44ca9d @mitsuhiko mitsuhiko committed Oct 6, 2011
Showing with 40 additions and 40 deletions.
  1. +40 −40 werkzeug/testsuite/wsgi.py
View
@@ -41,21 +41,21 @@ def null_application(environ, start_response):
for p in '/test.txt', '/sources/test.txt':
app_iter, status, headers = run_wsgi_app(app, create_environ(p))
- assert status == '200 OK'
- assert ''.join(app_iter).strip() == 'FOUND'
+ self.assert_equal(status, '200 OK')
+ self.assert_equal(''.join(app_iter).strip(), 'FOUND')
app_iter, status, headers = run_wsgi_app(app, create_environ('/pkg/debugger.js'))
contents = ''.join(app_iter)
assert '$(function() {' in contents
app_iter, status, headers = run_wsgi_app(app, create_environ('/missing'))
- assert status == '404 NOT FOUND'
- assert ''.join(app_iter).strip() == 'NOT FOUND'
+ self.assert_equal(status, '404 NOT FOUND')
+ self.assert_equal(''.join(app_iter).strip(), 'NOT FOUND')
def test_get_host(self):
env = {'HTTP_X_FORWARDED_HOST': 'example.org',
'SERVER_NAME': 'bullshit', 'HOST_NAME': 'ignore me dammit'}
- assert wsgi.get_host(env) == 'example.org'
+ self.assert_equal(wsgi.get_host(env), 'example.org')
assert wsgi.get_host(create_environ('/', 'http://example.org')) \
== 'example.org'
@@ -64,33 +64,33 @@ def foo(environ, start_response):
return BaseResponse('Test')
client = Client(wsgi.responder(foo), BaseResponse)
response = client.get('/')
- assert response.status_code == 200
- assert response.data == 'Test'
+ self.assert_equal(response.status_code, 200)
+ self.assert_equal(response.data, 'Test')
def test_pop_path_info(self):
original_env = {'SCRIPT_NAME': '/foo', 'PATH_INFO': '/a/b///c'}
# regular path info popping
def assert_tuple(script_name, path_info):
- assert env.get('SCRIPT_NAME') == script_name
- assert env.get('PATH_INFO') == path_info
+ self.assert_equal(env.get('SCRIPT_NAME'), script_name)
+ self.assert_equal(env.get('PATH_INFO'), path_info)
env = original_env.copy()
pop = lambda: wsgi.pop_path_info(env)
assert_tuple('/foo', '/a/b///c')
- assert pop() == 'a'
+ self.assert_equal(pop(), 'a')
assert_tuple('/foo/a', '/b///c')
- assert pop() == 'b'
+ self.assert_equal(pop(), 'b')
assert_tuple('/foo/a/b', '///c')
- assert pop() == 'c'
+ self.assert_equal(pop(), 'c')
assert_tuple('/foo/a/b///c', '')
assert pop() is None
def test_peek_path_info(self):
env = {'SCRIPT_NAME': '/foo', 'PATH_INFO': '/aaa/b///c'}
- assert wsgi.peek_path_info(env) == 'aaa'
- assert wsgi.peek_path_info(env) == 'aaa'
+ self.assert_equal(wsgi.peek_path_info(env), 'aaa')
+ self.assert_equal(wsgi.peek_path_info(env), 'aaa')
def test_limited_stream(self):
class RaisingLimitedStream(wsgi.LimitedStream):
@@ -99,53 +99,53 @@ def on_exhausted(self):
io = StringIO('123456')
stream = RaisingLimitedStream(io, 3)
- assert stream.read() == '123'
+ self.assert_equal(stream.read(), '123')
self.assert_raises(BadRequest, stream.read)
io = StringIO('123456')
stream = RaisingLimitedStream(io, 3)
self.assert_equal(stream.tell(), 0)
- assert stream.read(1) == '1'
+ self.assert_equal(stream.read(1), '1')
self.assert_equal(stream.tell(), 1)
- assert stream.read(1) == '2'
+ self.assert_equal(stream.read(1), '2')
self.assert_equal(stream.tell(), 2)
- assert stream.read(1) == '3'
+ self.assert_equal(stream.read(1), '3')
self.assert_equal(stream.tell(), 3)
self.assert_raises(BadRequest, stream.read)
io = StringIO('123456\nabcdefg')
stream = wsgi.LimitedStream(io, 9)
- assert stream.readline() == '123456\n'
- assert stream.readline() == 'ab'
+ self.assert_equal(stream.readline(), '123456\n')
+ self.assert_equal(stream.readline(), 'ab')
io = StringIO('123456\nabcdefg')
stream = wsgi.LimitedStream(io, 9)
- assert stream.readlines() == ['123456\n', 'ab']
+ self.assert_equal(stream.readlines(), ['123456\n', 'ab'])
io = StringIO('123456\nabcdefg')
stream = wsgi.LimitedStream(io, 9)
- assert stream.readlines(2) == ['12']
- assert stream.readlines(2) == ['34']
- assert stream.readlines() == ['56\n', 'ab']
+ self.assert_equal(stream.readlines(2), ['12'])
+ self.assert_equal(stream.readlines(2), ['34'])
+ self.assert_equal(stream.readlines(), ['56\n', 'ab'])
io = StringIO('123456\nabcdefg')
stream = wsgi.LimitedStream(io, 9)
- assert stream.readline(100) == '123456\n'
+ self.assert_equal(stream.readline(100), '123456\n')
io = StringIO('123456\nabcdefg')
stream = wsgi.LimitedStream(io, 9)
- assert stream.readlines(100) == ['123456\n', 'ab']
+ self.assert_equal(stream.readlines(100), ['123456\n', 'ab'])
io = StringIO('123456')
stream = wsgi.LimitedStream(io, 3)
- assert stream.read(1) == '1'
- assert stream.read(1) == '2'
- assert stream.read() == '3'
- assert stream.read() == ''
+ self.assert_equal(stream.read(1), '1')
+ self.assert_equal(stream.read(1), '2')
+ self.assert_equal(stream.read(), '3')
+ self.assert_equal(stream.read(), '')
io = StringIO('123456')
stream = wsgi.LimitedStream(io, 3)
- assert stream.read(-1) == '123'
+ self.assert_equal(stream.read(-1), '123')
def test_limited_stream_disconnection(self):
io = StringIO('A bit of content')
@@ -164,24 +164,24 @@ def test_limited_stream_disconnection(self):
def test_path_info_extraction(self):
x = wsgi.extract_path_info('http://example.com/app', '/app/hello')
- assert x == u'/hello'
+ self.assert_equal(x, u'/hello')
x = wsgi.extract_path_info('http://example.com/app',
'https://example.com/app/hello')
- assert x == u'/hello'
+ self.assert_equal(x, u'/hello')
x = wsgi.extract_path_info('http://example.com/app/',
'https://example.com/app/hello')
- assert x == u'/hello'
+ self.assert_equal(x, u'/hello')
x = wsgi.extract_path_info('http://example.com/app/',
'https://example.com/app')
- assert x == u'/'
+ self.assert_equal(x, u'/')
x = wsgi.extract_path_info(u'http://☃.net/', u'/fööbär')
- assert x == u'/fööbär'
+ self.assert_equal(x, u'/fööbär')
x = wsgi.extract_path_info(u'http://☃.net/x', u'http://☃.net/x/fööbär')
- assert x == u'/fööbär'
+ self.assert_equal(x, u'/fööbär')
env = create_environ(u'/fööbär', u'http://☃.net/x/')
x = wsgi.extract_path_info(env, u'http://☃.net/x/fööbär')
- assert x == u'/fööbär'
+ self.assert_equal(x, u'/fööbär')
x = wsgi.extract_path_info('http://example.com/app/',
'https://example.com/a/hello')
@@ -207,12 +207,12 @@ def test_multi_part_line_breaks(self):
data = 'abcdef\r\nghijkl\r\nmnopqrstuvwxyz\r\nABCDEFGHIJK'
test_stream = StringIO(data)
lines = list(wsgi.make_line_iter(test_stream, limit=len(data), buffer_size=16))
- assert lines == ['abcdef\r\n', 'ghijkl\r\n', 'mnopqrstuvwxyz\r\n', 'ABCDEFGHIJK']
+ self.assert_equal(lines, ['abcdef\r\n', 'ghijkl\r\n', 'mnopqrstuvwxyz\r\n', 'ABCDEFGHIJK'])
data = 'abc\r\nThis line is broken by the buffer length.\r\nFoo bar baz'
test_stream = StringIO(data)
lines = list(wsgi.make_line_iter(test_stream, limit=len(data), buffer_size=24))
- assert lines == ['abc\r\n', 'This line is broken by the buffer length.\r\n', 'Foo bar baz']
+ self.assert_equal(lines, ['abc\r\n', 'This line is broken by the buffer length.\r\n', 'Foo bar baz'])
def suite():

0 comments on commit c53d3fd

Please sign in to comment.