From 87b25ba503df3224c8ba6b7841717e85a2b174cb Mon Sep 17 00:00:00 2001 From: Marcel Wilson Date: Tue, 13 Feb 2024 15:48:26 -0600 Subject: [PATCH] fixes after rebase --- screenpy_requests/questions/body_of_the_last_response.py | 6 +++--- tests/test_questions.py | 7 +++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/screenpy_requests/questions/body_of_the_last_response.py b/screenpy_requests/questions/body_of_the_last_response.py index cab62bf..fd28285 100644 --- a/screenpy_requests/questions/body_of_the_last_response.py +++ b/screenpy_requests/questions/body_of_the_last_response.py @@ -3,7 +3,7 @@ from __future__ import annotations from json.decoder import JSONDecodeError -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Union from screenpy.exceptions import UnableToAnswer from screenpy.pacing import beat @@ -56,6 +56,7 @@ class BodyOfTheLastResponse: body_parts: list[subscripts] def __getitem__(self, key: subscripts) -> BodyOfTheLastResponse: + """Allows access to subscripts later in answered_by.""" self.body_parts.append(key) return self @@ -77,9 +78,8 @@ def answered_by(self, the_actor: Actor) -> dict | str: response = responses[-1].json() for part in self.body_parts: response = response[part] - return response except JSONDecodeError: response = responses[-1].text for part in self.body_parts: response = response[part] - return response + return response diff --git a/tests/test_questions.py b/tests/test_questions.py index 66cabfe..8463f77 100644 --- a/tests/test_questions.py +++ b/tests/test_questions.py @@ -58,12 +58,12 @@ def test_ask_for_body_of_the_last_response(self, APITester: Actor) -> None: assert BodyOfTheLastResponse().answered_by(APITester) == test_json - def test_stores_index_path(self): + def test_stores_index_path(self) -> None: botlr = BodyOfTheLastResponse()["shuffled"]["off"][10]["mortal"]["coils"] assert botlr.body_parts == ["shuffled", "off", 10, "mortal", "coils"] - def test_digs_into_json(self, APITester): + def test_digs_into_json(self, APITester: Actor) -> None: test_json = {"plays": [{"name": "Hamlet"}]} fake_response = mock.Mock() fake_response.json.return_value = test_json @@ -74,7 +74,7 @@ def test_digs_into_json(self, APITester): assert botlr.answered_by(APITester) == "Hamlet" - def test_slices_text(self, APITester): + def test_slices_text(self, APITester: Actor) -> None: test_text = "My favorite play is Hamlet." fake_response = mock.Mock() fake_response.json.return_value = test_text @@ -84,7 +84,6 @@ def test_slices_text(self, APITester): assert BodyOfTheLastResponse()[-7:-1].answered_by(APITester) == "Hamlet" - class TestCookies: def test_can_be_instantiated(self) -> None: c = Cookies()