pytest-bq


Namepytest-bq JSON
Version 0.0.4 PyPI version JSON
download
home_pageNone
SummaryBigQuery fixtures and fixture factories for Pytest.
upload_time2024-05-08 18:37:13
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseCopyright (c) 2024 Sam Pegler Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords tests pytest fixture bq
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## Pytest BQ

This is a pytest plugin in similar vein to [pytest-postgres](https://github.com/ClearcodeHQ/pytest-postgresql) and [pytest-kafka](https://pypi.org/project/pytest-kafka/). It runs a local version of bigquery that you can use throughout your test suite. 

This would have been much more painful without [Mirakuru](https://github.com/ClearcodeHQ/mirakuru)
and [bigquery-emulator](https://github.com/goccy/bigquery-emulator); this is a simple wrapper around
those tools.


### Installation

This tool requires you to have a copy of the `bigquery-emulator` binary somewhere on your path.
Depending upon your architecture you'll need a different version of the tool.

```sh
wget https://github.com/goccy/bigquery-emulator/releases/download/v0.6.1/bigquery-emulator-linux-amd64
mv bigquery-emulator-linux-amd64 /usr/local/bin/bigquery-emulator
```

To install this library:

```sh
pip install pytest-bq
```


### Demo

```python
# conftest.py
from pytest_bq.factories import client as bq_client
from pytest_bq.factories import proc as bq_process

# Create a process and a local client that targets that process.
bq_proc = bq_process.bq_proc(executable='/usr/local/bin/bigquery-emulator', project_id='test')
bqlocal = bq_client.bqlocal("bq_proc")

# tests/test_bq.py
from google.cloud import bigquery
from pytest_bq.executor.process import BQExecutor


def test_can_list_datasets(bq_proc: BQExecutor, bqlocal: bigquery.Client) -> None:
    """MVP to ensure everything works."""
    test_dataset = "test_base"
    bqlocal.create_dataset(test_dataset)
    datasets = [x.full_dataset_id for x in bqlocal.list_datasets()]

    assert test_dataset in datasets
```


### Contributing

PRs are accepted.

```sh
# Install the dependencies with:
pip install .[test]
# Install pre-commit hooks.
pre-commit install
# Validate everything passes.
pre-commit run --all
# Run the tests.
pytest tests/
```


### TODOs

* Validate `data_from_yaml` files.
* Tools for dummy data generation.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pytest-bq",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "tests, pytest, fixture, bq",
    "author": null,
    "author_email": "Sam Pegler <sam@sampegler.co.uk>",
    "download_url": "https://files.pythonhosted.org/packages/d5/9b/c8062bcc61c35fb2b4bade04a127986929766436447c3b24cf2d44ec212b/pytest_bq-0.0.4.tar.gz",
    "platform": null,
    "description": "## Pytest BQ\n\nThis is a pytest plugin in similar vein to [pytest-postgres](https://github.com/ClearcodeHQ/pytest-postgresql) and [pytest-kafka](https://pypi.org/project/pytest-kafka/). It runs a local version of bigquery that you can use throughout your test suite. \n\nThis would have been much more painful without [Mirakuru](https://github.com/ClearcodeHQ/mirakuru)\nand [bigquery-emulator](https://github.com/goccy/bigquery-emulator); this is a simple wrapper around\nthose tools.\n\n\n### Installation\n\nThis tool requires you to have a copy of the `bigquery-emulator` binary somewhere on your path.\nDepending upon your architecture you'll need a different version of the tool.\n\n```sh\nwget https://github.com/goccy/bigquery-emulator/releases/download/v0.6.1/bigquery-emulator-linux-amd64\nmv bigquery-emulator-linux-amd64 /usr/local/bin/bigquery-emulator\n```\n\nTo install this library:\n\n```sh\npip install pytest-bq\n```\n\n\n### Demo\n\n```python\n# conftest.py\nfrom pytest_bq.factories import client as bq_client\nfrom pytest_bq.factories import proc as bq_process\n\n# Create a process and a local client that targets that process.\nbq_proc = bq_process.bq_proc(executable='/usr/local/bin/bigquery-emulator', project_id='test')\nbqlocal = bq_client.bqlocal(\"bq_proc\")\n\n# tests/test_bq.py\nfrom google.cloud import bigquery\nfrom pytest_bq.executor.process import BQExecutor\n\n\ndef test_can_list_datasets(bq_proc: BQExecutor, bqlocal: bigquery.Client) -> None:\n    \"\"\"MVP to ensure everything works.\"\"\"\n    test_dataset = \"test_base\"\n    bqlocal.create_dataset(test_dataset)\n    datasets = [x.full_dataset_id for x in bqlocal.list_datasets()]\n\n    assert test_dataset in datasets\n```\n\n\n### Contributing\n\nPRs are accepted.\n\n```sh\n# Install the dependencies with:\npip install .[test]\n# Install pre-commit hooks.\npre-commit install\n# Validate everything passes.\npre-commit run --all\n# Run the tests.\npytest tests/\n```\n\n\n### TODOs\n\n* Validate `data_from_yaml` files.\n* Tools for dummy data generation.\n",
    "bugtrack_url": null,
    "license": "Copyright (c) 2024 Sam Pegler  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "BigQuery fixtures and fixture factories for Pytest.",
    "version": "0.0.4",
    "project_urls": {
        "Bug Tracker": "https://github.com/Poogles/pytest-bq/issues",
        "Source": "https://github.com/Poogles/pytest-bq"
    },
    "split_keywords": [
        "tests",
        " pytest",
        " fixture",
        " bq"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c89abe6ce7015d69c8e7bd3d25f024d476eaa8c78ad8814414d4a571ee3ef9ec",
                "md5": "cff6b5adbf84fd761c803f6d2ac93698",
                "sha256": "0182e9ad7719d971c22aaa1f6cefc418e2a84c6eb836bfc11ca480341f59320d"
            },
            "downloads": -1,
            "filename": "pytest_bq-0.0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "cff6b5adbf84fd761c803f6d2ac93698",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 8949,
            "upload_time": "2024-05-08T18:37:12",
            "upload_time_iso_8601": "2024-05-08T18:37:12.566639Z",
            "url": "https://files.pythonhosted.org/packages/c8/9a/be6ce7015d69c8e7bd3d25f024d476eaa8c78ad8814414d4a571ee3ef9ec/pytest_bq-0.0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d59bc8062bcc61c35fb2b4bade04a127986929766436447c3b24cf2d44ec212b",
                "md5": "7692f366357e4e94405fa8bea75db74b",
                "sha256": "c1bc378f75474dc3b35c6808b1151415a257848116c5a4c85f4a4c7305aab6f9"
            },
            "downloads": -1,
            "filename": "pytest_bq-0.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "7692f366357e4e94405fa8bea75db74b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 8736,
            "upload_time": "2024-05-08T18:37:13",
            "upload_time_iso_8601": "2024-05-08T18:37:13.791709Z",
            "url": "https://files.pythonhosted.org/packages/d5/9b/c8062bcc61c35fb2b4bade04a127986929766436447c3b24cf2d44ec212b/pytest_bq-0.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-08 18:37:13",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Poogles",
    "github_project": "pytest-bq",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pytest-bq"
}
        
Elapsed time: 0.61376s