Skip to content

Commit f874206

Browse files
adding unit tests
1 parent dcd36d7 commit f874206

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import unittest
2+
3+
from utils import construct_prompt
4+
from class_eval import record_to_sample
5+
6+
from test_data import record, sample, prompt
7+
8+
class TestClassEval(unittest.TestCase):
9+
10+
def test_record_to_sample(self):
11+
self.assertEqual(record_to_sample(record), sample)
12+
13+
class TestUtils(unittest.TestCase):
14+
15+
def test_construct_prompt(self):
16+
self.assertEqual(construct_prompt(record), prompt)
17+
18+
19+
# if __name__ == '__main__':
20+
21+
# #Save record to file
22+
# with open('test_data2.py', 'w') as f:
23+
# f.write(f'{record_to_sample(record)}')
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
from inspect_ai.dataset import Sample
2+
3+
record = {
4+
"task_id": "ClassEval_demo",
5+
"skeleton": "import numpy as np\n\nclass Add_numbers:\n \"\"\"\n This class adds numbers.\n \"\"\"\n\n def __init__(self):\n pass\n\n def add(self, x, y):\n \"\"\"\n Add the two numbers\n :param x: float, first number\n :param y: float, second number\n :return: float, sum of the two numbers\n >>> adder = Add_numbers()\n >>> adder.add(1,2)",
6+
"solution_code": "No solution code provided.",
7+
"import_statement": [
8+
"import numpy as np"
9+
],
10+
"class_description": " \"\"\"\n This class adds numbers.\n \"\"\"\n",
11+
"class_name": "Add_numbers",
12+
"test": "No test code provided.",
13+
"test_classes": [
14+
"AddTest"
15+
],
16+
"class_constructor": "class Add_numbers: \n def __init__(self):\n pass\n\n",
17+
"fields": [],
18+
"methods_info": [
19+
{
20+
"method_name": "add",
21+
"method_description": "def filter(self, request):\n \"\"\"\n Filter the incoming request based on certain rules and conditions.\n :param request: dict, the incoming request details\n :return: bool, True if the request is allowed, False otherwise\n >>> filter = AccessGatewayFilter()\n >>> filter.filter({'path': '/login', 'method': 'POST'})\n True\n\n \"\"\"",
22+
"test_class": "AddTest",
23+
"test_code": "pass",
24+
"dependencies": {
25+
"Standalone": True,
26+
"lib_dependencies": [],
27+
"field_dependencies": [],
28+
"method_dependencies": []
29+
}
30+
}
31+
]
32+
}
33+
34+
35+
sample = Sample(
36+
input = 'Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n ### Instruction:\n Please complete the class Add_numbers in the following code.\nimport numpy as np\n\nclass Add_numbers:\n """\n This class adds numbers.\n """\n\n def __init__(self):\n pass\n\n def add(self, x, y):\n """\n Add the two numbers\n :param x: float, first number\n :param y: float, second number\n :return: float, sum of the two numbers\n >>> adder = Add_numbers()\n >>> adder.add(1,2)\n\n ### Response:\n ',
37+
choices=None,
38+
target='No solution code provided.',
39+
id='ClassEval_demo',
40+
metadata={'task_id': 'ClassEval_demo', 'skeleton': 'import numpy as np\n\nclass Add_numbers:\n """\n This class adds numbers.\n """\n\n def __init__(self):\n pass\n\n def add(self, x, y):\n """\n Add the two numbers\n :param x: float, first number\n :param y: float, second number\n :return: float, sum of the two numbers\n >>> adder = Add_numbers()\n >>> adder.add(1,2)', 'test': 'No test code provided.', 'solution_code': 'No solution code provided.', 'import_statement': ['import numpy as np'], 'class_description': ' """\n This class adds numbers.\n """\n', 'methods_info': [{'method_name': 'add', 'method_description': 'def filter(self, request):\n """\n Filter the incoming request based on certain rules and conditions.\n :param request: dict, the incoming request details\n :return: bool, True if the request is allowed, False otherwise\n >>> filter = AccessGatewayFilter()\n >>> filter.filter({\'path\': \'/login\', \'method\': \'POST\'})\n True\n\n """', 'test_class': 'AddTest', 'test_code': 'pass', 'dependencies': {'Standalone': True, 'lib_dependencies': [], 'field_dependencies': [], 'method_dependencies': []}}], 'class_name': 'Add_numbers', 'test_classes': ['AddTest'], 'class_constructor': 'class Add_numbers: \n def __init__(self):\n pass\n\n', 'fields': []},
41+
sandbox=None,
42+
files=None,
43+
setup=None,
44+
)
45+
46+
47+
prompt = r'''Below is an instruction that describes a task. Write a response that appropriately completes the request.
48+
49+
### Instruction:
50+
Please complete the class Add_numbers in the following code.
51+
import numpy as np
52+
53+
class Add_numbers:
54+
"""
55+
This class adds numbers.
56+
"""
57+
58+
def __init__(self):
59+
pass
60+
61+
def add(self, x, y):
62+
"""
63+
Add the two numbers
64+
:param x: float, first number
65+
:param y: float, second number
66+
:return: float, sum of the two numbers
67+
>>> adder = Add_numbers()
68+
>>> adder.add(1,2)
69+
70+
### Response:
71+
'''
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
input='Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n ### Instruction:\n Please complete the class Add_numbers in the following code.\nimport numpy as np\n\nclass Add_numbers:\n """\n This class adds numbers.\n """\n\n def __init__(self):\n pass\n\n def add(self, x, y):\n """\n Add the two numbers\n :param x: float, first number\n :param y: float, second number\n :return: float, sum of the two numbers\n >>> adder = Add_numbers()\n >>> adder.add(1,2)\n\n ### Response:\n ' choices=None target='No solution code provided.' id='ClassEval_demo' metadata={'task_id': 'ClassEval_demo', 'skeleton': 'import numpy as np\n\nclass Add_numbers:\n """\n This class adds numbers.\n """\n\n def __init__(self):\n pass\n\n def add(self, x, y):\n """\n Add the two numbers\n :param x: float, first number\n :param y: float, second number\n :return: float, sum of the two numbers\n >>> adder = Add_numbers()\n >>> adder.add(1,2)', 'test': 'No test code provided.', 'solution_code': 'No solution code provided.', 'import_statement': ['import numpy as np'], 'class_description': ' """\n This class adds numbers.\n """\n', 'methods_info': [{'method_name': 'add', 'method_description': 'def filter(self, request):\n """\n Filter the incoming request based on certain rules and conditions.\n :param request: dict, the incoming request details\n :return: bool, True if the request is allowed, False otherwise\n >>> filter = AccessGatewayFilter()\n >>> filter.filter({\'path\': \'/login\', \'method\': \'POST\'})\n True\n\n """', 'test_class': 'AddTest', 'test_code': 'pass', 'dependencies': {'Standalone': True, 'lib_dependencies': [], 'field_dependencies': [], 'method_dependencies': []}}], 'class_name': 'Add_numbers', 'test_classes': ['AddTest'], 'class_constructor': 'class Add_numbers: \n def __init__(self):\n pass\n\n', 'fields': []} sandbox=None files=None setup=None

0 commit comments

Comments
 (0)