Skip to content

Commit b324b50

Browse files
[MERGE] Add pragma coverage annotations to test files
* tweaked coverage so it won't complain about test-code for project-wide stats as much. - [x] Contributes to #365 * **Chores** * Updated test files to exclude certain functions and code branches from coverage analysis. No changes to application behavior or test logic.
2 parents 19d38db + 7c0c735 commit b324b50

File tree

2 files changed

+33
-33
lines changed

2 files changed

+33
-33
lines changed

tests/MulticastUDPClient.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ class MCastClient(object): # skipcq: PYL-R0205
179179
"""The source port for the client."""
180180

181181
# skipcq: TCV-002
182-
def __init__(self, *args, **kwargs):
182+
def __init__(self, *args, **kwargs) -> None: # pragma: no cover
183183
"""
184184
Initialize a MCastClient object with optional group address and source port.
185185
@@ -240,11 +240,11 @@ def __init__(self, *args, **kwargs):
240240
241241
"""
242242
# skipcq: TCV-002
243-
if str("grp_addr") in kwargs:
243+
if "grp_addr" in kwargs: # pragma: no branch
244244
self._group_addr = kwargs.get("grp_addr", None) # skipcq: PTC-W0039 - ensure None
245-
if str("src_port") in kwargs:
245+
if "src_port" in kwargs: # pragma: no branch
246246
self._source_port = kwargs.get("src_port", 0)
247-
else:
247+
else: # pragma: no branch
248248
self._source_port = int(
249249
50000 + (
250250
int(random.SystemRandom().randbytes(int(60000).__sizeof__()).hex(), 16) % 9999
@@ -253,7 +253,7 @@ def __init__(self, *args, **kwargs):
253253

254254
# skipcq: TCV-002
255255
@staticmethod
256-
def say(address, port, sock, msg):
256+
def say(address: str, port: int, sock: socket.socket, msg: str) -> None: # pragma: no cover
257257
"""
258258
Send a message to a specified multicast address and port, then receive and print it.
259259
@@ -306,9 +306,9 @@ def say(address, port, sock, msg):
306306
307307
"""
308308
# skipcq: TCV-002
309-
sock.sendto(bytes(msg + "\n", "utf-8"), (address, port))
310-
received = str(sock.recv(1024), "utf-8")
311-
sp = " " * 4
309+
sock.sendto(bytes(msg + "\n", "utf-8"), (address, port)) # pragma: no cover
310+
received = str(sock.recv(1024), "utf-8") # pragma: no cover
311+
sp = " " * 4 # pragma: no cover
312312
if (sys.stdout.isatty()): # pragma: no cover
313313
print(f"Sent: {sp}{msg}") # skipcq: PYL-C0209 - must remain compatible
314314
print(f"Received: {received}") # skipcq: PYL-C0209 - must remain compatible
@@ -340,7 +340,7 @@ class MyUDPHandler(socketserver.BaseRequestHandler):
340340
__module__ = "tests.MulticastUDPClient.MyUDPHandler"
341341

342342
# skipcq: TCV-002
343-
def handle(self):
343+
def handle(self) -> None: # pragma: no cover
344344
"""
345345
Handle incoming UDP requests.
346346
@@ -389,15 +389,15 @@ def handle(self):
389389
390390
"""
391391
# skipcq: TCV-002
392-
data = self.request[0].strip()
393-
sock = self.request[1]
394-
print(f"{self.client_address[0]} wrote: ")
395-
print(data)
396-
sock.sendto(data.upper(), self.client_address)
392+
data = self.request[0].strip() # pragma: no cover
393+
sock = self.request[1] # pragma: no cover
394+
print(f"{self.client_address[0]} wrote: ") # pragma: no cover
395+
print(data) # pragma: no cover
396+
sock.sendto(data.upper(), self.client_address) # pragma: no cover
397397

398398

399399
# skipcq: TCV-002
400-
def main():
400+
def main() -> None: # pragma: no cover
401401
"""
402402
The main test operations.
403403
@@ -423,16 +423,16 @@ def main():
423423
424424
"""
425425
# skipcq: TCV-002
426-
HOST, PORT = "224.0.0.1", 59991
427-
data = "TEST This is a test"
428-
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
429-
tsts_fxr = MCastClient()
430-
print(str((HOST, PORT)))
431-
tsts_fxr.say(HOST, PORT, sock, data)
432-
tsts_fxr.say(HOST, PORT, sock, str("STOP"))
426+
HOST, PORT = "224.0.0.1", 59991 # pragma: no cover
427+
data = "TEST This is a test" # pragma: no cover
428+
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) # pragma: no cover
429+
tsts_fxr = MCastClient() # pragma: no cover
430+
print(str((HOST, PORT))) # pragma: no cover
431+
tsts_fxr.say(HOST, PORT, sock, data) # pragma: no cover
432+
tsts_fxr.say(HOST, PORT, sock, "STOP") # pragma: no cover
433433

434434

435-
if __name__ == "__main__":
435+
if __name__ == "__main__": # pragma: no branch
436436
main() # skipcq: TCV-002
437437
# skipcq: PYL-R1722
438438
exit(0) # skipcq: PYL-R1722 -- intentionally allow overwriteing exit for testing.

tests/run_selective.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,24 @@
2828
python3 -m tests.run_selective --group [mat|extra|fuzzing|performance] [--category CATEGORY]
2929
"""
3030

31-
__module__ = "tests"
31+
__module__ = "tests" # pragma: no cover
3232

33-
import sys
34-
import argparse
35-
import unittest
36-
import logging
33+
import sys # pragma: no cover
34+
import argparse # pragma: no cover
35+
import unittest # pragma: no cover
36+
import logging # pragma: no cover
3737

38-
if __debug__ and __name__ == "__main__":
38+
if __debug__ and __name__ == "__main__": # pragma: no branch
3939
logging.getLogger(__module__).debug(
4040
"Bootstrapping %s", # lazy formatting to avoid PYL-W1203
4141
__file__,
4242
)
4343

44-
from tests import get_test_suite
45-
from tests import TEST_GROUPS
44+
from tests import get_test_suite # pragma: no cover
45+
from tests import TEST_GROUPS # pragma: no cover
4646

4747

48-
def main() -> None:
48+
def main() -> None: # pragma: no cover
4949
"""Run selective tests based on specified group and category.
5050
5151
Parses command line arguments to select the appropriate test suite and executes the tests using
@@ -80,5 +80,5 @@ def main() -> None:
8080
sys.exit(1)
8181

8282

83-
if __name__ == "__main__":
83+
if __name__ == "__main__": # pragma: no branch
8484
main()

0 commit comments

Comments
 (0)