fix(agent/tests): Update test_utils.py:test_extract_json_from_response* in accordance with 956cdc7

Commit 956cdc7 "fix(agent/json_utils): Decode as JSON rather than Python objects" broke these unit tests because they generated "JSON" by stringifying a Python object.
This commit is contained in:
Reinier van der Leer
2024-02-02 18:18:45 +01:00
parent 925269d17b
commit 9b7fee673e

View File

@@ -1,3 +1,4 @@
import json
import os
from unittest.mock import patch
@@ -194,14 +195,14 @@ def test_get_current_git_branch_failure(mock_repo):
def test_extract_json_from_response(valid_json_response: dict):
emulated_response_from_openai = str(valid_json_response)
emulated_response_from_openai = json.dumps(valid_json_response)
assert (
extract_dict_from_response(emulated_response_from_openai) == valid_json_response
)
def test_extract_json_from_response_wrapped_in_code_block(valid_json_response: dict):
emulated_response_from_openai = "```" + str(valid_json_response) + "```"
emulated_response_from_openai = "```" + json.dumps(valid_json_response) + "```"
assert (
extract_dict_from_response(emulated_response_from_openai) == valid_json_response
)
@@ -210,14 +211,14 @@ def test_extract_json_from_response_wrapped_in_code_block(valid_json_response: d
def test_extract_json_from_response_wrapped_in_code_block_with_language(
valid_json_response: dict,
):
emulated_response_from_openai = "```json" + str(valid_json_response) + "```"
emulated_response_from_openai = "```json" + json.dumps(valid_json_response) + "```"
assert (
extract_dict_from_response(emulated_response_from_openai) == valid_json_response
)
def test_extract_json_from_response_json_contained_in_string(valid_json_response: dict):
emulated_response_from_openai = "sentence1" + str(valid_json_response) + "sentence2"
emulated_response_from_openai = "sentence1" + json.dumps(valid_json_response) + "sentence2"
assert (
extract_dict_from_response(emulated_response_from_openai) == valid_json_response
)