Skip to content

Commit 2f8ee9a

Browse files
authored
Some cleaning/refactoring (#168)
* Some cleaning/refactoring. * Improving coverage.
1 parent 9faa252 commit 2f8ee9a

File tree

14 files changed

+32
-48
lines changed

14 files changed

+32
-48
lines changed

.coveragerc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
omit =
33
*.egg/*
44
*site-packages*
5-
*compat.py
65

76
[report]
87
exclude_lines =

mocket/compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def shsplit(s):
2626
return shlex.split(s)
2727

2828

29-
def do_the_magic(lib_magic, body):
29+
def do_the_magic(lib_magic, body): # pragma: no cover
3030
if hasattr(lib_magic, "from_buffer"):
3131
# PyPI python-magic
3232
return lib_magic.from_buffer(body, mime=True)

mocket/mocket.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,7 @@ def __init__(
158158
self._truesocket_recording_dir = None
159159
self.kwargs = kwargs
160160

161-
def __unicode__(self): # pragma: no cover
162-
return str(self)
163-
164-
def __str__(self): # pragma: no cover
161+
def __str__(self):
165162
return "({})(family={} type={} protocol={})".format(
166163
self.__class__.__name__, self.family, self.type, self.proto
167164
)

mocket/plugins/httpretty/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,9 @@ def __init__(self):
107107

108108
def __getattr__(self, name):
109109
if name == "last_request":
110-
last_request = getattr(Mocket, "last_request")()
111-
return last_request
110+
return Mocket.last_request()
112111
if name == "latest_requests":
113-
return getattr(Mocket, "_requests")
112+
return Mocket._requests
114113
return getattr(Entry, name)
115114

116115

mocket/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ def hexload(string):
3939
def get_mocketize(wrapper_):
4040
import decorator
4141

42-
if decorator.__version__ < "5":
42+
if decorator.__version__ < "5": # pragma: no cover
4343
return decorator.decorator(wrapper_)
4444
return decorator.decorator(wrapper_, kwsyntax=True)

run_tests.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ def main(args=None):
1313
if not any(a for a in args[1:] if not a.startswith("-")):
1414
args.append("tests/main")
1515
args.append("mocket")
16-
args.append("tests/tests35")
1716

1817
if major == 3 and minor >= 7:
1918
args.append("tests/tests37")

setup.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import io
22
import os
3-
import sys
43

54
from setuptools import find_packages, setup
65

76
os.environ.setdefault("PIPENV_SKIP_LOCK", "1")
87

9-
major, minor = sys.version_info[:2]
10-
118
install_requires = [
129
line
1310
for line in io.open(

tests/__init__.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +0,0 @@
1-
from __future__ import unicode_literals
2-
import sys
3-
4-
PY2 = sys.version_info[0] == 2
5-
6-
if PY2:
7-
from urllib2 import urlopen, HTTPError
8-
from urllib import urlencode
9-
else:
10-
from urllib.request import urlopen
11-
from urllib.parse import urlencode
12-
from urllib.error import HTTPError

tests/main/test_http.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# -*- coding: utf-8 -*-
2-
from __future__ import unicode_literals
3-
42
import io
53
import json
64
import os
75
import socket
86
import tempfile
97
import time
108
from unittest import TestCase
9+
from urllib.error import HTTPError
10+
from urllib.parse import urlencode
11+
from urllib.request import urlopen
1112

1213
import mock
1314
import pytest
1415
import requests
1516

1617
from mocket import Mocket, mocketize
1718
from mocket.mockhttp import Entry, Response
18-
from tests import HTTPError, urlencode, urlopen
1919

2020
recording_directory = tempfile.mkdtemp()
2121

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
class AioHttpEntryTestCase(TestCase):
1414
@mocketize
1515
def test_http_session(self):
16-
url = 'http://httpbin.org/ip'
16+
url = "http://httpbin.org/ip"
1717
body = "asd" * 100
1818
Entry.single_register(Entry.GET, url, body=body, status=404)
19-
Entry.single_register(Entry.POST, url, body=body*2, status=201)
19+
Entry.single_register(Entry.POST, url, body=body * 2, status=201)
2020

21-
async def main(l):
22-
async with aiohttp.ClientSession(loop=l) as session:
21+
async def main(_loop):
22+
async with aiohttp.ClientSession(loop=_loop) as session:
2323
with async_timeout.timeout(3):
2424
async with session.get(url) as get_response:
2525
assert get_response.status == 404
@@ -29,7 +29,7 @@ async def main(l):
2929
async with session.post(url, data=body * 6) as post_response:
3030
assert post_response.status == 201
3131
assert await post_response.text() == body * 2
32-
assert Mocket.last_request().method == 'POST'
32+
assert Mocket.last_request().method == "POST"
3333
assert Mocket.last_request().body == body * 6
3434

3535
loop = asyncio.get_event_loop()
@@ -39,13 +39,13 @@ async def main(l):
3939

4040
@mocketize
4141
def test_https_session(self):
42-
url = 'https://httpbin.org/ip'
42+
url = "https://httpbin.org/ip"
4343
body = "asd" * 100
4444
Entry.single_register(Entry.GET, url, body=body, status=404)
45-
Entry.single_register(Entry.POST, url, body=body*2, status=201)
45+
Entry.single_register(Entry.POST, url, body=body * 2, status=201)
4646

47-
async def main(l):
48-
async with aiohttp.ClientSession(loop=l) as session:
47+
async def main(_loop):
48+
async with aiohttp.ClientSession(loop=_loop) as session:
4949
with async_timeout.timeout(3):
5050
async with session.get(url) as get_response:
5151
assert get_response.status == 404
@@ -63,19 +63,20 @@ async def main(l):
6363

6464
@httprettified
6565
def test_httprettish_session(self):
66-
url = 'https://httpbin.org/ip'
66+
url = "https://httpbin.org/ip"
6767
HTTPretty.register_uri(
6868
HTTPretty.GET,
6969
url,
70-
body=json.dumps(dict(origin='127.0.0.1')),
70+
body=json.dumps(dict(origin="127.0.0.1")),
7171
)
7272

73-
async def main(l):
74-
async with aiohttp.ClientSession(loop=l) as session:
73+
async def main(_loop):
74+
async with aiohttp.ClientSession(loop=_loop) as session:
7575
with async_timeout.timeout(3):
7676
async with session.get(url) as get_response:
7777
assert get_response.status == 200
7878
assert await get_response.text() == '{"origin": "127.0.0.1"}'
79+
7980
loop = asyncio.get_event_loop()
8081
loop.set_debug(True)
8182
loop.run_until_complete(main(loop))

0 commit comments

Comments
 (0)