Submission correctness tests for SQL
Project description
sqlwhat
sqlwhat
enables you to write Submission Correctness Tests (SCTs) for interactive SQL exercises on DataCamp.
- If you are new to teaching on DataCamp, check out https://authoring.datacamp.com.
- If you want to learn what SCTs are and how they work, visit this article specifically.
- For more information about writing SCTs for SQL exercises, consult https://sqlwhat.readthedocs.io.
Installing
pip install sqlwhat # install from pypi
make install # install from source
Reference
- API Docs: https://sqlwhat.readthedocs.io
- AST viewer: https://ast-viewer.datacamp.com
- Extensions: https://github.com/datacamp/sqlwhat-ext
Raising issues with how SQL is parsed
Please raise an issue on the respsective parser repo:
Basic Use
from tcs_sqlwhat2.State import State # State holds info needed for tests
from tcs_sqlwhat2.Reporter import Reporter
from tcs_sqlwhat2.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 tcs_sqlwhat2.sct_syntax import Ex
Ex(state).check_result()
Running unit tests
pytest -m "not backend"
If you also want to run the backend tests, you need to set a GITHUB_TOKEN
environment variable with access to the (private) sqlbackend
repository.
After this, you can:
make install
pytest
Rules of testing
- Running queries is the backend's job
- If a test doesn't run queries, it doesn't need the backend
- Very few tests should run queries
Building Docs
Install sqlwhat and run ..
cd docs
make html
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
tcs_sqlwhat2-3.8.1.tar.gz
(23.0 kB
view details)
File details
Details for the file tcs_sqlwhat2-3.8.1.tar.gz
.
File metadata
- Download URL: tcs_sqlwhat2-3.8.1.tar.gz
- Upload date:
- Size: 23.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b1b77b77f5f29bf87c6cbe1bf2bcaff22d51f080d578254d51521c61d8ddeef |
|
MD5 | bf25ae1896e23d3dc297096ea5c1dfe8 |
|
BLAKE2b-256 | 31d8d20ac70ed886803c3549f8fd8df3d4ba2a44d034d880dab66ce1605e0c31 |