Skip to main content

Minimum test flamework for sql

Project description

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]

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.

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

tdsql-0.0.4.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

tdsql-0.0.4-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file tdsql-0.0.4.tar.gz.

File metadata

  • Download URL: tdsql-0.0.4.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.4 Linux/5.13.0-1023-azure

File hashes

Hashes for tdsql-0.0.4.tar.gz
Algorithm Hash digest
SHA256 34434e0ad00aa2b7b1ff1c8f89a7c8a51b2782da832a7b573f7a2598a5e38fdd
MD5 5198fc95236e3d15169ad508b6e47804
BLAKE2b-256 286f016a967adf5dde1b2a20f6b3d4912f0148ef191356f2b83174377b422edd

See more details on using hashes here.

File details

Details for the file tdsql-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: tdsql-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.4 Linux/5.13.0-1023-azure

File hashes

Hashes for tdsql-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1d0d7e4ba0ee3480bbc2c46ebed5c8d018800d1a4c873024ac50962eefa64c58
MD5 16f08114ad3a1516566984d346ce9dcc
BLAKE2b-256 45b27cd10d9f48b585c22c897b6f25a7b5c6fa2c5cc5fc0d67c986c5da49f1d0

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