fixing typos and styles

This commit is contained in:
Gabriel Falcao
2011-06-25 23:41:56 -04:00
parent dcfd8c6e75
commit ed5d8c57c7
3 changed files with 21 additions and 11 deletions

View File

@@ -83,13 +83,13 @@ you will need **ONLY** if you decide to contribute to HTTPretty which means you'
* [httplib2](http://code.google.com/p/httplib2/)
* [bolacha](http://github.com/gabrielfalcao/bolacha/)
* [tornado](http://tornadoweb.org/)
* [multiprocessing](http://tornadoweb.org/)
* [multiprocessing](http://code.google.com/p/python-multiprocessing/) **(only needed if you're running python < 2.6)**
## Here is a oneliner
### I know you want it :)
sudo pip install multiprocessing sure nose tornado httplib2 bolacha
pip install -r requirements.txt
# Contributing

View File

@@ -46,9 +46,11 @@ try:
except ImportError:
socks = None
class HTTPrettyError(Exception):
pass
class FakeSockFile(StringIO):
def read(self, amount=None):
amount = amount or self.len
@@ -64,6 +66,7 @@ class FakeSockFile(StringIO):
return ret
class fakesock(object):
class socket(object):
_entry = None
@@ -135,6 +138,7 @@ class fakesock(object):
if entry.method == method:
self._entry = entry
def create_fake_connection(address, timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
s = fakesock.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP)
if timeout is not socket._GLOBAL_DEFAULT_TIMEOUT:
@@ -143,15 +147,20 @@ def create_fake_connection(address, timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
s.connect(address)
return s
def fake_gethostbyname(host):
return host
def fake_gethostname():
return 'localhost'
def fake_getaddrinfo(host, port, family=None, socktype=None, proto=None, flags=None):
def fake_getaddrinfo(
host, port, family=None, socktype=None, proto=None, flags=None):
return [(2, 1, 6, '', (host, port))]
STATUSES = {
100: "Continue",
101: "Switching Protocols",
@@ -195,6 +204,7 @@ STATUSES = {
505: "HTTP Version not supported",
}
class Entry(object):
def __init__(self, method, uri, body, adding_headers=None, forcing_headers=None, status=200, **headers):
self.method = method

View File

@@ -29,16 +29,16 @@ import httplib2
from sure import *
from httpretty import HTTPretty
def setup(context):
def prepare(context, now):
HTTPretty.enable()
context.http = httplib2.Http()
def teardown(context):
def and_clear(context, now):
HTTPretty.enable()
context.http = httplib2.Http()
@within(two=microseconds)
@that_with_context(setup, teardown)
@that_with_context(prepare, and_clear)
def test_httpretty_should_mock_a_simple_get_with_httplib2_read(context, now):
u"HTTPretty should mock a simple GET with httplib2.context.http"
@@ -49,7 +49,7 @@ def test_httpretty_should_mock_a_simple_get_with_httplib2_read(context, now):
assert that(got).equals('The biggest portal in Brazil')
@within(two=microseconds)
@that_with_context(setup, teardown)
@that_with_context(prepare, and_clear)
def test_httpretty_should_mock_headers_httplib2(context, now):
u"HTTPretty should mock basic headers with httplib2"
@@ -70,7 +70,7 @@ def test_httpretty_should_mock_headers_httplib2(context, now):
@within(two=microseconds)
@that_with_context(setup, teardown)
@that_with_context(prepare, and_clear)
def test_httpretty_should_allow_adding_and_overwritting_httplib2(context, now):
u"HTTPretty should allow adding and overwritting headers with httplib2"
@@ -95,7 +95,7 @@ def test_httpretty_should_allow_adding_and_overwritting_httplib2(context, now):
})
@within(two=microseconds)
@that_with_context(setup, teardown)
@that_with_context(prepare, and_clear)
def test_httpretty_should_allow_forcing_headers_httplib2(context, now):
u"HTTPretty should allow forcing headers with httplib2"
@@ -115,7 +115,7 @@ def test_httpretty_should_allow_forcing_headers_httplib2(context, now):
@within(two=microseconds)
@that_with_context(setup, teardown)
@that_with_context(prepare, and_clear)
def test_httpretty_should_allow_adding_and_overwritting_by_kwargs_u2(context, now):
u"HTTPretty should allow adding and overwritting headers by keyword args " \
"with httplib2"
@@ -140,7 +140,7 @@ def test_httpretty_should_allow_adding_and_overwritting_by_kwargs_u2(context, no
@within(two=microseconds)
@that_with_context(setup, teardown)
@that_with_context(prepare, and_clear)
def test_httpretty_should_support_a_list_of_successive_responses_httplib2(context, now):
u"HTTPretty should support adding a list of successive responses with httplib2"