{ "info": { "author": "Elad Kehat", "author_email": "eladkehat@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3.7", "Topic :: Database", "Topic :: Software Development :: Testing", "Typing :: Typed" ], "description": "# Lathorp - PostgreSQL Testing Fixtures\n\nLathorp provides handy **pytest fixtures** for test code that involves access to a **PostgreSQL** database.\n\nFor example, if the code under test writes data to a database, or queries it for data, you want to write tests to see\nthat it writes and reads the data as you expect.\nYou need an isolated and controlled environment for testing, so you need to set up a temporary database just for\ntesting and fill it up with known data.\nSetting up a new database is a relatively time consuming operation that slows your tests down. You want to do this\njust once per testing session and let multiple tests share the same temporary database instance.\nHowever, many tests should be isolated from each other - you don't want side effects from a test (say, data written to\nthe database) leaking to another test. The solution is to write known data before each test and delete it all after\nthe test has finished.\n\n\n## The Fixtures\n\nThe `pg` fixture is a session-scoped fixture that creates a new temporary database once per test session and deletes\nit after the session is done.\n\nThe `pg_connect` fixture is a function-scoped fixture that you use to establish a connection to the temporary database.\nYou can optionally load data into the database before the test begins, by pointing to data files that PostgreSQL can\nread. The data is automatically deleted after the test function returns, so that it doesn't leak to other tests that\nmay expect different data.\n\n## Utility Functions\n\nA utility function called `load_schema_definitions` can be used to create the database structure by reading SQL DDL\nfiles that you provide. Embed it in your own session-scoped fixture and call that together with `pg_connect`.\n\nAnother utility, `copy_data`, copies data from files in CSV or text format (as supported by PostgreSQL).\nIt can be used directly, or automatically by passing a path to the files to the `pg_connect` fixture.\n\nA third utility, `delete_data`, deletes all data from a set of tables.\nIt is used automatically by `pg_connect` to remove data from tables that it loaded with `copy_data`.\nYou can also use it directly to clean up any changes made by your test.\n\n\n## Using Lathorp in Your Project\n\n1. Include the `lathorp` package with the development packages of your projects.\nWith `pipenv`:\n```bash\npipenv install --dev lathorp\n```\n\n1. Import fixtures from `lathorp` in your tests. You can also import them in `conftest.py` to make them available to all\nyour tests. See `tests/conftest.py` in this project for an example.\n\n1. Add either `pg` or `pg_connect` as arguments to your test functions, as shown below. There's no point in adding\nboth, since `pg_connect` itself uses `pg`.\n```python\ndef my_test(pg_connect):\n \"\"\"A test that connects to the temporary test database.\"\"\"\n with pg_connect() as conn:\n with conn.cursor() as cursor:\n cursor.execute(\"SELECT 'Hello, world!' AS hello;\")\n```\nFor more examples, see `tests/test_fixtures.py` in this project.\n\n1. Lathorp truly shines when you use it together with schema definitions (SQL DDL) files and test data files (CSV or\nPostgreSQL-readable text).\nCreate a session-scoped fixture that calls `load_schema_definitions` and give it the path to your schema definitions.\nThen use this fixture along with `pg_connect` and give it the path to your data files.\n\n ```python\n # In conftest.py\n import pathlib\n from lathorp import load_schema_definitions\n from lathorp.fixtures import pg\n from lathorp.fixtures import pg_connect\n\n def init_schema(pg):\n load_schema_definitions(pathlib.Path('path/to/my/ddl/file_or_directory'))\n\n # In your test module\n def test_my_fun(init_schema, pg_connect):\n conn = pg_connect(pathlib.Path('path/to/my_table.csv')) # loads data into my_table\n with conn.cursor() as cursor:\n cursor.execute('SELECT * FROM my_table;')\n ```\n Now every test can have access to an initialized database with test-specific data.\n\n\n## Why \"Lathorp?\n\nThe name is a reference to [Dr. Emmett Lathorp \"Doc\" Brown][Emmett Brown on Wikipedia],\nthe crazy scientist and inventor of the DeLorean time machine from _Back to the Future_ trilogy.\n\nThe Lathorp library too lets you go back in time to a fresh database after every test.\n\n[Emmett Brown on Wikipedia]: https://en.wikipedia.org/wiki/Emmett_Brown\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/eladkehat/lathorp", "keywords": "pytest postgresql pgsql testing", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "lathorp", "package_url": "https://pypi.org/project/lathorp/", "platform": "", "project_url": "https://pypi.org/project/lathorp/", "project_urls": { "Homepage": "https://github.com/eladkehat/lathorp" }, "release_url": "https://pypi.org/project/lathorp/0.2.0/", "requires_dist": [ "psycopg2-binary (>=2.7)", "pytest (>=4.3)", "testing.postgresql (>=1.3)" ], "requires_python": ">=3.7", "summary": "pytest fixtures for PostgreSQL", "version": "0.2.0" }, "last_serial": 4984228, "releases": { "0.1.3": [ { "comment_text": "", "digests": { "md5": "0b1d413a6f53759d72480a079d8f88e5", "sha256": "074bd416c14b235289dae64a9aa37c6d9eb020824478f52b4a18ae87b5b10b95" }, "downloads": -1, "filename": "lathorp-0.1.3-py3-none-any.whl", "has_sig": false, "md5_digest": "0b1d413a6f53759d72480a079d8f88e5", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7", "size": 6649, "upload_time": "2019-03-16T18:05:38", "url": "https://files.pythonhosted.org/packages/b8/50/7afeb36e8067adcab491f987bac52cd047830a81502608154d81ce726317/lathorp-0.1.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "9c4b4e5d6c14f1d763c5135224dcef9c", "sha256": "ae5ef0401afc1879338cee3a1df9c9a826803d9b6d6f8cf70117b97331ed2ac4" }, "downloads": -1, "filename": "lathorp-0.1.3.tar.gz", "has_sig": false, "md5_digest": "9c4b4e5d6c14f1d763c5135224dcef9c", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7", "size": 9104, "upload_time": "2019-03-16T18:05:39", "url": "https://files.pythonhosted.org/packages/fa/27/0ea5e69d66a8b97cb61b7a4e164e6c8092a4f35eb3a497cf3bc72710cf51/lathorp-0.1.3.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "b46708d66fee20ea2d992298a4e7f3f0", "sha256": "0acf7bc3268191974573f16f0e27d74858a257bb80174db9b02f9668d63e2fe4" }, "downloads": -1, "filename": "lathorp-0.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "b46708d66fee20ea2d992298a4e7f3f0", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7", "size": 7015, "upload_time": "2019-03-25T19:21:53", "url": "https://files.pythonhosted.org/packages/92/0f/766e33131638f81b5b93ce83db4b7d248158284359633fe518d3b7f49a69/lathorp-0.2.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "646f3279f3d7f4f1e885b4adeb516fe8", "sha256": "a08db71302b81b112b9e0b8386b908b7e2b41e0e7158a4230ebb04cb337ab5bf" }, "downloads": -1, "filename": "lathorp-0.2.0.tar.gz", "has_sig": false, "md5_digest": "646f3279f3d7f4f1e885b4adeb516fe8", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7", "size": 9646, "upload_time": "2019-03-25T19:21:54", "url": "https://files.pythonhosted.org/packages/ed/ca/1d5decdea0ea179e45d3a5b9e23c5e3dce28260a3301b96e7fdfe221c9f1/lathorp-0.2.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "b46708d66fee20ea2d992298a4e7f3f0", "sha256": "0acf7bc3268191974573f16f0e27d74858a257bb80174db9b02f9668d63e2fe4" }, "downloads": -1, "filename": "lathorp-0.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "b46708d66fee20ea2d992298a4e7f3f0", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7", "size": 7015, "upload_time": "2019-03-25T19:21:53", "url": "https://files.pythonhosted.org/packages/92/0f/766e33131638f81b5b93ce83db4b7d248158284359633fe518d3b7f49a69/lathorp-0.2.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "646f3279f3d7f4f1e885b4adeb516fe8", "sha256": "a08db71302b81b112b9e0b8386b908b7e2b41e0e7158a4230ebb04cb337ab5bf" }, "downloads": -1, "filename": "lathorp-0.2.0.tar.gz", "has_sig": false, "md5_digest": "646f3279f3d7f4f1e885b4adeb516fe8", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7", "size": 9646, "upload_time": "2019-03-25T19:21:54", "url": "https://files.pythonhosted.org/packages/ed/ca/1d5decdea0ea179e45d3a5b9e23c5e3dce28260a3301b96e7fdfe221c9f1/lathorp-0.2.0.tar.gz" } ] }