Test Driven SQL
Tdsql is a minimum test flamework for sql. You can replace any part of sql and check if the result is as expected. You can define test cases as yaml file.
Install
Currently, only bigquery is supported.
pip install 'tdsql[bigquery]'
Authentication
Run either of these commands.
gcloud auth application-default login
# If you want to use service account
# export GOOGLE_APPLICATION_CREDENTIALS=/path/to/keyfile.json
Quick start
Save these files in your working directory.
# ./tdsql.yaml
database: bigquery
tests:
- filepath: ./hello-world.sql
replace:
data: |
SELECT * FROM UNNEST([
STRUCT('2020-01-01' AS dt, 100 AS id),
STRUCT('2020-01-01', 100),
STRUCT('2020-01-01', 200)
])
master: |
FROM (
SELECT 100 AS id, 1 AS category
)
expected: |
SELECT * FROM UNNEST([
STRUCT('2020-01-01' AS dt, 1 AS category, 2 AS cnt),
STRUCT('2020-01-01', NULL, 1)
])
-- ./hello-world.sql
WITH data AS (
-- tdsql-start: data
SELECT dt, id
FROM `data_table`
-- tdsql-end: data
), master AS (
SELECT id, category
FROM `master_table` -- tdsql-line: master
)
SELECT
dt,
category,
COUNT(*) AS cnt
FROM data INNER JOIN master USING(id)
GROUP BY 1, 2
Then, run this command. You'll see an error message.
tdsql
Fix hello-world.sql and run tdsql again,
you won't see any error message this time.
- FROM data INNER JOIN master USING(id)
+ FROM data LEFT JOIN master USING(id)
Quite simple, isn't it?
Examples
Heavily documented sample codes are here.
Feedback
If you find any bugs, please feel free to create an issue.
Metadata
Release files for tdsql 0.0.5
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 | Actions |
|---|---|---|---|---|
| tdsql-0.0.5.tar.gz | 8.4 kB | Without provenance | Details for tdsql-0.0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tdsql-0.0.5-py3-none-any.whl | Python 3 | none | any | Details for tdsql-0.0.5-py3-none-any.whl |
Total release size: 17.9 kB
Release files / tdsql-0.0.5.tar.gz
| Download URL | tdsql-0.0.5.tar.gz |
|---|---|
| Size | 8.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3d198f751323d244d7e82bdc5cc861dee0453da13e14082bc78ba4ed478c8ec6
|
|
BLAKE2b-256 checksum How to use checksums |
922d6a576e3aa8744665311fd095b8e21482883a4dc28ba4a337be362dd30d8e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.13 CPython/3.10.4 Linux/5.13.0-1023-azure
|
Release files / tdsql-0.0.5-py3-none-any.whl
| Download URL | tdsql-0.0.5-py3-none-any.whl |
|---|---|
| Size | 9.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
33c66dcdc49733111dd1bf8a52711a87da74bc36e33c005f2b7bedafe452734a
|
|
BLAKE2b-256 checksum How to use checksums |
3dc96afd86441961b41c49e6a9e41b43acbddaeb201e7ba21ba18d9aad153d5c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.13 CPython/3.10.4 Linux/5.13.0-1023-azure
|
Security for tdsql 0.0.5
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.