winloop 0.1.4__cp38-cp38-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tests/__init__.py +0 -0
- tests/__main__.py +16 -0
- tests/test_aiodns.py +40 -0
- tests/test_aiohttp.py +133 -0
- tests/test_aiomultiprocess.py +60 -0
- tests/test_base.py +972 -0
- tests/test_context.py +791 -0
- tests/test_cython.py +35 -0
- tests/test_dealloc.py +61 -0
- tests/test_dns.py +256 -0
- tests/test_executors.py +47 -0
- tests/test_libuv_api.py +23 -0
- tests/test_process_spawning.py +115 -0
- tests/test_regr1.py +120 -0
- tests/test_runner.py +39 -0
- tests/test_sourcecode.py +73 -0
- tests/test_testbase.py +51 -0
- tests/test_udp.py +414 -0
- tests/test_unix.py +700 -0
- winloop/__init__.py +180 -0
- winloop/_noop.py +3 -0
- winloop/_testbase.py +554 -0
- winloop/_version.py +13 -0
- winloop/includes/__init__.py +23 -0
- winloop/loop.c +214929 -0
- winloop/loop.cp38-win_amd64.pyd +0 -0
- winloop/loop.pyi +297 -0
- winloop-0.1.4.dist-info/LICENSE-APACHE +203 -0
- winloop-0.1.4.dist-info/LICENSE-MIT +21 -0
- winloop-0.1.4.dist-info/METADATA +292 -0
- winloop-0.1.4.dist-info/RECORD +33 -0
- winloop-0.1.4.dist-info/WHEEL +5 -0
- winloop-0.1.4.dist-info/top_level.txt +2 -0
tests/__init__.py
ADDED
|
File without changes
|
tests/__main__.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import os.path
|
|
2
|
+
import sys
|
|
3
|
+
import unittest
|
|
4
|
+
import unittest.runner
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def suite():
|
|
8
|
+
test_loader = unittest.TestLoader()
|
|
9
|
+
test_suite = test_loader.discover(os.path.dirname(__file__))
|
|
10
|
+
return test_suite
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
if __name__ == '__main__':
|
|
14
|
+
runner = unittest.runner.TextTestRunner()
|
|
15
|
+
result = runner.run(suite())
|
|
16
|
+
sys.exit(not result.wasSuccessful())
|
tests/test_aiodns.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# NOTE: I forked the aiodns Repository you will have to use that for now
|
|
2
|
+
# or wait for the pull request I recently made to go through:
|
|
3
|
+
# https://github.com/saghul/aiodns/pull/116
|
|
4
|
+
|
|
5
|
+
try:
|
|
6
|
+
import aiodns
|
|
7
|
+
except ImportError:
|
|
8
|
+
skip_tests = True
|
|
9
|
+
else:
|
|
10
|
+
skip_tests = False
|
|
11
|
+
|
|
12
|
+
import unittest
|
|
13
|
+
|
|
14
|
+
from winloop import _testbase as tb
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class _TestAiodns:
|
|
18
|
+
def test_dns_query(self):
|
|
19
|
+
# This is not allowed to fail...
|
|
20
|
+
resolver = aiodns.DNSResolver(loop=self.loop)
|
|
21
|
+
|
|
22
|
+
async def test():
|
|
23
|
+
async def query(name, query_type):
|
|
24
|
+
return await resolver.query(name, query_type)
|
|
25
|
+
await query('google.com', 'A')
|
|
26
|
+
await query('httpbin.org', 'A')
|
|
27
|
+
await query('example.com', 'A')
|
|
28
|
+
|
|
29
|
+
self.loop.run_until_complete(test())
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@unittest.skipIf(skip_tests, "no aiodns module")
|
|
33
|
+
class Test_UV_Aiodns(_TestAiodns, tb.UVTestCase):
|
|
34
|
+
pass
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@unittest.skip("aiodns needs a SelectorEventLoop on Windows."
|
|
38
|
+
" See more: https://github.com/saghul/aiodns/issues/86")
|
|
39
|
+
class Test_AIO_Aiodns(_TestAiodns, tb.AIOTestCase):
|
|
40
|
+
pass
|
tests/test_aiohttp.py
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
try:
|
|
2
|
+
import aiohttp
|
|
3
|
+
import aiohttp.web
|
|
4
|
+
except ImportError:
|
|
5
|
+
skip_tests = True
|
|
6
|
+
else:
|
|
7
|
+
skip_tests = False
|
|
8
|
+
|
|
9
|
+
import asyncio
|
|
10
|
+
import sys
|
|
11
|
+
import unittest
|
|
12
|
+
import weakref
|
|
13
|
+
|
|
14
|
+
from winloop import _testbase as tb
|
|
15
|
+
|
|
16
|
+
# TODO: Fix or patch DeprecationWarning
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class _TestAioHTTP:
|
|
20
|
+
|
|
21
|
+
def test_aiohttp_basic_1(self):
|
|
22
|
+
|
|
23
|
+
PAYLOAD = '<h1>It Works!</h1>' * 10000
|
|
24
|
+
|
|
25
|
+
async def on_request(request):
|
|
26
|
+
return aiohttp.web.Response(text=PAYLOAD)
|
|
27
|
+
|
|
28
|
+
asyncio.set_event_loop(self.loop)
|
|
29
|
+
app = aiohttp.web.Application()
|
|
30
|
+
app.router.add_get('/', on_request)
|
|
31
|
+
|
|
32
|
+
runner = aiohttp.web.AppRunner(app)
|
|
33
|
+
self.loop.run_until_complete(runner.setup())
|
|
34
|
+
site = aiohttp.web.TCPSite(runner, '0.0.0.0', '0')
|
|
35
|
+
self.loop.run_until_complete(site.start())
|
|
36
|
+
port = site._server.sockets[0].getsockname()[1]
|
|
37
|
+
|
|
38
|
+
async def test():
|
|
39
|
+
# Make sure we're using the correct event loop.
|
|
40
|
+
self.assertIs(asyncio.get_event_loop(), self.loop)
|
|
41
|
+
|
|
42
|
+
for addr in (('localhost', port),
|
|
43
|
+
('127.0.0.1', port)):
|
|
44
|
+
async with aiohttp.ClientSession() as client:
|
|
45
|
+
async with client.get('http://{}:{}'.format(*addr)) as r:
|
|
46
|
+
self.assertEqual(r.status, 200)
|
|
47
|
+
result = await r.text()
|
|
48
|
+
self.assertEqual(result, PAYLOAD)
|
|
49
|
+
|
|
50
|
+
self.loop.run_until_complete(test())
|
|
51
|
+
self.loop.run_until_complete(runner.cleanup())
|
|
52
|
+
|
|
53
|
+
def test_aiohttp_graceful_shutdown(self):
|
|
54
|
+
# NOTE: This Might Already be solved I haven't checked yet - Vizonex
|
|
55
|
+
if self.implementation == 'asyncio' and sys.version_info >= (3, 12, 0):
|
|
56
|
+
# In Python 3.12.0, asyncio.Server.wait_closed() waits for all
|
|
57
|
+
# existing connections to complete, before aiohttp sends
|
|
58
|
+
# on_shutdown signals.
|
|
59
|
+
# https://github.com/aio-libs/aiohttp/issues/7675#issuecomment-1752143748
|
|
60
|
+
# https://github.com/python/cpython/pull/98582
|
|
61
|
+
raise unittest.SkipTest('bug in aiohttp: #7675')
|
|
62
|
+
|
|
63
|
+
async def websocket_handler(request):
|
|
64
|
+
ws = aiohttp.web.WebSocketResponse()
|
|
65
|
+
await ws.prepare(request)
|
|
66
|
+
request.app['websockets'].add(ws)
|
|
67
|
+
try:
|
|
68
|
+
async for msg in ws:
|
|
69
|
+
await ws.send_str(msg.data)
|
|
70
|
+
finally:
|
|
71
|
+
request.app['websockets'].discard(ws)
|
|
72
|
+
return ws
|
|
73
|
+
|
|
74
|
+
async def on_shutdown(app):
|
|
75
|
+
for ws in set(app['websockets']):
|
|
76
|
+
await ws.close(
|
|
77
|
+
code=aiohttp.WSCloseCode.GOING_AWAY,
|
|
78
|
+
message='Server shutdown')
|
|
79
|
+
|
|
80
|
+
asyncio.set_event_loop(self.loop)
|
|
81
|
+
app = aiohttp.web.Application()
|
|
82
|
+
app.router.add_get('/', websocket_handler)
|
|
83
|
+
app.on_shutdown.append(on_shutdown)
|
|
84
|
+
app['websockets'] = weakref.WeakSet()
|
|
85
|
+
|
|
86
|
+
runner = aiohttp.web.AppRunner(app)
|
|
87
|
+
self.loop.run_until_complete(runner.setup())
|
|
88
|
+
site = aiohttp.web.TCPSite(
|
|
89
|
+
runner,
|
|
90
|
+
'0.0.0.0',
|
|
91
|
+
0,
|
|
92
|
+
# https://github.com/aio-libs/aiohttp/pull/7188
|
|
93
|
+
shutdown_timeout=0.1,
|
|
94
|
+
)
|
|
95
|
+
self.loop.run_until_complete(site.start())
|
|
96
|
+
port = site._server.sockets[0].getsockname()[1]
|
|
97
|
+
|
|
98
|
+
async def client():
|
|
99
|
+
async with aiohttp.ClientSession() as client:
|
|
100
|
+
async with client.ws_connect(
|
|
101
|
+
'http://127.0.0.1:{}'.format(port)) as ws:
|
|
102
|
+
await ws.send_str("hello")
|
|
103
|
+
async for msg in ws:
|
|
104
|
+
assert msg.data == "hello"
|
|
105
|
+
|
|
106
|
+
client_task = asyncio.ensure_future(client())
|
|
107
|
+
|
|
108
|
+
async def stop():
|
|
109
|
+
await asyncio.sleep(0.1)
|
|
110
|
+
try:
|
|
111
|
+
await asyncio.wait_for(runner.cleanup(), timeout=0.5)
|
|
112
|
+
finally:
|
|
113
|
+
try:
|
|
114
|
+
client_task.cancel()
|
|
115
|
+
await client_task
|
|
116
|
+
except asyncio.CancelledError:
|
|
117
|
+
pass
|
|
118
|
+
|
|
119
|
+
self.loop.run_until_complete(stop())
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
@unittest.skipIf(skip_tests, "no aiohttp module")
|
|
123
|
+
class Test_UV_AioHTTP(_TestAioHTTP, tb.UVTestCase):
|
|
124
|
+
pass
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
@unittest.skipIf(skip_tests, "no aiohttp module")
|
|
128
|
+
class Test_AIO_AioHTTP(_TestAioHTTP, tb.AIOTestCase):
|
|
129
|
+
pass
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
if __name__ == "__main__":
|
|
133
|
+
unittest.main()
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
try:
|
|
2
|
+
import aiomultiprocess
|
|
3
|
+
import multiprocessing
|
|
4
|
+
except ImportError:
|
|
5
|
+
skip_tests = True
|
|
6
|
+
else:
|
|
7
|
+
skip_tests = False
|
|
8
|
+
import unittest
|
|
9
|
+
import winloop
|
|
10
|
+
import random
|
|
11
|
+
import asyncio
|
|
12
|
+
from winloop import _testbase as tb
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
async def test_func(sleep: float):
|
|
16
|
+
return await asyncio.sleep(sleep)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def my_map():
|
|
20
|
+
return [random.uniform(0.005, 1) for _ in range(7)]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class _Test_Multiprocessing():
|
|
24
|
+
"""Used for Testing aiomultiprocessing"""
|
|
25
|
+
|
|
26
|
+
def test_proccess_spawning(self):
|
|
27
|
+
|
|
28
|
+
# See:
|
|
29
|
+
# https://github.com/Vizonex/Winloop/issues/11#issuecomment-1922659521
|
|
30
|
+
self.processes = set()
|
|
31
|
+
# There must be at least 2 pids setup for this to be correctly ran...
|
|
32
|
+
total_proccesses = 2
|
|
33
|
+
|
|
34
|
+
async def test():
|
|
35
|
+
async with aiomultiprocess.Pool(total_proccesses) as pool:
|
|
36
|
+
self.processes.update(p.pid for p in pool.processes)
|
|
37
|
+
await pool.map(test_func, my_map())
|
|
38
|
+
await asyncio.sleep(0.005)
|
|
39
|
+
self.assertEqual(len(self.processes), total_proccesses)
|
|
40
|
+
|
|
41
|
+
self.loop.run_until_complete(test())
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@unittest.skipIf(skip_tests, "no aiomultiproccess module")
|
|
45
|
+
class Test_UV_AioMultiprocess(_Test_Multiprocessing, tb.UVTestCase):
|
|
46
|
+
pass
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@unittest.skipIf(skip_tests, "no aiomultiproccess module")
|
|
50
|
+
class Test_AIO_AioMultiprocess(_Test_Multiprocessing, tb.AIOTestCase):
|
|
51
|
+
pass
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
if __name__ == "__main__":
|
|
55
|
+
# I have confirmed that multiproccessing is supported so no need
|
|
56
|
+
# to continue with trying... - Vizonex...
|
|
57
|
+
multiprocessing.freeze_support()
|
|
58
|
+
# aiomultiprocess.set_start_method("spawn")
|
|
59
|
+
winloop.install()
|
|
60
|
+
unittest.main()
|