diff options
author | Tomasz Kramkowski <tomasz@kramkow.ski> | 2023-03-24 20:23:03 +0000 |
---|---|---|
committer | Tomasz Kramkowski <tomasz@kramkow.ski> | 2023-03-24 20:25:01 +0000 |
commit | f29abe40fb1eb063ef67651361a2f3f851b25ed1 (patch) | |
tree | 7a325ccfd0dbed16709709e0df88d9e4700ac7c8 | |
parent | d60eaea561d8095cf6f677df0c151ab7e5932e42 (diff) | |
download | paste-f29abe40fb1eb063ef67651361a2f3f851b25ed1.tar.gz paste-f29abe40fb1eb063ef67651361a2f3f851b25ed1.tar.xz paste-f29abe40fb1eb063ef67651361a2f3f851b25ed1.zip |
add tests for paste.db
-rw-r--r-- | poetry.lock | 88 | ||||
-rw-r--r-- | pyproject.toml | 1 | ||||
-rw-r--r-- | tests/__init__.py | 0 | ||||
-rw-r--r-- | tests/test_db.py | 53 |
4 files changed, 141 insertions, 1 deletions
diff --git a/poetry.lock b/poetry.lock index ba230b8..0a66966 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,6 +1,25 @@ # This file is automatically @generated by Poetry and should not be changed by hand. [[package]] +name = "attrs" +version = "22.2.0" +description = "Classes Without Boilerplate" +category = "dev" +optional = false +python-versions = ">=3.6" +files = [ + {file = "attrs-22.2.0-py3-none-any.whl", hash = "sha256:29e95c7f6778868dbd49170f98f8818f78f3dc5e0e37c0b1f474e3561b240836"}, + {file = "attrs-22.2.0.tar.gz", hash = "sha256:c9227bfc2f01993c03f68db37d1d15c9690188323c067c641f1a35ca58185f99"}, +] + +[package.extras] +cov = ["attrs[tests]", "coverage-enable-subprocess", "coverage[toml] (>=5.3)"] +dev = ["attrs[docs,tests]"] +docs = ["furo", "myst-parser", "sphinx", "sphinx-notfound-page", "sphinxcontrib-towncrier", "towncrier", "zope.interface"] +tests = ["attrs[tests-no-zope]", "zope.interface"] +tests-no-zope = ["cloudpickle", "cloudpickle", "hypothesis", "hypothesis", "mypy (>=0.971,<0.990)", "mypy (>=0.971,<0.990)", "pympler", "pympler", "pytest (>=4.3.0)", "pytest (>=4.3.0)", "pytest-mypy-plugins", "pytest-mypy-plugins", "pytest-xdist[psutil]", "pytest-xdist[psutil]"] + +[[package]] name = "black" version = "23.1.0" description = "The uncompromising code formatter." @@ -78,6 +97,33 @@ files = [ ] [[package]] +name = "exceptiongroup" +version = "1.1.1" +description = "Backport of PEP 654 (exception groups)" +category = "dev" +optional = false +python-versions = ">=3.7" +files = [ + {file = "exceptiongroup-1.1.1-py3-none-any.whl", hash = "sha256:232c37c63e4f682982c8b6459f33a8981039e5fb8756b2074364e5055c498c9e"}, + {file = "exceptiongroup-1.1.1.tar.gz", hash = "sha256:d484c3090ba2889ae2928419117447a14daf3c1231d5e30d0aae34f354f01785"}, +] + +[package.extras] +test = ["pytest (>=6)"] + +[[package]] +name = "iniconfig" +version = "2.0.0" +description = "brain-dead simple config-ini parsing" +category = "dev" +optional = false +python-versions = ">=3.7" +files = [ + {file = "iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374"}, + {file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"}, +] + +[[package]] name = "isort" version = "5.12.0" description = "A Python utility / library to sort Python imports." @@ -163,6 +209,22 @@ docs = ["furo (>=2022.12.7)", "proselint (>=0.13)", "sphinx (>=6.1.3)", "sphinx- test = ["appdirs (==1.4.4)", "covdefaults (>=2.2.2)", "pytest (>=7.2.1)", "pytest-cov (>=4)", "pytest-mock (>=3.10)"] [[package]] +name = "pluggy" +version = "1.0.0" +description = "plugin and hook calling mechanisms for python" +category = "dev" +optional = false +python-versions = ">=3.6" +files = [ + {file = "pluggy-1.0.0-py2.py3-none-any.whl", hash = "sha256:74134bbf457f031a36d68416e1509f34bd5ccc019f0bcc952c7b909d06b37bd3"}, + {file = "pluggy-1.0.0.tar.gz", hash = "sha256:4224373bacce55f955a878bf9cfa763c1e360858e330072059e10bad68531159"}, +] + +[package.extras] +dev = ["pre-commit", "tox"] +testing = ["pytest", "pytest-benchmark"] + +[[package]] name = "pyright" version = "1.1.293" description = "Command line wrapper for pyright" @@ -182,6 +244,30 @@ all = ["twine (>=3.4.1)"] dev = ["twine (>=3.4.1)"] [[package]] +name = "pytest" +version = "7.2.2" +description = "pytest: simple powerful testing with Python" +category = "dev" +optional = false +python-versions = ">=3.7" +files = [ + {file = "pytest-7.2.2-py3-none-any.whl", hash = "sha256:130328f552dcfac0b1cec75c12e3f005619dc5f874f0a06e8ff7263f0ee6225e"}, + {file = "pytest-7.2.2.tar.gz", hash = "sha256:c99ab0c73aceb050f68929bc93af19ab6db0558791c6a0715723abe9d0ade9d4"}, +] + +[package.dependencies] +attrs = ">=19.2.0" +colorama = {version = "*", markers = "sys_platform == \"win32\""} +exceptiongroup = {version = ">=1.0.0rc8", markers = "python_version < \"3.11\""} +iniconfig = "*" +packaging = "*" +pluggy = ">=0.12,<2.0" +tomli = {version = ">=1.0.0", markers = "python_version < \"3.11\""} + +[package.extras] +testing = ["argcomplete", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "xmlschema"] + +[[package]] name = "setuptools" version = "67.2.0" description = "Easily download, build, install, upgrade, and uninstall Python packages" @@ -236,4 +322,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "cb7d3903b9ba0286dc6b5affa2ec4c50b2bb193fbf5037cfc4fc99dd64c3657c" +content-hash = "77af368711793c4ad45130892553cfd105662c3947b72c66145b5121b480928e" diff --git a/pyproject.toml b/pyproject.toml index 88238db..dced527 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,6 +14,7 @@ isort = "^5.12.0" black = "^23.1.0" vermin = "^1.5.1" pyright = "^1.1.0" +pytest = "^7" [build-system] requires = ["poetry-core"] diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/__init__.py diff --git a/tests/test_db.py b/tests/test_db.py new file mode 100644 index 0000000..d1b269a --- /dev/null +++ b/tests/test_db.py @@ -0,0 +1,53 @@ +import pytest + +from paste import db + + +@pytest.fixture +def unmigrated_conn(): + with db.connect(":memory:", migrations=None) as conn: + yield conn + + +@pytest.fixture +def conn(): + with db.connect(":memory:") as conn: + yield conn + + +def test_connect_succeeds(conn): + _ = conn + pass + + +def test_migration_succeeds(unmigrated_conn): + conn = unmigrated_conn + assert db.get_version(conn) == 0 + (schema_count,) = conn.execute("SELECT COUNT(*) FROM sqlite_schema").fetchone() + assert schema_count == 0 + db.migrate(conn, db.migrations) + assert db.get_version(conn) == 1 + (schema_count,) = conn.execute("SELECT COUNT(*) FROM sqlite_schema").fetchone() + assert schema_count == 7 + + +hash_testdata = [ + ("", "", True), + (b"", b"", True), + ("a", "a", True), + (b"a", b"a", True), + ("a", "", False), + ("a", "A", False), + ("a", "b", False), + ("a", "aa", False), + (b"a", "a", True), + (b"a", "A", False), +] + + +@pytest.mark.parametrize("a,b,expected", hash_testdata) +def test_hash_behaves_normally(unmigrated_conn, a, b, expected): + (res,) = unmigrated_conn.execute( + "SELECT DATA_HASH(?) == DATA_HASH(?)", (a, b) + ).fetchone() + assert res == (1 if expected else 0) |