SQL提交正确性测试
项目描述
sqlwhat
sqlwhat
允许您为DataCamp上的交互式SQL练习编写提交正确性测试 (SCT)。
- 如果您是DataCamp上的新教师,请查看 https://authoring.datacamp.com。
- 如果您想了解SCT是什么以及它们是如何工作的,请访问 这篇文章。
- 有关编写SQL练习的SCT的更多信息,请参阅 https://sqlwhat.readthedocs.io。
安装
pip install sqlwhat # install from pypi
make install # install from source
参考
- API文档: https://sqlwhat.readthedocs.io
- AST查看器: https://ast-viewer.datacamp.com
- 扩展: https://github.com/datacamp/sqlwhat-ext
提出关于SQL解析的问题
请在相应的解析器存储库上提出问题
基本用法
from sqlwhat.State import State # State holds info needed for tests
from sqlwhat.Reporter import Reporter
from sqlwhat.checks import * # imports all SCTs
from sqlalchemy import create_engine
code = "SELECT * FROM artists WHERE id < 100"
state = State(
student_code = code,
solution_code = code,
pre_exercise_code = "",
student_conn = create_engine('sqlite:///'),
solution_conn = create_engine('sqlite:///'),
student_result = {'id': [1,2,3], 'name': ['greg', 'jon', 'martha']},
solution_result = {'id': [1,2,3], 'name': ['toby', 'keith', 'deb']},
reporter = Reporter()
)
# test below passes, since code is equal for student and solution
has_equal_ast(state)
# test below raises a TestFail error, since 'name' col of results
# doesn't match between student and solution results
check_result(state)
# shows error data
state.reporter.build_payload()
# can also be done using a chain
from sqlwhat.sct_syntax import Ex
Ex(state).check_result()
运行单元测试
pytest -m "not backend"
如果您还想运行后端测试,您需要设置一个具有访问 (私有) sqlbackend
存储库的 GITHUB_TOKEN
环境变量。之后,您可以
make install
pytest
测试规则
- 运行查询是后端的工作
- 如果一个测试不运行查询,则不需要后端
- 应该很少的测试需要运行查询
构建文档
安装sqlwhat并运行...
cd docs
make html
项目详情
下载文件
下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。
源分发
sqlwhat-3.9.4.tar.gz (22.4 kB 查看哈希值)
构建分发
sqlwhat-3.9.4-py3-none-any.whl (22.7 kB 查看哈希值)
关闭
sqlwhat-3.9.4.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | cb756931236ad5fc991fef4c74594c8a7ce34590a780505c198c96e65cb98d4d |
|
MD5 | c67805776d8d2b46ee87c18ce818c9c1 |
|
BLAKE2b-256 | 1b694a49e7a1f65389d723148f4c539c735cfedb41d6b29961e401e7d02a688a |
关闭
sqlwhat-3.9.4-py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 1ecb8fd08cf55009344fe72c73c17f1d52b4b221b696afb9f9c84c71e6631509 |
|
MD5 | 8e60bcf2268a0d6bdd1fe8436fe375ca |
|
BLAKE2b-256 | a6a6cd3f8b3b4dc77cfa68191c014a47d1205ed4a03abf920fc386d0d5b30ff6 |