]> 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 16:22:11 +0000 (18:22 +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 e8370ad69885b83d97c8856f694ef36e4c6220ee..bc74f3daf1dfeba43f40b12c1e9e272c80731263 100644 (file)
@@ -78,6 +78,10 @@ jobs:
   linux:  # {{{
     runs-on: ubuntu-20.04
 
+    env:
+      LIBPQ_VERSION: "14.3"
+      OPENSSL_VERSION: "1.1.1o"
+
     strategy:
       fail-fast: false
       matrix:
@@ -95,7 +99,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
@@ -117,6 +121,7 @@ jobs:
             && auditwheel repair -w {dest_dir} {wheel}
           CIBW_TEST_REQUIRES: ./psycopg[test] ./psycopg_pool
           CIBW_TEST_COMMAND: pytest {project}/tests -m 'not slow' --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'
@@ -124,6 +129,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:
@@ -178,6 +185,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:
@@ -225,6 +234,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 fca2edc2afc50b31f8c0223ba19949a5d3b58fa9..ec25df6855a3bdc877cf93e10bf9f40d7b565abb 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 0e8eb4ffa0fd2841143b3963475f9411d68a694a..b364c135a41cb7ac78940746eafb4a63aefb26ef 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 e859a122afb2e240ad5a262c0c9165a830bdf03e..6206d1215c3dd1d8c8662d91b41c001dffea8199 100644 (file)
@@ -1,5 +1,11 @@
+import os
+
+import pytest
+
 from psycopg import pq
 
+from ..utils import check_libpq_version
+
 
 def test_version():
     rv = pq.version()
@@ -14,3 +20,17 @@ def test_build_version():
         assert pq.__build_version__ and pq.__build_version__ >= 70400
     else:
         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)
index a02827f985c003126769f3e79860d352b86bb987..f4efee816fb49e8c2793521689a52d282d9cf670 100644 (file)
@@ -32,6 +32,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)
@@ -41,7 +46,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}")
 
@@ -56,12 +64,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}