Skip to content

Commit bd2d16d

Browse files
committed
Test HTTPStatus items are stringified as values
It was discovered by @julianz- [[1]] that this works differently under *NIX and on Windows. So this patch adds a test case to demonstrate the inconsistency. [1]: cherrypy/cheroot#800 (comment)
1 parent 26757d1 commit bd2d16d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Lib/test/test_httpservers.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,26 @@ def test_all(self):
12621262
expected.append(name)
12631263
self.assertCountEqual(server.__all__, expected)
12641264

1265+
def test_http_status_str_equals_value_str(self):
1266+
"""Ensure string render of an HTTPStatus is the same as of its
1267+
value attribute."""
1268+
for http_status_attr in HTTPStatus._member_map_:
1269+
http_status = getattr(HTTPStatus, http_status_attr)
1270+
with self.subTest(http_status_attr=http_status_attr):
1271+
self.assertEqual(str(http_status), str(http_status.value))
1272+
1273+
def test_http_status_str_is_numeric(self):
1274+
"""Ensure string render of an HTTPStatus is the same as of its
1275+
value attribute."""
1276+
for http_status_attr in HTTPStatus._member_map_:
1277+
http_status = getattr(HTTPStatus, http_status_attr)
1278+
with self.subTest(http_status_attr=http_status_attr):
1279+
self.assertTrue(str(http_status).isdigit())
1280+
1281+
def test_http_status_bad_request_str_looks_like_a_number(self):
1282+
"""Ensure string render of ``HTTPStatus.BAD_REQUEST`` is 400."""
1283+
self.assertEqual(str(HTTPStatus.BAD_REQUEST), '400')
1284+
12651285

12661286
class ScriptTestCase(unittest.TestCase):
12671287

0 commit comments

Comments
 (0)