Skip to content

Commit ed5d5b3

Browse files
committed
test: add unit tests for new classes
1 parent 3bd679e commit ed5d5b3

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

.coverage

0 Bytes
Binary file not shown.

api/terraform/python/openai_api/lambda_openai_function/tests/test_custom_config.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@
2323
from openai_api.lambda_openai_function.custom_config import (
2424
AdditionalInformation,
2525
CustomConfig,
26+
FunctionCalling,
27+
Prompting,
2628
SearchTerms,
2729
SystemPrompt,
30+
validate_required_keys,
2831
)
2932

3033
# our stuff
@@ -42,6 +45,19 @@ def setUp(self):
4245
self.everlasting_gobbstopper = get_test_file_yaml("config/everlasting-gobbstopper.yaml")
4346
self.everlasting_gobbstopper_invalid = get_test_file_yaml("config/everlasting-gobbstopper-invalid.yaml")
4447

48+
def test_validate_required_keys(self):
49+
"""Test validate_required_keys."""
50+
required_keys = ["meta_data", "prompting", "function_calling"]
51+
validate_required_keys(
52+
class_name="CustomConfig", config_json=self.everlasting_gobbstopper, required_keys=required_keys
53+
)
54+
55+
with self.assertRaises(ValueError):
56+
required_keys = ["meta_data", "prompting", "some_other_key"]
57+
validate_required_keys(
58+
class_name="CustomConfig", config_json=self.everlasting_gobbstopper_invalid, required_keys=required_keys
59+
)
60+
4561
def test_system_prompt(self):
4662
"""Test system_prompt."""
4763
prompt = self.everlasting_gobbstopper["prompting"]["system_prompt"]
@@ -53,6 +69,7 @@ def test_system_prompt(self):
5369
)
5470
self.assertIsInstance(system_prompt, SystemPrompt)
5571
self.assertIsInstance(system_prompt.system_prompt, str)
72+
self.assertTrue(isinstance(system_prompt.to_json(), dict))
5673

5774
def test_system_prompt_invalid(self):
5875
"""Test system_prompt."""
@@ -132,3 +149,21 @@ def test_refers_to(self):
132149
self.assertListEqual(
133150
additional_information.keys, ["contact", "biographical", "sales_promotions", "coupon_codes"]
134151
)
152+
153+
def test_prompting(self):
154+
"""Test prompting."""
155+
custom_config = CustomConfig(config_json=self.everlasting_gobbstopper)
156+
prompting_config_json = custom_config.prompting.to_json()
157+
Prompting(config_json=prompting_config_json)
158+
159+
with self.assertRaises(ValueError):
160+
Prompting(config_json={})
161+
162+
def test_function_calling(self):
163+
"""Test function_calling."""
164+
custom_config = CustomConfig(config_json=self.everlasting_gobbstopper)
165+
function_calling_config_json = custom_config.function_calling.to_json()
166+
FunctionCalling(config_json=function_calling_config_json)
167+
168+
with self.assertRaises(ValueError):
169+
FunctionCalling(config_json={})

0 commit comments

Comments
 (0)