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 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()

Running unit tests

pytest -m "not backend"

If you also want to run the backend tests, you need psycopg2. to install psycopg2 in a virtualenv, I needed to run..

env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip install --no-cache psycopg2

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

sqlwhat-2.2.2.tar.gz (6.1 kB view details)

Uploaded Source

File details

Details for the file sqlwhat-2.2.2.tar.gz.

File metadata

  • Download URL: sqlwhat-2.2.2.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for sqlwhat-2.2.2.tar.gz
Algorithm Hash digest
SHA256 bffa6c6fb7f90b9af47f784f0a9b1f2f2a45f5f19e95ea5dfa2ef3cee401f4ad
MD5 b7bca63ef093ab2289f7c687993ee642
BLAKE2b-256 5a6dee135840f2d7aa065eb3ce6816395988c49c25f19d39870ba452bce95d03

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