({
assertion,
renderedValue,
valueFromScript,
assertionValueContext,
inverse,
output,
}: AssertionParams)
| 30 | } |
| 31 | |
| 32 | export const handlePython = async ({ |
| 33 | assertion, |
| 34 | renderedValue, |
| 35 | valueFromScript, |
| 36 | assertionValueContext, |
| 37 | inverse, |
| 38 | output, |
| 39 | }: AssertionParams): Promise<GradingResult> => { |
| 40 | invariant(typeof renderedValue === 'string', 'python assertion must have a string value'); |
| 41 | try { |
| 42 | const result: ScriptAssertionResult = |
| 43 | typeof valueFromScript === 'undefined' |
| 44 | ? await runPythonCode(buildPythonScript(renderedValue), 'main', [ |
| 45 | output, |
| 46 | assertionValueContext, |
| 47 | ]) |
| 48 | : valueFromScript; |
| 49 | |
| 50 | return normalizeScriptResult( |
| 51 | assertion, |
| 52 | result, |
| 53 | inverse, |
| 54 | { code: 'Python code', language: 'Python' }, |
| 55 | assertion.value, |
| 56 | ); |
| 57 | } catch (err) { |
| 58 | return { |
| 59 | pass: false, |
| 60 | score: 0, |
| 61 | reason: `Python code execution failed: ${(err as Error).message}`, |
| 62 | assertion, |
| 63 | }; |
| 64 | } |
| 65 | }; |
nothing calls this directly
no test coverage detected
searching dependent graphs…