2121
2222@pytest .fixture
2323def valid_prompt_file ():
24+ """A context manager that creates a temporary file with valid prompt data.
25+
26+ This method creates a temporary file, writes a predefined dictionary
27+ (_PROMPT_FILE_DICT) as JSON to the file, and yields the file path. The file
28+ is automatically closed and deleted after the context is exited.
29+
30+ Args:
31+ None
32+
33+ Returns:
34+ str: The path to the temporary file containing the valid prompt data.
35+
36+ Yields:
37+ str: The path to the temporary file containing the valid prompt data.
38+
39+ Raises:
40+ JSONDecodeError: If there's an error in JSON serialization.
41+ IOError: If there's an error in file operations.
42+ """
2443 fp = tempfile .NamedTemporaryFile ("w" , delete = False )
2544 try :
2645 json .dump (_PROMPT_FILE_DICT , fp )
@@ -32,6 +51,25 @@ def valid_prompt_file():
3251
3352@pytest .fixture
3453def valid_prompt_values_file ():
54+ """Creates a temporary file containing valid prompt values and yields the file path.
55+
56+ This method generates a temporary file, writes the contents of _PROMPT_VALUES
57+ (assumed to be a dictionary or list) as JSON to the file, and yields the file path.
58+ The file is automatically closed and deleted after use.
59+
60+ Args:
61+ None
62+
63+ Returns:
64+ str: The path to the temporary file containing the valid prompt values.
65+
66+ Yields:
67+ str: The path to the temporary file containing the valid prompt values.
68+
69+ Raises:
70+ IOError: If there's an error writing to the temporary file.
71+ JSONDecodeError: If _PROMPT_VALUES cannot be serialized to JSON.
72+ """
3573 fp = tempfile .NamedTemporaryFile ("w" , delete = False )
3674 try :
3775 json .dump (_PROMPT_VALUES , fp )
@@ -61,6 +99,21 @@ def valid_prompt_values_file():
6199 ],
62100)
63101def test_prepare_prompt_required_keys (valid_prompt_file , valid_prompt_values_file , keys ):
102+ """Tests the PreparePrompt class with required keys missing.
103+
104+ This method tests the behavior of the PreparePrompt class when required keys are missing from the input dictionary. It expects a ValueError to be raised when the PreparePrompt class is instantiated with incomplete inputs.
105+
106+ Args:
107+ valid_prompt_file (str): Path to a valid prompt template file.
108+ valid_prompt_values_file (str): Path to a valid prompt values file.
109+ keys (list): List of keys to be removed from the input dictionary.
110+
111+ Returns:
112+ None
113+
114+ Raises:
115+ ValueError: When PreparePrompt is instantiated with missing required keys.
116+ """
64117 inputs = {
65118 "prompt_template_file" : valid_prompt_file ,
66119 "prompt_id" : _PROMPT_ID ,
@@ -88,6 +141,19 @@ def test_prepare_prompt_non_existent_files(valid_prompt_file, valid_prompt_value
88141
89142@pytest .mark .parametrize ("key" , ["prompt_values" , "prompt_value_file" ])
90143def test_prepare_prompt_prompt_values (valid_prompt_file , valid_prompt_values_file , key ):
144+ """Tests the PreparePrompt class initialization with different input combinations.
145+
146+ Args:
147+ valid_prompt_file (str): Path to a valid prompt template file.
148+ valid_prompt_values_file (str): Path to a valid prompt values file.
149+ key (str): The key to be removed from the inputs dictionary.
150+
151+ Returns:
152+ None: This method doesn't return anything explicitly.
153+
154+ Raises:
155+ AssertionError: If the assertions for prompt_template or prompt_values fail.
156+ """
91157 inputs = {
92158 "prompt_template_file" : valid_prompt_file ,
93159 "prompt_id" : _PROMPT_ID ,
@@ -101,6 +167,17 @@ def test_prepare_prompt_prompt_values(valid_prompt_file, valid_prompt_values_fil
101167
102168
103169def test_prepare_prompt_prompts (valid_prompt_file ):
170+ """Test the preparation of prompts using a valid prompt file.
171+
172+ Args:
173+ valid_prompt_file (str): Path to a valid prompt template file.
174+
175+ Returns:
176+ None
177+
178+ Raises:
179+ AssertionError: If the prepared prompts are None or if the number of prompts is not equal to 2.
180+ """
104181 inputs = {
105182 "prompt_template_file" : valid_prompt_file ,
106183 "prompt_id" : _PROMPT_ID ,
0 commit comments