sql的提交正确性测试
sqlwhat的Python项目详细描述
SqlWhat
sqlwhat
使您能够为datacamp上的交互式sql练习编写提交正确性测试(sct)。
- 如果你是新来的教学数据营,看看https://authoring.datacamp.com。
- 如果您想了解什么是sct以及它们是如何工作的,请特别访问this article。
- 有关为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的问题
请提出有关响应式解析器repo的问题:
基本用途
fromsqlwhat.StateimportState# State holds info needed for testsfromsqlwhat.ReporterimportReporterfromsqlwhat.checksimport*# imports all SCTsfromsqlalchemyimportcreate_enginecode="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 solutionhas_equal_ast(state)# test below raises a TestFail error, since 'name' col of results# doesn't match between student and solution resultscheck_result(state)# shows error datastate.reporter.build_payload()# can also be done using a chainfromsqlwhat.sct_syntaximportExEx(state).check_result()
运行单元测试
pytest -m "not backend"
如果还想运行后端测试,则需要设置一个具有(私有)sqlbackend
存储库访问权限的GITHUB_TOKEN
环境变量。
在此之后,您可以:
make install pytest
测试规则
- 运行查询是后端的工作
- 如果测试不运行查询,则不需要后端
- 很少有测试应该运行查询
构建文档
安装sqlwhat并运行..
cd docs
make html