Skip to content

Commit eb7028b

Browse files
trim test script
1 parent 661b285 commit eb7028b

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

Lib/test/test_email/test_infinite_loop_fix.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
import unittest
88
import email.message
9-
import email.policy
10-
from email import policy
119

1210

1311
class TestInfiniteLoopFix(unittest.TestCase):
@@ -16,21 +14,21 @@ class TestInfiniteLoopFix(unittest.TestCase):
1614
def test_long_parameter_key_no_infinite_loop(self):
1715
"""Test that very long parameter keys don't cause infinite loops."""
1816
msg = email.message.EmailMessage()
19-
17+
2018
# Create a parameter key that's 64 characters long (the problematic length)
2119
long_key = "a" * 64
22-
20+
2321
# Add attachment first
2422
msg.add_attachment(
2523
b"test content",
2624
maintype="text",
2725
subtype="plain",
2826
filename="test.txt"
2927
)
30-
28+
3129
# Set the long parameter using set_param
3230
msg.set_param(long_key, "test_value")
33-
31+
3432
# This should not hang - it should complete in reasonable time
3533
try:
3634
result = msg.as_string()
@@ -43,21 +41,21 @@ def test_long_parameter_key_no_infinite_loop(self):
4341
def test_extremely_long_parameter_key(self):
4442
"""Test with extremely long parameter keys that could cause maxchars < 0."""
4543
msg = email.message.EmailMessage()
46-
44+
4745
# Create an extremely long parameter key (100+ characters)
4846
extremely_long_key = "b" * 100
49-
47+
5048
# Add attachment first
5149
msg.add_attachment(
5250
b"test content",
5351
maintype="text",
5452
subtype="plain",
5553
filename="test.txt"
5654
)
57-
55+
5856
# Set the extremely long parameter
5957
msg.set_param(extremely_long_key, "test_value")
60-
58+
6159
# This should not hang even with extremely long keys
6260
try:
6361
result = msg.as_string()
@@ -69,25 +67,25 @@ def test_extremely_long_parameter_key(self):
6967
def test_multiple_long_parameters(self):
7068
"""Test with multiple long parameters to ensure robust handling."""
7169
msg = email.message.EmailMessage()
72-
70+
7371
# Add attachment first
7472
msg.add_attachment(
7573
b"test content",
7674
maintype="text",
7775
subtype="plain",
7876
filename="test.txt"
7977
)
80-
78+
8179
# Add multiple long parameters
8280
long_params = {
8381
"a" * 64: "value1",
8482
"b" * 80: "value2",
8583
"c" * 90: "value3"
8684
}
87-
85+
8886
for key, value in long_params.items():
8987
msg.set_param(key, value)
90-
88+
9189
try:
9290
result = msg.as_string()
9391
self.assertIsInstance(result, str)
@@ -101,22 +99,22 @@ def test_edge_case_parameter_lengths(self):
10199
"""Test edge cases around the problematic parameter lengths."""
102100
# Test parameter keys of various lengths around the problematic 64-char mark
103101
test_lengths = [60, 61, 62, 63, 64, 65, 66, 67, 68]
104-
102+
105103
for length in test_lengths:
106104
key = "x" * length
107105
msg = email.message.EmailMessage()
108-
106+
109107
# Add attachment first
110108
msg.add_attachment(
111109
b"test content",
112110
maintype="text",
113111
subtype="plain",
114112
filename="test.txt"
115113
)
116-
114+
117115
# Set the parameter
118116
msg.set_param(key, "test_value")
119-
117+
120118
try:
121119
result = msg.as_string()
122120
self.assertIsInstance(result, str)
@@ -127,18 +125,18 @@ def test_edge_case_parameter_lengths(self):
127125
def test_rfc_2231_compliance(self):
128126
"""Test that the fix maintains RFC 2231 compliance."""
129127
msg = email.message.EmailMessage()
130-
128+
131129
# Add attachment first
132130
msg.add_attachment(
133131
b"test content",
134132
maintype="text",
135133
subtype="plain",
136134
filename="test.txt"
137135
)
138-
136+
139137
# Set a parameter with special characters that should trigger RFC 2231 encoding
140138
msg.set_param("long_param", "value_with_special_chars_ñáéíóú")
141-
139+
142140
try:
143141
result = msg.as_string()
144142
self.assertIsInstance(result, str)

0 commit comments

Comments
 (0)