Skip to content

Commit e38f1a8

Browse files
authored
Test cov (#721)
* nocover for abstract classes * Add event manager test * Assert call args * Sponsored by `Jaxl Innovations Private Limited`
1 parent df7f1c8 commit e38f1a8

File tree

6 files changed

+62
-16
lines changed

6 files changed

+62
-16
lines changed

README.md

+5-7
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,22 @@
44
[![Docker Pulls](https://img.shields.io/docker/pulls/abhinavsingh/proxy.py?style=for-the-badge&color=darkgreen)](https://hub.docker.com/r/abhinavsingh/proxy.py)
55
[![No Dependencies](https://img.shields.io/static/v1?label=dependencies&message=0&style=for-the-badge&color=darkgreen)](https://github.com/abhinavsingh/proxy.py)
66
[![Gitter](https://img.shields.io/gitter/room/abhinavsingh/proxy.py?style=for-the-badge&color=darkgreen)](https://gitter.im/proxy-py/community)
7-
[![License](https://img.shields.io/github/license/abhinavsingh/proxy.py?style=for-the-badge&color=darkgreen)](https://opensource.org/licenses/BSD-3-Clause)
7+
[![License](https://img.shields.io/github/license/abhinavsingh/proxy.py?style=for-the-badge&color=darkgreen)](https://github.com/abhinavsingh/proxy.py/blob/develop/LICENSE)
88

99
[![Tested With MacOS, Ubuntu, Windows, Android, Android Emulator, iOS, iOS Simulator](https://img.shields.io/static/v1?label=tested%20with&message=mac%20OS%20%F0%9F%92%BB%20%7C%20Ubuntu%20%F0%9F%96%A5%20%7C%20Windows%20%F0%9F%92%BB&color=darkgreen&style=for-the-badge)](https://abhinavsingh.com/proxy-py-a-lightweight-single-file-http-proxy-server-in-python/)
1010
[![Android, Android Emulator](https://img.shields.io/static/v1?label=tested%20with&message=Android%20%F0%9F%93%B1%20%7C%20Android%20Emulator%20%F0%9F%93%B1&color=darkgreen&style=for-the-badge)](https://abhinavsingh.com/proxy-py-a-lightweight-single-file-http-proxy-server-in-python/)
1111
[![iOS, iOS Simulator](https://img.shields.io/static/v1?label=tested%20with&message=iOS%20%F0%9F%93%B1%20%7C%20iOS%20Simulator%20%F0%9F%93%B1&color=darkgreen&style=for-the-badge)](https://abhinavsingh.com/proxy-py-a-lightweight-single-file-http-proxy-server-in-python/)
1212

13-
<!--
14-
[![Maintenance](https://img.shields.io/static/v1?label=maintained%3F&message=yes&color=darkgreen)](https://gitHub.com/abhinavsingh/proxy.py/graphs/commit-activity)
15-
[![Ask Me Anything](https://img.shields.io/static/v1?label=need%20help%3F&message=ask&color=darkgreen)](https://twitter.com/imoracle)
16-
[![Contributions Welcome](https://img.shields.io/static/v1?label=contributions&message=welcome%20%F0%9F%91%8D&color=darkgreen)](https://github.com/abhinavsingh/proxy.py/issues)
17-
-->
18-
1913
[![lib](https://github.com/abhinavsingh/proxy.py/actions/workflows/test-library.yml/badge.svg)](https://github.com/abhinavsingh/proxy.py/actions/workflows/test-library.yml)
2014
[![docker](https://github.com/abhinavsingh/proxy.py/actions/workflows/test-docker.yml/badge.svg)](https://github.com/abhinavsingh/proxy.py/actions/workflows/test-docker.yml)
2115
[![dashboard](https://github.com/abhinavsingh/proxy.py/actions/workflows/test-dashboard.yml/badge.svg)](https://github.com/abhinavsingh/proxy.py/actions/workflows/test-dashboard.yml)
2216
[![brew](https://github.com/abhinavsingh/proxy.py/actions/workflows/test-brew.yml/badge.svg)](https://github.com/abhinavsingh/proxy.py/actions/workflows/test-brew.yml)
2317
[![CodeQL](https://github.com/abhinavsingh/proxy.py/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/abhinavsingh/proxy.py/actions/workflows/codeql-analysis.yml)
2418

19+
[![Contributions Welcome](https://img.shields.io/static/v1?label=Contributions&message=Welcome%20%F0%9F%91%8D&color=darkgreen)](https://github.com/abhinavsingh/proxy.py/issues)
20+
[![Need Help](https://img.shields.io/static/v1?label=Need%20Help%3F&message=Ask&color=darkgreen)](https://twitter.com/imoracle)
21+
[![Sponsored by Jaxl Innovations Private Limited](https://img.shields.io/static/v1?label=Sponsored%20By&message=Jaxl%20Innovations%20Private%20Limited&color=darkgreen)](https://github.com/jaxl-innovations-private-limited)
22+
2523
[![pypi version](https://img.shields.io/pypi/v/proxy.py)](https://pypi.org/project/proxy.py/)
2624
[![Python 3.x](https://img.shields.io/static/v1?label=Python&message=3.6%20%7C%203.7%20%7C%203.8%20%7C%203.9%20%7C%203.10&color=blue)](https://www.python.org/)
2725
[![Checked with mypy](https://img.shields.io/static/v1?label=MyPy&message=checked&color=blue)](http://mypy-lang.org/)

proxy/core/base/tcp_server.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class BaseTcpServerHandler(Work):
4545
def __init__(self, *args: Any, **kwargs: Any) -> None:
4646
super().__init__(*args, **kwargs)
4747
self.must_flush_before_shutdown = False
48-
if self.flags.unix_socket_path:
48+
if self.flags.unix_socket_path: # pragma: no cover
4949
logger.debug(
5050
'Connection accepted from {0}'.format(self.work.address),
5151
)

proxy/dashboard/plugin.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,20 @@ def __init__(
3535
@abstractmethod
3636
def methods(self) -> List[str]:
3737
"""Return list of methods that this plugin will handle."""
38-
pass
38+
pass # pragma: no cover
3939

4040
def connected(self) -> None:
4141
"""Invoked when client websocket handshake finishes."""
42-
pass
42+
pass # pragma: no cover
4343

4444
@abstractmethod
4545
def handle_message(self, message: Dict[str, Any]) -> None:
4646
"""Handle messages for registered methods."""
47-
pass
47+
pass # pragma: no cover
4848

4949
def disconnected(self) -> None:
5050
"""Invoked when client websocket connection gets closed."""
51-
pass
51+
pass # pragma: no cover
5252

5353
def reply(self, data: Dict[str, Any]) -> None:
5454
self.client.queue(

proxy/http/websocket/client.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ def upgrade(self) -> None:
7474
assert WebsocketFrame.key_to_accept(key) == accept
7575

7676
def ping(self, data: Optional[bytes] = None) -> None:
77-
pass
77+
pass # pragma: no cover
7878

7979
def pong(self, data: Optional[bytes] = None) -> None:
80-
pass
80+
pass # pragma: no cover
8181

8282
def shutdown(self, _data: Optional[bytes] = None) -> None:
8383
"""Closes connection with the server."""

proxy/plugin/cloudflare_dns.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
try:
1414
import httpx
15-
except ImportError:
15+
except ImportError: # pragma: no cover
1616
pass
1717

1818
from typing import Optional, Tuple
@@ -75,7 +75,9 @@ def resolve_dns(self, host: str, port: int) -> Tuple[Optional[str], Optional[Tup
7575
return answers[0]['data'], None
7676
except Exception as e:
7777
logger.info(
78-
'Unable to resolve DNS-over-HTTPS for host {0} : {1}'.format(host, str(e)),
78+
'Unable to resolve DNS-over-HTTPS for host {0} : {1}'.format(
79+
host, str(e),
80+
),
7981
)
8082
return None, None
8183

tests/core/test_event_manager.py

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
proxy.py
4+
~~~~~~~~
5+
⚡⚡⚡ Fast, Lightweight, Pluggable, TLS interception capable proxy server focused on
6+
Network monitoring, controls & Application development, testing, debugging.
7+
8+
:copyright: (c) 2013-present by Abhinav Singh and contributors.
9+
:license: BSD, see LICENSE for more details.
10+
"""
11+
import unittest
12+
13+
from unittest import mock
14+
15+
from proxy.core.event import EventManager
16+
17+
18+
class TestEventManager(unittest.TestCase):
19+
20+
@mock.patch('proxy.core.event.manager.EventQueue')
21+
@mock.patch('proxy.core.event.manager.EventDispatcher')
22+
@mock.patch('proxy.core.event.manager.multiprocessing.Queue')
23+
@mock.patch('proxy.core.event.manager.threading.Event')
24+
@mock.patch('proxy.core.event.manager.threading.Thread')
25+
def test_setup_and_teardown(
26+
self,
27+
mock_thread: mock.Mock,
28+
mock_event: mock.Mock,
29+
mock_queue: mock.Mock,
30+
mock_dispatcher: mock.Mock,
31+
mock_event_queue: mock.Mock,
32+
) -> None:
33+
with EventManager() as _:
34+
mock_queue.assert_called_once()
35+
mock_event.assert_called_once()
36+
mock_thread.assert_called_once_with(
37+
target=mock_dispatcher.return_value.run,
38+
)
39+
mock_thread.return_value.start.assert_called_once()
40+
mock_event_queue.assert_called_once_with(mock_queue.return_value)
41+
mock_dispatcher.assert_called_once_with(
42+
shutdown=mock_event.return_value,
43+
event_queue=mock_event_queue.return_value,
44+
)
45+
mock_event.return_value.set.assert_called_once()
46+
mock_thread.return_value.join.assert_called_once()

0 commit comments

Comments
 (0)