" result = subprocess.run(command, check=True, capture_output=True, text=True)\n",
@ -117,15 +115,7 @@
" print(\"Output:\\n\", e.stdout)\n",
" print(\"Errors:\\n\", e.stderr)\n",
" # Extracting failed test information\n",
" failed_tests = []\n",
" for line in e.stdout.splitlines():\n",
" if \"FAILED\" in line and \"::\" in line:\n",
" failed_tests.append(line.strip())\n",
" if failed_tests:\n",
" print(\"Failed Tests:\")\n",
" for test in failed_tests:\n",
" print(test)\n",
" return failed_tests\n",
" return e.stdout\n",
"\n",
"def save_unit_tests(code):\n",
"\n",
@ -179,7 +169,8 @@
" print(\"Failed Tests:\")\n",
" for test in failed_tests:\n",
" print(test)\n",
" return e.stderr\n",
" \n",
" return e.stdout\n",
" "
]
},
@ -192,7 +183,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
@ -201,15 +192,18 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"def get_user_prompt(code):\n",
"\n",
" user_prompt = \"Write for a python code the unit test cases.\"\n",
" user_prompt += \"Return unit tests cases using pytest library, do not create any custom imports; do not explain your work other than a few comments.\"\n",
" user_prompt += \"Do not insert the function to be tested in the output before the tests. Validate both the case where the function is executed successfully and where it is expected to fail.\"\n",
" user_prompt += \"Return readable unit tests cases using pytest library, do not create any custom imports, don't forget to import errors if needed; do not explain your work other than a few comments.\"\n",
" user_prompt += \"The tests should include normal inputs, the inputs where the code is expected to fail, edge case and error handling.\"\n",
" user_prompt += \"Do not insert the function to be tested in the output before the tests.\"\n",