Testing framework for BigQuery SQL.
What is this?
BigQuery enables us to execute “super-fast SQL queries using the processing power of Google’s infrastructure”.
However, testing query-based data pipelines sometimes become depressing work, because:
SQL itself takes more responsibility in data transformation logic, and the glue code layer like Python scripts(which is relatively easy to test) doesn’t.
We can’t imitate BigQuery infrastructure easily. There’s no Docker image, StandardSQL has many unique syntaxes which can’t be used on other RDBMS, and above all, Google has huge computing resources than ours.
BQUnit solves this problem, by managing your test data preparation on your BigQuery data set, which is isolated from your production environment.
Usage
First, instantiate BQUnit object:
bqunit = BQUnit(project_id='test-env-123456', dataset_name='bqunit') # If Application Default Credential is set, project id is not required. bqunit = BQUnit(dataset_name='bqunit')
And then, mockup your tables by a fixture() method call:
bqunit.fixture(
table_name='your-production-123456.foo.bar',
statement="""
select 1 as col1, 'str_1' as col2, true as col3
union all
select 2, 'str_2', false
""")
You don’t need to know where to insert your test data. You just need to specify your production table name here.
Testing will be like this:
tested_query = """ select col1, col2 from `your-production-123456.foo.bar` foo where col1 = 1 """ query_result = bqunit.test_query(tested_query) assert query_result.total_rows == 1
BQUnit execute your query on test data set, which is created when you called the fixture() method, so you can predict its result set correctly, and make assertions.
Note that query_result will be RowIterator object of google-cloud-bigquery library. see also google-cloud-bigquery documentation.
Release files for bqunit 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| bqunit-0.1.3.tar.gz | 4.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| bqunit-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size:10.2 kB
Release files / bqunit-0.1.3.tar.gz
| Download URL | bqunit-0.1.3.tar.gz |
|---|---|
| Size | 4.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
36fa89354ad9d080016f5e3361a739ec15661f4645666ff6bb20ae46525663c0
|
|
BLAKE2b-256 checksum How to use checksums |
ed99f9c6a4b0e0d6bb2922e6ad84160f9d9e0ea42f1c3f6077d009f25fb8ec27
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.5 CPython/3.7.1 Darwin/19.3.0
|
Release files / bqunit-0.1.3-py3-none-any.whl
| Download URL | bqunit-0.1.3-py3-none-any.whl |
|---|---|
| Size | 5.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bb9c52606e0a2a521a6452cd9f154e8fd50419a37f953127c23a4d3380ef8ced
|
|
BLAKE2b-256 checksum How to use checksums |
cd01aff58dc7d459bd57df00ff2cd0568f01391137a0e2e234699ec4d12d97db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.5 CPython/3.7.1 Darwin/19.3.0
|