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 --all
docker stop sql-postgres sql-mysql
docker rm sql-postgres sql-mysql
Build and publish:
hatch build
hatch publish
Metadata
Release files for sql-judge-utils 0.1.15
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| sql_judge_utils-0.1.15.tar.gz | 4.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sql_judge_utils-0.1.15-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.5 kB
Release files / sql_judge_utils-0.1.15.tar.gz
| Download URL | sql_judge_utils-0.1.15.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b6518b60ee9bccd2e72ef7f1fda200435d5406c6f82aacdded993c4dd7babf98
|
|
BLAKE2b-256 checksum How to use checksums |
bcc00246e451b5bd1a306607285075874fb91d050a05734690e77eaff9613ac8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.27.2
|
Release files / sql_judge_utils-0.1.15-py3-none-any.whl
| Download URL | sql_judge_utils-0.1.15-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
24c65ef0f977783003b1b37f31a909c1222e75cfd0d8de52af06c1e4ae95935e
|
|
BLAKE2b-256 checksum How to use checksums |
330a8d9fddadf83fc97eb6d901f9550ff335c64e6e3618b9531252562c15881a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.27.2
|
Security for sql-judge-utils 0.1.15
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.