Skip to main content

maybach_request

用户实现 Python 自动批改的库

下载

pip install maybach_request

使用

举一个例子,现在要断言一下代码的正确性:

# main.py
# student_code_starts
name = input('请输入姓名:')
print(name)
# student_code_ends

要求:用户输入 xigua,控制台能正确打印出来 xigua 并且能检查到 name 变量为 xigua

# test.py
from maybach-request import get_print, send_print, pass_test, no_pass_test

# 获取用户的输入
# 模拟一个用户的输入
send_print('xigua')
# 获取用户的输入
text = get_print()
passed = False
msg = '请打印name变量'
if name == 'xigua':
  for i in text:
    if i.find('xigua'):
      passed = True
      msg = 'success'
      break
else:
  msg = '请声明name变量'

if passed:
  # 通过测试
  pass_test(msg)
else:
  # 测试不通过
  no_pass_test(msg)

运行 python test.py --port 3004 --host 127.0.0.1,当不传 --host 默认使用 127.0.0.1

依赖

maybach_request 依赖服务提供接口获取用户的输入,以及通知服务测试的结果。 @xigua/maybach-server 提供了整套服务。

动态端口号

maybach_request 依赖的服务端口号是动态产生的,因此在执行相应的 python 代码的时候,需要通过 argv的形式传递给 python 进程

python xxx.py --port port

这样 maybach_request 能够拿到相应的端口号,跟对应的进程通信。如果使用了 @xigua/maybach-vm

import { run } from '@xigua/maybach-vm';

run(0, xxx.py, cwd, ['--port', port]).then((res) => {
  console.log(res);
});

run(1, 'print(123)', cwd, ['--port', port], (res) => {
  console.log(res);
});

Release files for maybach-request 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for maybach-request 0.5.0
File Size Uploaded
maybach_request-0.5.0.tar.gz 2.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for maybach-request 0.5.0
File Interpreter ABI Platform
maybach_request-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 5.6 kB

Release files / maybach_request-0.5.0.tar.gz

Download URL maybach_request-0.5.0.tar.gz
Size 2.8 kB
Tags Source
SHA-256 checksum
How to use checksums
a1a703bf40f70973fe02de4abcb2bde8acc275f939627707db29dc18cdb25551
BLAKE2b-256 checksum
How to use checksums
20d25c78b5f8f0bf1311f7861ada184e36035cd47f2784855073ac338446e225
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1.post20200604 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

Release files / maybach_request-0.5.0-py3-none-any.whl

Download URL maybach_request-0.5.0-py3-none-any.whl
Size 2.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ffd247fae5edc24dda781feff39cbf9a8fdbe89e91856d79ec363768f92998ce
BLAKE2b-256 checksum
How to use checksums
2c23556ac8af2c30b5baf42e14576b04e4b50a9513f1d29f2376bfcad7fda66b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1.post20200604 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page