Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
omit =
*.egg/*
*site-packages*
*compat.py

[report]
exclude_lines =
Expand Down
2 changes: 1 addition & 1 deletion mocket/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def shsplit(s):
return shlex.split(s)


def do_the_magic(lib_magic, body):
def do_the_magic(lib_magic, body): # pragma: no cover
if hasattr(lib_magic, "from_buffer"):
# PyPI python-magic
return lib_magic.from_buffer(body, mime=True)
Expand Down
5 changes: 1 addition & 4 deletions mocket/mocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,7 @@ def __init__(
self._truesocket_recording_dir = None
self.kwargs = kwargs

def __unicode__(self): # pragma: no cover
return str(self)

def __str__(self): # pragma: no cover
def __str__(self):
return "({})(family={} type={} protocol={})".format(
self.__class__.__name__, self.family, self.type, self.proto
)
Expand Down
5 changes: 2 additions & 3 deletions mocket/plugins/httpretty/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,9 @@ def __init__(self):

def __getattr__(self, name):
if name == "last_request":
last_request = getattr(Mocket, "last_request")()
return last_request
return Mocket.last_request()
if name == "latest_requests":
return getattr(Mocket, "_requests")
return Mocket._requests
return getattr(Entry, name)


Expand Down
2 changes: 1 addition & 1 deletion mocket/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ def hexload(string):
def get_mocketize(wrapper_):
import decorator

if decorator.__version__ < "5":
if decorator.__version__ < "5": # pragma: no cover
return decorator.decorator(wrapper_)
return decorator.decorator(wrapper_, kwsyntax=True)
1 change: 0 additions & 1 deletion run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ def main(args=None):
if not any(a for a in args[1:] if not a.startswith("-")):
args.append("tests/main")
args.append("mocket")
args.append("tests/tests35")

if major == 3 and minor >= 7:
args.append("tests/tests37")
Expand Down
3 changes: 0 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import io
import os
import sys

from setuptools import find_packages, setup

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

major, minor = sys.version_info[:2]

install_requires = [
line
for line in io.open(
Expand Down
12 changes: 0 additions & 12 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +0,0 @@
from __future__ import unicode_literals
import sys

PY2 = sys.version_info[0] == 2

if PY2:
from urllib2 import urlopen, HTTPError
from urllib import urlencode
else:
from urllib.request import urlopen
from urllib.parse import urlencode
from urllib.error import HTTPError
6 changes: 3 additions & 3 deletions tests/main/test_http.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import io
import json
import os
import socket
import tempfile
import time
from unittest import TestCase
from urllib.error import HTTPError
from urllib.parse import urlencode
from urllib.request import urlopen

import mock
import pytest
import requests

from mocket import Mocket, mocketize
from mocket.mockhttp import Entry, Response
from tests import HTTPError, urlencode, urlopen

recording_directory = tempfile.mkdtemp()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
class AioHttpEntryTestCase(TestCase):
@mocketize
def test_http_session(self):
url = 'http://httpbin.org/ip'
url = "http://httpbin.org/ip"
body = "asd" * 100
Entry.single_register(Entry.GET, url, body=body, status=404)
Entry.single_register(Entry.POST, url, body=body*2, status=201)
Entry.single_register(Entry.POST, url, body=body * 2, status=201)

async def main(l):
async with aiohttp.ClientSession(loop=l) as session:
async def main(_loop):
async with aiohttp.ClientSession(loop=_loop) as session:
with async_timeout.timeout(3):
async with session.get(url) as get_response:
assert get_response.status == 404
Expand All @@ -29,7 +29,7 @@ async def main(l):
async with session.post(url, data=body * 6) as post_response:
assert post_response.status == 201
assert await post_response.text() == body * 2
assert Mocket.last_request().method == 'POST'
assert Mocket.last_request().method == "POST"
assert Mocket.last_request().body == body * 6

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

@mocketize
def test_https_session(self):
url = 'https://httpbin.org/ip'
url = "https://httpbin.org/ip"
body = "asd" * 100
Entry.single_register(Entry.GET, url, body=body, status=404)
Entry.single_register(Entry.POST, url, body=body*2, status=201)
Entry.single_register(Entry.POST, url, body=body * 2, status=201)

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

@httprettified
def test_httprettish_session(self):
url = 'https://httpbin.org/ip'
url = "https://httpbin.org/ip"
HTTPretty.register_uri(
HTTPretty.GET,
url,
body=json.dumps(dict(origin='127.0.0.1')),
body=json.dumps(dict(origin="127.0.0.1")),
)

async def main(l):
async with aiohttp.ClientSession(loop=l) as session:
async def main(_loop):
async with aiohttp.ClientSession(loop=_loop) as session:
with async_timeout.timeout(3):
async with session.get(url) as get_response:
assert get_response.status == 200
assert await get_response.text() == '{"origin": "127.0.0.1"}'

loop = asyncio.get_event_loop()
loop.set_debug(True)
loop.run_until_complete(main(loop))
5 changes: 3 additions & 2 deletions tests/main/test_https.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import json
import os
import tempfile
from urllib.request import urlopen

import pytest
import requests

from mocket import Mocket, Mocketizer, mocketize
from mocket.mockhttp import Entry
from tests import urlopen


@pytest.fixture
Expand Down Expand Up @@ -51,7 +51,8 @@ def test_truesendall_with_recording_https():
assert resp.status_code == 200

dump_filename = os.path.join(
Mocket.get_truesocket_recording_dir(), Mocket.get_namespace() + ".json",
Mocket.get_truesocket_recording_dir(),
Mocket.get_namespace() + ".json",
)
with io.open(dump_filename) as f:
responses = json.load(f)
Expand Down
10 changes: 7 additions & 3 deletions tests/main/test_mocket.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import unicode_literals

import os
import io
import os
import socket
from unittest import TestCase
from unittest.mock import patch
Expand Down Expand Up @@ -54,7 +54,10 @@ def test_register(self):
Mocket.register(entry_1, entry_2, entry_3)
self.assertEqual(
Mocket._entries,
{("localhost", 80): [entry_1, entry_2], ("localhost", 8080): [entry_3],},
{
("localhost", 80): [entry_1, entry_2],
("localhost", 8080): [entry_3],
},
)

def test_collect(self):
Expand Down Expand Up @@ -138,6 +141,7 @@ def test_socket_as_context_manager(self):
_so.sendall(encode_to_bytes("Whatever..."))
data = _so.recv(4096)
self.assertEqual(data, encode_to_bytes("Show me.\r\n"))
self.assertEqual(str(_so), "(MocketSocket)(family=2 type=1 protocol=0)")


class MocketizeTestCase(TestCase):
Expand Down Expand Up @@ -172,5 +176,5 @@ def test_mocketize_with_fixture(fixture):
def test_patch(
method_patch,
):
method_patch.return_value = 'foo'
method_patch.return_value = "foo"
assert os.getcwd() == "foo"
1 change: 0 additions & 1 deletion tests/tests35/README.txt

This file was deleted.

Empty file removed tests/tests35/__init__.py
Empty file.