# -*- coding: utf-8 -*-
from distutils.core import setup

packages = \
['sqvid']

package_data = \
{'': ['*']}

install_requires = \
['click>=7.0,<8.0',
 'envtoml>=0.1.1,<0.2.0',
 'jinjasql>=0.1.7,<0.2.0',
 'nicetable>=0.7.0,<0.8.0',
 'sqlalchemy>=1.3,<2.0']

entry_points = \
{'console_scripts': ['sqvid = sqvid:console.run']}

setup_kwargs = {
    'name': 'sqvid',
    'version': '0.1.3',
    'description': 'SQVID: Simple sQl Validator of varIous Datasources',
    'long_description': 'SQVID\n=====\n\n.. image:: https://img.shields.io/pypi/v/sqvid.svg\n    :target: https://pypi.python.org/pypi/sqvid\n    :alt: PyPI Status\n\n.. image:: https://img.shields.io/travis/mrshu/sqvid.svg\n    :target: https://travis-ci.org/mrshu/sqvid\n    :alt: Build Status\n\n.. image:: https://coveralls.io/repos/github/mrshu/sqvid/badge.svg?branch=master\n    :target: https://coveralls.io/github/mrshu/sqvid?branch=master\n    :alt: Code coverage Status\n\n.. image:: https://img.shields.io/pypi/l/sqvid.svg\n   :target: ./LICENSE\n   :alt: License Status\n\n\nSQVID, the Simple sQl Validator of varIous Datasources is a framework for\nvalidating any type of data source that can be queried via SQL with the\nhelp of `SQLAlchemy`_. It aims to be a simplified and extensible\ncounterpart to `validation of dbt models`_ or `data assertions of\ndataform`_ that does not require you to use the full `dbt`_ or `dataform`_\nand still ensure your data is automatically validated to be what you expect\nit to be. This allows SQVID to be used on all sorts of data sources: from\nCSVs and spreadsheets to massive databases.\n\nYou can easily use SQVID to serve as a "sanity check" of your processing\npipeline or as a testing framework for your various ETL processes.\n\nInstallation\n------------\n\n.. code::\n\n    pip install sqvid\n\nExample\n-------\n\nLet us consider a database table called ``suppliers`` that would result\nfrom executing the following code snippet in a SQLite database called\n``test_sqvid_db``.\n\n.. code:: sql\n\n    CREATE TABLE `suppliers` (\n      `SupplierID` int NOT NULL,\n      `SupplierName` varchar(255) DEFAULT NULL,\n      `ContactName` varchar(255) DEFAULT NULL,\n      `Address` varchar(255) DEFAULT NULL,\n      `City` varchar(255) DEFAULT NULL,\n      `PostalCode` varchar(255) DEFAULT NULL,\n      `Country` varchar(255) DEFAULT NULL,\n      `Phone` varchar(255) DEFAULT NULL\n    );\n    \n    INSERT INTO `suppliers` (`SupplierID`, `SupplierName`, `ContactName`, `Address`, `City`, `PostalCode`, `Country`, `Phone`) VALUES\n    (1, "Exotic Liquid", "Charlotte Cooper", "49 Gilbert St.", "Londona", "EC1 4SD", "UK", "(171) 555-2222"),\n    (2, "New Orleans Cajun Delights", "Shelley Burke", "P.O. Box 78934", "New Orleans", "70117", "USA", "(100) 555-4822"),\n    (3, "Grandma Kelly\'s Homestead", "Regina Murphy", "707 Oxford Rd.", "Ann Arbor", "48104", "USA", "(313) 555-5735"),\n    (4, "Tokyo Traders", "Yoshi Nagase", "9-8 Sekimai Musashino-shi", "Tokyo", "100", "Japan", "(03) 3555-5011"),\n    (5, "Cooperativa de Quesos \'Las Cabras\'", "Antonio del Valle Saavedra", "Calle del Rosal 4", "Oviedo", "33007", "Spain", "(98) 598 76 54"),\n\n\nIn order to validate that this table contains the data we would expect it\nto, we can put together the following SQVID validation config:\n\n.. code:: toml\n\n   [general]\n   sqla = "sqlite:///test_sqvid_db.sqlite"\n   db_name = \'test_sqvid_db\'\n   \n   [[test_sqvid_db.suppliers.SupplierID]]\n   validator = \'unique\'\n   \n   [[test_sqvid_db.suppliers.SupplierID]]\n   validator = \'in_range\'\n   args = {min = 1, max = 256}\n\n*Note that the the validation config file is fromated using* `TOML`_ *-- you\ncan find a very nice tutorial on this formatting language at*\n`LearnXinYMinutes`_.\n\nThe ``[general]`` section specifies SQLAlchemy connection string in\n``sqla`` and the name of the DB that is going to have its data validated in\n``db_name``.\n\nThe other sections specify the various validations performed on this DB. In\nparticular the table ``suppliers`` and data in its column ``SupplierID`` is\nbeing validated via two validators: the ``unique`` validator ensures that\neach value in this column occurs only once and the ``in_range`` validator\nchecks whether all data points in this column fall withing the ``min`` and\n``max`` range specified via parameters of the same name in ``args``.\n\nOnce we save a validation config like this one into a file (say\n``validate_suppliers.toml``), SQVID validation tests can be invoked in the\nfollowing way:\n\n.. code::\n    \n    sqvid --config ./validate_suppliers.toml\n\nThis should provide output close to the following:\n\n.. code::\n\n    PASSED: Validation on [test_sqvid_db] suppliers.SupplierID of unique\n    PASSED: Validation on [test_sqvid_db] suppliers.SupplierID of in_range({\'min\': 1, \'max\': 256})\n\nSince all tests passed, ``sqvid`` would finish with exit code ``0``.\n\nFailing validations\n~~~~~~~~~~~~~~~~~~~\n\nWhat happens when a SQVID validation test fails? We can easily see that by\nslightly changing the config file from the above:\n\n.. code:: toml\n\n   [general]\n   sqla = "sqlite:///test_sqvid_db.sqlite"\n   db_name = \'test_sqvid_db\'\n   \n   [[test_sqvid_db.suppliers.SupplierID]]\n   validator = \'unique\'\n   \n   [[test_sqvid_db.suppliers.SupplierID]]\n   validator = \'in_range\'\n   args = {min = 3, max = 256}\n\n\nNote that the contents stayed the same, except for the final line where the\n``min`` parameter has been set to ``3``. If we now save this file (to say\n``./validate_suppliers_fail.toml``), we can again execute SQVID tests in a\nsimilar way:\n\n.. code::\n    \n    sqvid --config ./validate_suppliers_fail.toml\n\nThe output should change to something like this:\n\n.. code::\n\n    PASSED: Validation on [test_sqvid_db] suppliers.SupplierID of unique\n    FAILED: Validation on [test_sqvid_db] suppliers.SupplierID of in_range({\'min\': 3, \'max\': 256})\n    Offending 2 rows:\n    +--------------+------------------------------+--------------------+------------------+---------------+--------------+-----------+------------------+\n    |  SupplierID  |  SupplierName                |  ContactName       |  Address         |  City         |  PostalCode  |  Country  |  Phone           |\n    +--------------+------------------------------+--------------------+------------------+---------------+--------------+-----------+------------------+\n    |           1  |  Exotic Liquid               |  Charlotte Cooper  |  49 Gilbert St.  |  Londona      |  EC1 4SD     |  UK       |  (171) 555-2222  |\n    |           2  |  New Orleans Cajun Delights  |  Shelley Burke     |  P.O. Box 78934  |  New Orleans  |  70117       |  USA      |  (100) 555-4822  |\n    +--------------+------------------------------+--------------------+------------------+---------------+--------------+-----------+------------------+\n\n\nAs we would expect, the ``unique`` validation still passed while the\n``in_range`` validation failed on the two rows which have their\n``SupplierID`` outside of the ``[3, 256]`` range.\n\nSince some tests failed, ``sqvid`` would finish with exit code ``1``.\n\nTests\n-----\n\nAs this project makes use of `Poetry <https://poetry.eustace.io/>`_, after\ninstalling it the tests can be ran by executing the following from the\nproject\'s root directory:\n\n.. code:: bash\n\n    poetry run pytest\n\nThey can also be ran with `coverage <https://nose.readthedocs.io/en/latest/plugins/cover.html>`_:\n\n.. code:: bash\n\n    poetry run pytest --cov=envtoml\n\n\nLicense\n-------\n\nCopyright 2019 Marek "mr.Shu" Suppa\n\nLicensed under the Apache License, Version 2.0 (the "License");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an "AS IS" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n\n\n\n.. _SQLAlchemy: https://www.sqlalchemy.org/\n.. _validation of dbt models: https://docs.getdbt.com/docs/testing\n.. _data assertions of dataform: https://docs.dataform.co/guides/assertions/\n.. _dbt: https://getdbt.com\n.. _dataform: https://dataform.co/\n.. _TOML: https://github.com/toml-lang/toml\n.. _LearnXinYMinutes:  https://learnxinyminutes.com/docs/toml/\n',
    'author': 'Marek Suppa',
    'author_email': 'mr@shu.io',
    'url': 'https://github.com/mrshu/sqvid',
    'packages': packages,
    'package_data': package_data,
    'install_requires': install_requires,
    'entry_points': entry_points,
    'python_requires': '>=3.6,<4.0',
}


setup(**setup_kwargs)
