-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Annotate some of the functions and classes. #134
Conversation
The ping, status and query responses have been annotated. Some obvious issues that have been going under the radar due to missing annotations have been fixed
assert latency >= 0 | ||
# # Test keeps failing for me! Unknown fixture | ||
# class TestAsyncMinecraftServer: | ||
# @pytest.mark.asyncio # unknown mark ??? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Authored by thesadru
Jun 15, 2021
Outdated (history rewrite) - original diff
@@ -54,18 +54,19 @@ async def create_server(port, data_expected_to_receive, data_to_respond_with):
await server.wait_closed()
-class TestAsyncMinecraftServer:
- @pytest.mark.asyncio
- async def test_async_ping(self, unused_tcp_port, create_mock_packet_server):
- mock_packet_server = await create_mock_packet_server(
- port=unused_tcp_port,
- data_expected_to_receive=bytearray.fromhex("09010000000001C54246"),
- data_to_respond_with=bytearray.fromhex("0F002F096C6F63616C686F737463DD0109010000000001C54246"),
- )
- minecraft_server = MinecraftServer("localhost", port=unused_tcp_port)
-
- latency = await minecraft_server.async_ping(ping_token=29704774, version=47)
- assert latency >= 0
+# # Test keeps failing for me! Unknown fixture
+# class TestAsyncMinecraftServer:
+# @pytest.mark.asyncio # unknown mark ???
Using tox
instead of pytest
makes it possible to run the test but now it's giving me an actual failure.
==================================================================================================================== FAILURES ====================================================================================================================
____________________________________________________________________________________________________ TestAsyncMinecraftServer.test_async_ping ____________________________________________________________________________________________________
self = <test_server.TestAsyncMinecraftServer object at 0x000001FE1750DE20>, unused_tcp_port = 59313, create_mock_packet_server = <function create_mock_packet_server.<locals>.create_server at 0x000001FE1744E550>
@pytest.mark.asyncio
async def test_async_ping(self, unused_tcp_port, create_mock_packet_server):
mock_packet_server = await create_mock_packet_server(
port=unused_tcp_port,
data_expected_to_receive=bytearray.fromhex("09010000000001C54246"),
data_to_respond_with=bytearray.fromhex("0F002F096C6F63616C686F737463DD0109010000000001C54246"),
)
minecraft_server = MinecraftServer("localhost", port=unused_tcp_port)
> latency = await minecraft_server.async_ping(ping_token=29704774, version=47)
mcstatus\tests\test_server.py:67:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
mcstatus\server.py:94: in async_ping
raise exception
mcstatus\server.py:88: in async_ping
ping = await pinger.test_ping()
mcstatus\pinger.py:95: in test_ping
response = await self.connection.read_buffer()
mcstatus\protocol\connection.py:174: in read_buffer
length = await self.read_varint()
mcstatus\protocol\connection.py:139: in read_varint
part = ord(await self.read(1))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <mcstatus.protocol.connection.TCPAsyncSocketConnection object at 0x000001FE17514190>, length = 1
async def read(self, length):
result = bytearray()
while len(result) < length:
new = await self.reader.read(length - len(result))
if len(new) == 0:
> raise IOError("Server did not respond with any information!")
E OSError: Server did not respond with any information!
mcstatus\protocol\connection.py:264: OSError
-------------------------------------------------------------------------------------------------------------- Captured stdout call --------------------------------------------------------------------------------------------------------------
connection_made
connection_lost
--------------------------------------------------------------------------------------------------------------- Captured log call ----------------------------------------------------------------------------------------------------------------
ERROR asyncio:base_events.py:1738 Exception in callback _ProactorReadPipeTransport._loop_reading(<_OverlappedF...esult=b'\x0f'>)
handle: <Handle _ProactorReadPipeTransport._loop_reading(<_OverlappedF...esult=b'\x0f'>)>
Traceback (most recent call last):
File "c:\program files\python39\lib\asyncio\events.py", line 80, in _run
self._context.run(self._callback, *self._args)
File "c:\program files\python39\lib\asyncio\proactor_events.py", line 318, in _loop_reading
self._data_received(data)
File "c:\program files\python39\lib\asyncio\proactor_events.py", line 269, in _data_received
self._protocol.data_received(data)
File "C:\Users\D\code\thesadru\mcstatus\mcstatus\tests\test_server.py", line 24, in data_received
assert self.data_expected_to_receive in data
AssertionError: assert bytearray(b'\t\x01\x00\x00\x00\x00\x01\xc5BF') in b'\x0f'
+ where bytearray(b'\t\x01\x00\x00\x00\x00\x01\xc5BF') = <test_server.MockProtocolFactory object at 0x000001FE17514F40>.data_expected_to_receive
----------- coverage: platform win32, python 3.9.0-final-0 -----------
Name Stmts Miss Branch BrPart Cover Missing
----------------------------------------------------------------------------------------
mcstatus\__init__.py 1 0 0 0 100%
mcstatus\bedrock_status.py 53 22 0 0 58% 11-13, 24-26, 40-48, 51-64
mcstatus\pinger.py 160 6 60 2 96% 78, 81-82, 85-86, 198
mcstatus\protocol\__init__.py 0 0 0 0 100%
mcstatus\protocol\connection.py 234 72 36 5 66% 24, 29, 134, 140-143, 146-147, 150-153, 156, 159, 162, 165, 168, 171, 175-177, 182-184, 187, 190, 193, 196-202, 205, 208-211, 216-219, 222, 225, 228, 231-234, 237-239, 242-245, 265-266, 272, 283-285, 288, 291, 294, 297-298, 301-303
mcstatus\querier.py 100 2 10 0 98% 108-109
mcstatus\scripts\__init__.py 0 0 0 0 100%
mcstatus\scripts\address_tools.py 13 5 2 1 60% 7-10, 16
mcstatus\scripts\mcstatus.py 58 40 8 1 29% 44, 52, 61-64, 81-106, 115-128, 138
mcstatus\server.py 145 60 28 0 56% 89-90, 128-141, 154-156, 178-198, 211-212, 222, 232-244, 254-266
mcstatus\tests\protocol\test_connection.py 176 34 0 0 81% 209-214, 217-218, 221-222, 225-226, 229-231, 234-237, 240-242, 247-252, 255-256, 259-260, 263, 266-268, 271-273
mcstatus\tests\test_async_pinger.py 53 0 0 0 100%
mcstatus\tests\test_async_querier.py 22 0 0 0 100%
mcstatus\tests\test_async_support.py 18 0 8 0 100%
mcstatus\tests\test_bedrock_status.py 14 0 0 0 100%
mcstatus\tests\test_pinger.py 147 0 0 0 100%
mcstatus\tests\test_querier.py 48 0 0 0 100%
mcstatus\tests\test_server.py 132 5 4 0 96% 25, 30, 33, 36, 68
----------------------------------------------------------------------------------------
TOTAL 1374 246 156 9 81%
============================================================================================================ short test summary info =============================================================================================================
FAILED mcstatus/tests/test_server.py::TestAsyncMinecraftServer::test_async_ping - OSError: Server did not respond with any information!
========================================================================================================= 1 failed, 108 passed in 3.75s ==========================================================================================================
ERROR: InvocationError for command 'C:\Users\D\code\thesadru\mcstatus\.tox\py39\Scripts\pytest.EXE' (exited with code 1)
assert latency >= 0 | ||
# # Test keeps failing for me! Unknown fixture | ||
# class TestAsyncMinecraftServer: | ||
# @pytest.mark.asyncio # unknown mark ??? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Authored by kevinkjt2000
Jun 15, 2021
Outdated (history rewrite) - original diff
@@ -54,18 +54,19 @@ async def create_server(port, data_expected_to_receive, data_to_respond_with):
await server.wait_closed()
-class TestAsyncMinecraftServer:
- @pytest.mark.asyncio
- async def test_async_ping(self, unused_tcp_port, create_mock_packet_server):
- mock_packet_server = await create_mock_packet_server(
- port=unused_tcp_port,
- data_expected_to_receive=bytearray.fromhex("09010000000001C54246"),
- data_to_respond_with=bytearray.fromhex("0F002F096C6F63616C686F737463DD0109010000000001C54246"),
- )
- minecraft_server = MinecraftServer("localhost", port=unused_tcp_port)
-
- latency = await minecraft_server.async_ping(ping_token=29704774, version=47)
- assert latency >= 0
+# # Test keeps failing for me! Unknown fixture
+# class TestAsyncMinecraftServer:
+# @pytest.mark.asyncio # unknown mark ???
Is it only python 3.9.0 that gives the issue? Or do other python versions have similar output? Does updating to the latest bugfix version of 3.9.5 solve the issue? I haven't run the unit tests on Windows in years, so it could also be a platform-specific issue. I'll boot up my Windows box later and see if I can reproduce this too.
assert latency >= 0 | ||
# # Test keeps failing for me! Unknown fixture | ||
# class TestAsyncMinecraftServer: | ||
# @pytest.mark.asyncio # unknown mark ??? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Authored by kevinkjt2000
Jun 15, 2021
Outdated (history rewrite) - original diff
@@ -54,18 +54,19 @@ async def create_server(port, data_expected_to_receive, data_to_respond_with):
await server.wait_closed()
-class TestAsyncMinecraftServer:
- @pytest.mark.asyncio
- async def test_async_ping(self, unused_tcp_port, create_mock_packet_server):
- mock_packet_server = await create_mock_packet_server(
- port=unused_tcp_port,
- data_expected_to_receive=bytearray.fromhex("09010000000001C54246"),
- data_to_respond_with=bytearray.fromhex("0F002F096C6F63616C686F737463DD0109010000000001C54246"),
- )
- minecraft_server = MinecraftServer("localhost", port=unused_tcp_port)
-
- latency = await minecraft_server.async_ping(ping_token=29704774, version=47)
- assert latency >= 0
+# # Test keeps failing for me! Unknown fixture
+# class TestAsyncMinecraftServer:
+# @pytest.mark.asyncio # unknown mark ???
I was able to reproduce this on my Windows machine, so I made a bug #140
Since this project is completely missing annotations and it doesn't seem like it would be getting them any time soon I have just decided to annotate all the classes exposed to the user and some backend ones.