Skip to main content

Utilities for writing tests for Quera SQL judge.

Project description

sql-judge-utils

Utilities for writing Python unit tests for version 2 of the Quera SQL judge.

Installation

pip install sql-judge-utils # or git+https://github.com/QueraTeam/sql-judge-utils

Usage

Import one of database classes:

# PostgreSQL:
from sql_judge_utils.postgresql import PostgresqlDatabase as Database

# MySQL:
from sql_judge_utils.mysql import MysqlDatabase as Database

Define database instances:

db1 = Database("db1")
db2 = Database("db2")

Optional arguments:

Argument PostgreSQL default MySQL default
host "postgresql" "mysql"
port 5432 3306
username "postgres" "root"
password None None

WARNING: Don't override the default values if you're writing tests for Quera SQL judge.

Create database:

db1.create()

Drop database:

db1.drop()

Init data (run SQL command without fetching results) with SQL string or SQL file path:

db1.init(sql_string)
# or
db1.initf(sql_file_path)

Run query and fetch the results:

col_names, records = db1.run_query(sql_string)

Compare two result of run_query:

status, message = Database.compare_query_result(col_names_1, records_1, col_names_2, records_2)

Compare two database instances:

status, message = db1.is_equal(db2)

Compare two database instances on a table:

status, message = db1.is_equal_on_table(db2, table_name)

Submission parser

Use the parser to extract queries from a submission file:

from sql_judge_utils.parser import get_queries, get_query
submission_file_path = 'path/to/submission.sql'
queries = get_queries(submission_file_path)
# or
submission_file_path = 'path/to/submission.sql'
query_number = 2
query = get_query(submission_file_path, query_number)

Development

Install Hatch and pre-commit hooks:

pipx install hatch
pipx install pre-commit
pre-commit install

Before running the tests, start a MySQL and a PostgreSQL instance:

docker run --name sql-postgres -e POSTGRES_PASSWORD=password -p "127.0.0.1:15432:5432" -d postgres postgres -c log_statement=all
docker run --name sql-mysql -e MYSQL_ROOT_PASSWORD=password -p "127.0.0.1:13306:3306" -d mysql

Run the tests and stop the database instances:

hatch test
docker stop sql-postgres sql-mysql
docker rm sql-postgres sql-mysql

Build and publish:

hatch build
hatch publish

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

sql_judge_utils-0.1.11.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

sql_judge_utils-0.1.11-py2.py3-none-any.whl (6.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file sql_judge_utils-0.1.11.tar.gz.

File metadata

  • Download URL: sql_judge_utils-0.1.11.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.2

File hashes

Hashes for sql_judge_utils-0.1.11.tar.gz
Algorithm Hash digest
SHA256 3113b4c7fc88694f345185cc65f8086d670046165a982f60ad45d63aa53e1810
MD5 67307018f4b4ce622ed83522722a6f9a
BLAKE2b-256 33505ddbf2fc90b134def88ed0fbe31241a3a6980f0a9e10e52007db1b12d06b

See more details on using hashes here.

File details

Details for the file sql_judge_utils-0.1.11-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for sql_judge_utils-0.1.11-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 40ea4c6b1613122d5f8c1af416820fad3a76df5179169b4633f0c922c1e2d28c
MD5 43273f362bb6340f5e22666cde9d7c53
BLAKE2b-256 8a275d071d66db9c6b851d32f97e83c1ae51dcf6f80870ff4e2da807396fa7c0

See more details on using hashes here.

Supported by

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