Allow more APIs for CodeQuestion
- Dominant language
- Python
- Stars
- 435
- Forks
- 124
- Avg merge
- 5h 40m
- Merged PRs (30d)
- 14
Description
(Hi, long time no see.)
I wish to added more APIs for CodeQuestions, so that some simple tests could be done which is currently not possible for relate AFAIK. For example, testing if a specifc function was called with specific arguments (#381 ) .
Another use case is to test scripts (not a function) submit by a user. For example, I need to test if `input` was used as expected in a script. The following was the `user_code`:
```python
name = input("please input your name")
print(”Hello %s!" % name)
```
My workround is to turn `user_code` into the following before sent to [request_run](https://github.com/inducer/relate/blob/68ecca7ea440ee4eaf70312168a54e5ecf73aa37/course/page/code.py#L602):
```python
def __func():
name = input("please input your name")
print(”Hello %s!" % name)
```
and then I can use unittest to check whether it really works, using something like [this](https://forum.learncodethehardway.com/t/testing-input-and-print/1757/10) using `mock`. That also requires the `__func` namespace being added to the `run_req` as a runpy context so that `__func` can be called in `test_code`.
To summarize, I need to refactor the [`grade`](https://github.com/inducer/relate/blob/68ecca7ea440ee4eaf70312168a54e5ecf73aa37/course/page/code.py#L595) method so that more possibilities of subclass of `CodeQuestion` or `PythonCodeQuestion` are possible.
May I write a PR to do that? Thanks.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.