]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
test: verify that we distribute the libpq we want to build
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 14 Jun 2022 14:57:01 +0000 (16:57 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 14 Jun 2022 22:56:07 +0000 (00:56 +0200)
.github/workflows/packages.yml
psycopg/tox.ini
psycopg_c/tox.ini
tests/pq/test_pq.py
tests/utils.py
tools/build/build_libpq.sh

index f1c9f4b3b1ad15d47f2ee7e1483c8e076bd32de4..2297f1357739b22d9e8f0c932740cb2213ab63ee 100644 (file)
@@ -80,6 +80,10 @@ jobs:
   linux:  # {{{
     runs-on: ubuntu-20.04
 
+    env:
+      LIBPQ_VERSION: "14.3"
+      OPENSSL_VERSION: "1.1.1o"
+
     strategy:
       fail-fast: false
       matrix:
@@ -97,7 +101,7 @@ jobs:
         uses: actions/cache@v3
         with:
           path: /tmp/libpq.build
-          key: libpq-14.3-${{ matrix.platform }}-${{ matrix.arch }}-1
+          key: libpq-${{ env.LIBPQ_VERSION }}-${{ matrix.platform }}-${{ matrix.arch }}-1
 
       - name: Create the binary package source tree
         run: python3 ./tools/build/copy_to_binary.py
@@ -120,6 +124,7 @@ jobs:
           CIBW_TEST_REQUIRES: ./psycopg[test] ./psycopg_pool
           CIBW_TEST_COMMAND: >-
             pytest {project}/tests -m 'not slow and not flakey' --color yes
+          CIBW_ENVIRONMENT_PASS_LINUX: LIBPQ_VERSION OPENSSL_VERSION
           CIBW_ENVIRONMENT: >-
             PSYCOPG_IMPL=binary
             PSYCOPG_TEST_DSN='host=172.17.0.1 user=postgres'
@@ -127,6 +132,8 @@ jobs:
             LIBPQ_BUILD_PREFIX=/host/tmp/libpq.build
             PATH="$LIBPQ_BUILD_PREFIX/bin:$PATH"
             LD_LIBRARY_PATH="$LIBPQ_BUILD_PREFIX/lib"
+            PSYCOPG_TEST_WANT_LIBPQ_BUILD=${{ env.LIBPQ_VERSION }}
+            PSYCOPG_TEST_WANT_LIBPQ_IMPORT=${{ env.LIBPQ_VERSION }}
 
       - uses: actions/upload-artifact@v2
         with:
@@ -182,6 +189,8 @@ jobs:
           CIBW_ENVIRONMENT: >-
             PSYCOPG_IMPL=binary
             PSYCOPG_TEST_DSN='dbname=postgres'
+            PSYCOPG_TEST_WANT_LIBPQ_BUILD=">= 14"
+            PSYCOPG_TEST_WANT_LIBPQ_IMPORT=">= 14"
 
       - uses: actions/upload-artifact@v2
         with:
@@ -230,6 +239,8 @@ jobs:
             PSYCOPG_IMPL=binary
             PATH="C:\\Program Files\\PostgreSQL\\14\\bin;$PATH"
             PSYCOPG_TEST_DSN="host=127.0.0.1 user=postgres"
+            PSYCOPG_TEST_WANT_LIBPQ_BUILD=">= 14"
+            PSYCOPG_TEST_WANT_LIBPQ_IMPORT=">= 14"
 
       - uses: actions/upload-artifact@v2
         with:
index 494b53ab324512d305c56c9c47733aba836c2b9b..a1dc963dd77c293c2922274e7243f6942d60362e 100644 (file)
@@ -19,7 +19,7 @@ commands =
     -python -bb -m pytest {posargs}
     -python -bb -m pytest --lf --lfnf=none --no-collect-ok --randomly-seed=last {posargs}
     python -bb -m pytest --lf --lfnf=none --no-collect-ok --randomly-seed=last {posargs}
-passenv = PG* PSYCOPG_TEST_DSN PYTEST_ADDOPTS PSYCOPG_IMPL PIP_CONSTRAINT
+passenv = PG* PSYCOPG_TEST_* PYTEST_ADDOPTS PSYCOPG_IMPL PIP_CONSTRAINT
 extras = test
 deps =
     -e {toxinidir}/../psycopg_pool
index a77cf45e107a0d9a85d2ab84352c03bfe6ca10e8..ca4cfc3ac4eaaba9a158d6613d4d1a6924b489cf 100644 (file)
@@ -8,7 +8,7 @@ commands =
     -python -bb -m pytest {posargs}
     -python -bb -m pytest --lf --lfnf=none --no-collect-ok --randomly-seed=last {posargs}
     python -bb -m pytest --lf --lfnf=none --no-collect-ok --randomly-seed=last {posargs}
-passenv = PG* PSYCOPG_TEST_DSN PYTEST_ADDOPTS PSYCOPG_IMPL PIP_CONSTRAINT
+passenv = PG* PSYCOPG_TEST_* PYTEST_ADDOPTS PSYCOPG_IMPL PIP_CONSTRAINT
 deps =
     -e {toxinidir}/../psycopg[test]
     -e {toxinidir}/../psycopg_pool
index 41e4b72a18428d16e57e28c856f16b1b3eac7a86..d344d121365d0b9bcb049017bd6e2577a1fb1b99 100644 (file)
@@ -1,6 +1,12 @@
+import os
+
+import pytest
+
 import psycopg
 from psycopg import pq
 
+from ..utils import check_libpq_version
+
 
 def test_version():
     rv = pq.version()
@@ -17,6 +23,20 @@ def test_build_version():
         assert False, f"unexpected libpq implementation: {pq.__impl__}"
 
 
+@pytest.mark.skipif("not os.environ.get('PSYCOPG_TEST_WANT_LIBPQ_BUILD')")
+def test_want_built_version():
+    want = os.environ["PSYCOPG_TEST_WANT_LIBPQ_BUILD"]
+    got = pq.__build_version__
+    assert not check_libpq_version(got, want)
+
+
+@pytest.mark.skipif("not os.environ.get('PSYCOPG_TEST_WANT_LIBPQ_IMPORT')")
+def test_want_import_version():
+    want = os.environ["PSYCOPG_TEST_WANT_LIBPQ_IMPORT"]
+    got = pq.version()
+    assert not check_libpq_version(got, want)
+
+
 def test_pipeline_supported():
     # Note: This test is here because pipeline tests are skipped on libpq < 14
     if pq.__impl__ == "python":
index 80ec6afd8cc42e46f1cce37c1c4c1318503d6f92..ec1cba4466f9cdff8f832eb274b3d52265c73e4e 100644 (file)
@@ -34,6 +34,11 @@ def check_server_version(got, want):
 
 
 def _check_version(got, want, whose_version):
+    """Check that a postgres-style version matches a desired spec.
+
+    - The postgres-style version is a number such as 90603 for 9.6.3.
+    - The want version is a spec string such as "> 9.6"
+    """
     # convert 90603 to (9, 6, 3), 120003 to (12, 3)
     got, got_fix = divmod(got, 100)
     got_maj, got_min = divmod(got, 100)
@@ -43,7 +48,10 @@ def _check_version(got, want, whose_version):
         got = (got_maj, got_min, got_fix)
 
     # Parse a spec like "> 9.6"
-    m = re.match(r"^\s*(>=|<=|>|<)\s*(?:(\d+)(?:\.(\d+)(?:\.(\d+))?)?)?\s*$", want)
+    m = re.match(
+        r"^\s*(>=|<=|>|<|==)?\s*(?:(\d+)(?:\.(\d+)(?:\.(\d+))?)?)?\s*$",
+        want,
+    )
     if m is None:
         pytest.fail(f"bad wanted version spec: {want}")
 
@@ -58,12 +66,13 @@ def _check_version(got, want, whose_version):
     else:
         want = (want_maj, want_min, want_fix)
 
-    op = getattr(operator, {">=": "ge", "<=": "le", ">": "gt", "<": "lt"}[m.group(1)])
+    opnames = {">=": "ge", "<=": "le", ">": "gt", "<": "lt", "==": "eq"}
+    op = getattr(operator, opnames[m.group(1) or "=="])
 
     if not op(got, want):
-        revops = {">=": "<", "<=": ">", ">": "<=", "<": ">="}
+        revops = {">=": "<", "<=": ">", ">": "<=", "<": ">=", "==": "!="}
         return (
-            f"skipping test: {whose_version} version is {'.'.join(map(str, got))}"
+            f"{whose_version} version is {'.'.join(map(str, got))}"
             f" {revops[m.group(1)]} {'.'.join(map(str, want))}"
         )
 
index e098ba7c0c2b63cf13fd033f07d9c7e83c7cc168..35a346a6a5c60f944b4e7c67457365d653779249 100755 (executable)
@@ -5,10 +5,17 @@
 set -euo pipefail
 set -x
 
+# Last release: https://www.postgresql.org/ftp/source/
 # IMPORTANT! Change the cache key in packages.yml when upgrading libraries
-postgres_version="14.3"
-openssl_version="1.1.1o"
+postgres_version="${LIBPQ_VERSION:-14.3}"
+
+# last release: https://www.openssl.org/source/
+openssl_version="${OPENSSL_VERSION:-1.1.1o}"
+
+# last release: https://openldap.org/software/download/
 ldap_version="2.6.2"
+
+# last release: https://github.com/cyrusimap/cyrus-sasl/releases
 sasl_version="2.1.28"
 
 export LIBPQ_BUILD_PREFIX=${LIBPQ_BUILD_PREFIX:-/tmp/libpq.build}