Skip to main content

Submission correctness tests for SQL

Project description

sqlwhat

Build Status codecov PyPI version

sqlwhat enables you to write Submission Correctness Tests (SCTs) for interactive SQL exercises on DataCamp.

Installing

pip install sqlwhat     # install from pypi
make install            # install from source

Reference

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

  1. Running queries is the backend's job
  2. If a test doesn't run queries, it doesn't need the backend
  3. Very few tests should run queries

Building Docs

Install sqlwhat and run ..

cd docs
make html

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ds_sqlwhat-3.8.4.tar.gz (520.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ds_sqlwhat-3.8.4-py3-none-any.whl (23.3 kB view details)

Uploaded Python 3

File details

Details for the file ds_sqlwhat-3.8.4.tar.gz.

File metadata

  • Download URL: ds_sqlwhat-3.8.4.tar.gz
  • Upload date:
  • Size: 520.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.7

File hashes

Hashes for ds_sqlwhat-3.8.4.tar.gz
Algorithm Hash digest
SHA256 9196e6a464f965d81cee0007bbd9a00e1038839e20d1b7c095e6835e29a4ebf4
MD5 2ffcc31edc253a17726111d4e91997b1
BLAKE2b-256 e9293b4fa983a3b69d79d7f1ef8336a530e1f19cd5c081544b7414cdae0340ee

See more details on using hashes here.

File details

Details for the file ds_sqlwhat-3.8.4-py3-none-any.whl.

File metadata

  • Download URL: ds_sqlwhat-3.8.4-py3-none-any.whl
  • Upload date:
  • Size: 23.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.7

File hashes

Hashes for ds_sqlwhat-3.8.4-py3-none-any.whl
Algorithm Hash digest
SHA256 42faf02cfeab235c6fc87bfbe3fce9ee92fa9c3498c1c319b6897a22f34fa3ef
MD5 bb9a236587b938b5b547daf0caa1369c
BLAKE2b-256 d4ff1dd1a4c5dc8c894b30db2cb39aadf29b3e8d3ae3280914472bfc78171a18

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page