Skip to content

Commit 164e5e3

Browse files
committed
test: make doctests work
./tools/devtool -y test -- --doctest-modules framework Signed-off-by: Pablo Barbáchano <[email protected]>
1 parent 6bc11c4 commit 164e5e3

File tree

6 files changed

+45
-48
lines changed

6 files changed

+45
-48
lines changed

tests/framework/gitlint_rules.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class EndsSigned(CommitRule):
2222
def validate(self, commit):
2323
r"""Validates Signed-off-by and Co-authored-by tags as Linux's scripts/checkpatch.pl
2424
25-
>>> from gitlint.tests.base import BaseTestCase
25+
>>> from gitlint.git import GitContext
2626
>>> from gitlint.rules import RuleViolation
2727
...
2828
>>> ends_signed = EndsSigned()
@@ -31,7 +31,7 @@ def validate(self, commit):
3131
... f"Title\n\nMessage.\n\n"
3232
... f"Signed-off-by: name <email@domain>"
3333
... )
34-
>>> commit1 = BaseTestCase.gitcommit(msg1)
34+
>>> commit1 = GitContext.from_commit_msg(msg1)
3535
>>> ends_signed.validate(commit1)
3636
[]
3737
>>> msg2 = (

tests/framework/properties.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def get_os_version():
2626
"""Get the OS version
2727
2828
>>> get_os_version()
29-
Ubuntu 18.04.6 LTS
29+
'Ubuntu 24.04.1 LTS'
3030
"""
3131

3232
os_release = Path("/etc/os-release").read_text(encoding="ascii")
@@ -41,7 +41,7 @@ def get_host_os(kv: str = None):
4141
This only works for AL2 and AL2023
4242
4343
>>> get_host_os("6.1.41-63.118.amzn2023.x86_64")
44-
amzn2023
44+
'amzn2023'
4545
"""
4646
if kv is None:
4747
kv = platform.release()

tests/framework/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,8 +660,8 @@ class Timeout:
660660
"""
661661
A Context Manager to timeout sections of code.
662662
663-
>>> with Timeout(30):
664-
>>> time.sleep(35)
663+
>>> with Timeout(30): # doctest: +SKIP
664+
... time.sleep(35) # doctest: +SKIP
665665
"""
666666

667667
def __init__(self, seconds, msg="Timed out"):

tests/framework/utils_imdsv2.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ class IMDSv2Client:
2424
"""
2525
A simple IMDSv2 client.
2626
27-
>>> IMDSv2Client().get("/meta-data/instance-type")
27+
>>> IMDSv2Client().get("/meta-data/instance-type") # doctest: +SKIP
28+
...
2829
"""
2930

3031
def __init__(self, endpoint="http://169.254.169.254", version="latest"):
@@ -49,8 +50,8 @@ def get(self, path):
4950
"""
5051
Get a metadata path from IMDSv2
5152
52-
>>> IMDSv2Client().get("/meta-data/instance-type")
53-
>>> m5d.metal
53+
>>> IMDSv2Client().get("/meta-data/instance-type") # doctest: +SKIP
54+
'm5d.metal'
5455
"""
5556
headers = {IMDSV2_HDR_TOKEN: self.get_token()}
5657
url = f"{self.endpoint}/{self.version}{path}"

tests/host_tools/udp_offload.py

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,35 +24,37 @@ def eprint(*args, **kwargs):
2424
SOL_UDP = 17 # Protocol number for UDP
2525
UDP_SEGMENT = 103 # Option code for UDP segmentation (non-standard)
2626

27-
# Get the IP and port from command-line arguments
28-
if len(sys.argv) != 3:
29-
eprint("Usage: python3 udp_offload.py <ip_address> <port>")
30-
sys.exit(1)
3127

32-
ip_address = sys.argv[1]
33-
port = int(sys.argv[2])
34-
35-
# Create a UDP socket
36-
sockfd = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
37-
38-
# Set the UDP segmentation option (UDP_SEGMENT) to 1400 bytes
39-
OPTVAL = 1400
40-
try:
41-
sockfd.setsockopt(SOL_UDP, UDP_SEGMENT, OPTVAL)
42-
except (AttributeError, PermissionError):
43-
eprint("Unable to set UDP_SEGMENT option")
44-
sys.exit(1)
45-
46-
# Set the destination address and port
47-
servaddr = (ip_address, port)
48-
49-
# Send the message to the destination address
50-
MESSAGE = b"x"
51-
try:
52-
sockfd.sendto(MESSAGE, servaddr)
53-
print("Message sent successfully")
54-
except socket.error as e:
55-
eprint(f"Error sending message: {e}")
56-
sys.exit(1)
57-
58-
sockfd.close()
28+
if __name__ == "__main__":
29+
# Get the IP and port from command-line arguments
30+
if len(sys.argv) != 3:
31+
eprint("Usage: python3 udp_offload.py <ip_address> <port>")
32+
sys.exit(1)
33+
34+
ip_address = sys.argv[1]
35+
port = int(sys.argv[2])
36+
37+
# Create a UDP socket
38+
sockfd = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
39+
40+
# Set the UDP segmentation option (UDP_SEGMENT) to 1400 bytes
41+
OPTVAL = 1400
42+
try:
43+
sockfd.setsockopt(SOL_UDP, UDP_SEGMENT, OPTVAL)
44+
except (AttributeError, PermissionError):
45+
eprint("Unable to set UDP_SEGMENT option")
46+
sys.exit(1)
47+
48+
# Set the destination address and port
49+
servaddr = (ip_address, port)
50+
51+
# Send the message to the destination address
52+
MESSAGE = b"x"
53+
try:
54+
sockfd.sendto(MESSAGE, servaddr)
55+
print("Message sent successfully")
56+
except socket.error as e:
57+
eprint(f"Error sending message: {e}")
58+
sys.exit(1)
59+
60+
sockfd.close()

tests/integration_tests/style/test_rust.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66

77

88
def test_rust_order():
9-
"""
10-
Tests that `Cargo.toml` dependencies are alphabetically ordered.
11-
12-
@type: style
13-
"""
9+
"""Tests that `Cargo.toml` dependencies are alphabetically ordered."""
1410

1511
# Runs `cargo-sort` with the current working directory (`cwd`) as the repository root.
1612
_, _, _ = utils.check_output(
@@ -19,9 +15,7 @@ def test_rust_order():
1915

2016

2117
def test_rust_style():
22-
"""
23-
Test that rust code passes style checks.
24-
"""
18+
"""Test that rust code passes style checks."""
2519

2620
# ../src/io_uring/src/bindings.rs
2721
config = open("fmt.toml", encoding="utf-8").read().replace("\n", ",")

0 commit comments

Comments
 (0)