Skip to content

Commit 784ffc7

Browse files
cursoragentxxg1413
andcommitted
courses: combine nested with-statements in the new course tests (ruff SIM117)
Co-authored-by: P小二 <xxg1413@gmail.com>
1 parent 75f2f8b commit 784ffc7

2 files changed

Lines changed: 6 additions & 9 deletions

File tree

‎courses/llm-features-in-python/tests/test_ticket_triage.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,8 @@ def test_parse_rejects_missing_extra_and_mistyped_fields(self) -> None:
6464
ticket_triage.parse_triage(raw, CATEGORIES)
6565
self.assertIn(field, str(caught.exception))
6666
for raw in ("Sure! Category: billing.", "[]", reply(summary="x" * 121)):
67-
with self.subTest(raw=raw[:20]):
68-
with self.assertRaises(ticket_triage.TriageError):
69-
ticket_triage.parse_triage(raw, CATEGORIES)
67+
with self.subTest(raw=raw[:20]), self.assertRaises(ticket_triage.TriageError):
68+
ticket_triage.parse_triage(raw, CATEGORIES)
7069

7170

7271
class ToolCallTest(unittest.TestCase):

‎courses/secure-ai-generated-code/tests/test_notes_app.py‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,8 @@ def test_attachment_inside_base_is_read(self) -> None:
7474

7575
def test_attachment_traversal_is_refused(self) -> None:
7676
for name in ("../secrets.txt", "docs/../../secrets.txt"):
77-
with self.subTest(name=name):
78-
with self.assertRaises(notes_app.SecurityError):
79-
notes_app.read_attachment(self.base, name)
77+
with self.subTest(name=name), self.assertRaises(notes_app.SecurityError):
78+
notes_app.read_attachment(self.base, name)
8079

8180
def test_absolute_attachment_path_is_refused(self) -> None:
8281
with self.assertRaises(notes_app.SecurityError):
@@ -141,9 +140,8 @@ def test_tampered_or_foreign_session_is_refused(self) -> None:
141140
flipped = ("A" if token[0] != "A" else "B") + token[1:]
142141
non_ascii = token.rpartition(".")[0] + ".é" + token.rpartition(".")[2][1:]
143142
for bad in (forged, flipped, non_ascii, "", "no-signature-here"):
144-
with self.subTest(token=bad[:16]):
145-
with self.assertRaises(notes_app.SecurityError):
146-
notes_app.load_session(bad, self.key)
143+
with self.subTest(token=bad[:16]), self.assertRaises(notes_app.SecurityError):
144+
notes_app.load_session(bad, self.key)
147145

148146
def test_pickle_payload_is_never_executed(self) -> None:
149147
with tempfile.TemporaryDirectory() as tmp:

0 commit comments

Comments
 (0)