Skip to content

Commit

Permalink
i
Browse files Browse the repository at this point in the history
  • Loading branch information
tlocke committed Sep 29, 2024
1 parent 761c74c commit 288f67f
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 171 deletions.
105 changes: 3 additions & 102 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
postgresql-version: [16, 15, 14, 13, 12]
postgresql-version: [17, 16, 15, 14, 13, 12]

container:
image: python:${{ matrix.python-version }}
Expand All @@ -31,6 +31,7 @@ jobs:
--health-interval 10s
--health-timeout 5s
--health-retries 5
--mount type=bind,source="test/postgres_server/init_scripts",target=/docker-entrypoint-initdb.d \
steps:
- uses: actions/checkout@v4
Expand All @@ -39,109 +40,9 @@ jobs:
git config --global --add safe.directory "$GITHUB_WORKSPACE"
python -m pip install --no-cache-dir --upgrade pip
pip install --no-cache-dir --root-user-action ignore pytest pytest-mock pytest-benchmark pytz .
- name: Set up Postgresql
run: |
apt-get update
apt-get install --yes --no-install-recommends postgresql-client
psql -c "CREATE EXTENSION hstore;"
psql -c "SELECT pg_reload_conf()"
- name: Test with pytest
run: |
python -m pytest -x -v -W error --ignore=test/dbapi/auth/ --ignore=test/legacy/auth/ --ignore=test/native/auth/ test --ignore=test/test_readme.py
auth-test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11"]
postgresql-version: ["16", "12"]
auth-type: [md5, gss, password, scram-sha-256]

container:
image: python:${{ matrix.python-version }}
env:
PGHOST: postgres
PGPASSWORD: postgres
PGUSER: postgres
PIP_ROOT_USER_ACTION: ignore

services:
postgres:
image: postgres:${{ matrix.postgresql-version }}
env:
POSTGRES_PASSWORD: postgres
POSTGRES_HOST_AUTH_METHOD: ${{ matrix.auth-type }}
POSTGRES_INITDB_ARGS: "${{ matrix.auth-type == 'scram-sha-256' && '--auth-host=scram-sha-256' || '' }}"
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"
python -m pip install --no-cache-dir --upgrade pip
pip install --no-cache-dir pytest pytest-mock pytest-benchmark pytz .
- name: Test with pytest
run: |
python -m pytest -x -v -W error test/dbapi/auth/test_${{ matrix.auth-type }}.py test/native/auth/test_${{ matrix.auth-type }}.py test/legacy/auth/test_${{ matrix.auth-type }}.py
ssl-test:
runs-on: ubuntu-latest

strategy:
matrix:
auth-type: [md5, scram-sha-256]

services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
POSTGRES_HOST_AUTH_METHOD: ${{ matrix.auth-type }}
POSTGRES_INITDB_ARGS: "${{ matrix.auth-type == 'scram-sha-256' && '--auth-host=scram-sha-256' || '' }}"
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

steps:
- name: Configure Postgres
env:
PGPASSWORD: postgres
PGUSER: postgres
PGHOST: localhost
run: |
sudo apt update
sudo apt install --yes --no-install-recommends postgresql-client
psql -c "ALTER SYSTEM SET ssl = on;"
psql -c "ALTER SYSTEM SET ssl_cert_file = '/etc/ssl/certs/ssl-cert-snakeoil.pem'"
psql -c "ALTER SYSTEM SET ssl_key_file = '/etc/ssl/private/ssl-cert-snakeoil.key'"
psql -c "SELECT pg_reload_conf()"
- name: Check out repository code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest pytest-mock pytest-benchmark pytz .
- name: SSL Test
env:
PGPASSWORD: postgres
USER: postgres
run: |
python -m pytest -x -v -W error test/dbapi/auth/test_${{ matrix.auth-type}}_ssl.py test/native/auth/test_${{ matrix.auth-type}}_ssl.py test/legacy/auth/test_${{ matrix.auth-type}}_ssl.py
python -m pytest -x -v -W error test --ignore=test/test_readme.py
static-test:
runs-on: ubuntu-latest
Expand Down
36 changes: 0 additions & 36 deletions postgres_test_server/init-scripts/pg8000-init.sh

This file was deleted.

3 changes: 0 additions & 3 deletions postgres_test_server/init-scripts/pg8000-init.sql

This file was deleted.

16 changes: 0 additions & 16 deletions postgres_test_server/run-test-server.sh

This file was deleted.

9 changes: 9 additions & 0 deletions test/native/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from locale import LC_MONETARY, localeconv, setlocale
from os import environ

import pytest
Expand Down Expand Up @@ -49,3 +50,11 @@ def pg_version(con):
version = retval[0][0]
major = parse_server_version(version)
return major


@pytest.fixture
def currency(con):
retval = con.run("show lc_monetary")
lc_monetary = retval[0][0]
setlocale(LC_MONETARY, lc_monetary)
return localeconv()["currency_symbol"]
28 changes: 14 additions & 14 deletions test/native/test_typeconversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from enum import Enum
from ipaddress import IPv4Address, IPv4Network
from json import dumps
from locale import LC_ALL, localeconv, setlocale
from uuid import UUID

import pytest
Expand Down Expand Up @@ -490,13 +489,6 @@ def test_float8_array_out(con):
assert f3 == [[[1, 2], [3, 4]], [[None, 6], [7, 8]]]


# Find the currency string
setlocale(LC_ALL, "")
CURRENCY = localeconv()["currency_symbol"]
if CURRENCY == "":
CURRENCY = "$"


@pytest.mark.parametrize(
"test_input,oid",
[
Expand All @@ -518,7 +510,7 @@ def test_float8_array_out(con):
[[7000000000, 2, 3], BIGINT_ARRAY], # int8[]
[[1.1, 2.2, 3.3], FLOAT_ARRAY], # float8[]
[[Decimal("1.1"), None, Decimal("3.3")], NUMERIC_ARRAY], # numeric[]
[[f"{CURRENCY}1.10", None, f"{CURRENCY}3.30"], MONEY_ARRAY], # money[]
[["{currency}1.10", None, "{currency}3.30"], MONEY_ARRAY], # money[]
[[UUID("911460f2-1f43-fea2-3e2c-e01fd5b5069d")], UUID_ARRAY], # uuid[]
[ # json[]
[{"name": "Apollo 11 Cave", "zebra": True, "age": 26.003}],
Expand All @@ -535,8 +527,8 @@ def test_float8_array_out(con):
[True, BOOLEAN], # bool
[None, BOOLEAN], # null
[Decimal("1.1"), NUMERIC], # numeric
[f"{CURRENCY}1.10", MONEY], # money
[f"-{CURRENCY}1.10", MONEY], # money
["{currency}1.10", MONEY], # money
["-{currency}1.10", MONEY], # money
[50000000000000, BIGINT], # int8
[UUID("911460f2-1f43-fea2-3e2c-e01fd5b5069d"), UUID_TYPE], # uuid
[IPv4Network("192.168.0.0/28"), INET], # inet
Expand All @@ -548,9 +540,17 @@ def test_float8_array_out(con):
[{"name": "Apollo 11 Cave", "zebra": True, "age": 26.003}, JSONB], # jsonb
],
)
def test_roundtrip_oid(con, test_input, oid):
retval = con.run("SELECT :v", v=test_input, types={"v": oid})
assert retval[0][0] == test_input
def test_roundtrip_oid(currency, con, test_input, oid):
def fill_currency(s):
return s.format(currency=currency) if isinstance(s, str) else s

if isinstance(test_input, list):
v = [fill_currency(k) for k in test_input]
else:
v = fill_currency(test_input)

retval = con.run("SELECT :v", v=v, types={"v": oid})
assert retval[0][0] == v

assert oid == con.columns[0]["type_oid"]

Expand Down

0 comments on commit 288f67f

Please sign in to comment.