Skip to content

Commit 9cb2d66

Browse files
committed
Add Postman test for image generation and configure matplotlib temp directory
Includes a new Postman test case for image generation in demo mode and updates the evaluation function to set a temporary matplotlib configuration directory.
1 parent 1fcaeea commit 9cb2d66

2 files changed

Lines changed: 53 additions & 1 deletion

File tree

evaluation_function/evaluation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def _run_code(code: str, stdin: str) -> tuple[str, str, bool, list[Image.Image]]
4444
capture_output=True,
4545
text=True,
4646
timeout=_TIMEOUT,
47-
env={**os.environ, "MPLBACKEND": "Agg"},
47+
env={**os.environ, "MPLBACKEND": "Agg", "MPLCONFIGDIR": "/tmp"},
4848
)
4949
images = []
5050
for fn in sorted(os.listdir(plot_dir)):

postman/evaluatePython.postman_collection.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,58 @@
552552
}
553553
]
554554
},
555+
{
556+
"name": "20 – Image generation (demo mode)",
557+
"request": {
558+
"method": "POST",
559+
"header": [
560+
{ "key": "Content-Type", "value": "application/json" }
561+
],
562+
"body": {
563+
"mode": "raw",
564+
"raw": "{\n \"response\": \"import matplotlib.pyplot as plt\\nplt.plot([1, 2, 3], [1, 4, 9])\\nplt.title('squares')\\n\",\n \"answer\": \"\",\n \"params\": {\n \"tests\": []\n }\n}",
565+
"options": { "raw": { "language": "json" } }
566+
},
567+
"url": { "raw": "{{baseUrl}}", "host": ["{{baseUrl}}"] }
568+
},
569+
"event": [
570+
{
571+
"listen": "prerequest",
572+
"script": {
573+
"type": "text/javascript",
574+
"exec": ["pm.request.timeout = 40000;"]
575+
}
576+
},
577+
{
578+
"listen": "test",
579+
"script": {
580+
"type": "text/javascript",
581+
"exec": [
582+
"pm.test('Status 200', () => {",
583+
" pm.expect(pm.response.code, 'Body: ' + pm.response.text()).to.equal(200);",
584+
"});",
585+
"",
586+
"pm.test('Response is eval command with no error', () => {",
587+
" const json = pm.response.json();",
588+
" pm.expect(json.command).to.equal('eval');",
589+
" pm.expect(json).to.not.have.property('error');",
590+
"});",
591+
"",
592+
"pm.test('Feedback contains Output block (code ran successfully)', () => {",
593+
" pm.expect(pm.response.json().result.feedback).to.include('Output');",
594+
"});",
595+
"",
596+
"pm.test('Feedback contains uploaded plot link (requires cloud credentials)', () => {",
597+
" // This assertion only passes when the server has valid S3/image-upload",
598+
" // credentials. Skip or ignore locally if upload is not configured.",
599+
" const feedback = pm.response.json().result.feedback;",
600+
" pm.expect(feedback).to.include('![Plot 1]');",
601+
"});"
602+
]
603+
}
604+
}
605+
]
606+
},
555607
{
556608
"name": "11 – numpy scientific library",
557609
"request": {

0 commit comments

Comments
 (0)