Skip to content

Commit 92aaa40

Browse files
authored
Merge pull request #10 from pangpang20/master
Enhance Test and CI Compatibility with openGauss
2 parents eece3d4 + 12b8048 commit 92aaa40

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+646
-249
lines changed

.flake8

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ per-file-ignores =
1717
# Pytest's importorskip() getting in the way
1818
tests/types/test_numpy.py: E402
1919
tests/types/test_shapely.py: E402
20+
21+
tools/async_to_sync.py: E999
22+
tools/bump_version.py: E999

.github/workflows/3rd-party-tests.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
name: 3rd party tests
22

33
on:
4-
push:
5-
branches:
6-
- "master"
7-
- "maint-3.1"
8-
- "sqlalchemy_pipeline"
9-
- "django_pipeline"
10-
paths-ignore:
11-
- "docs/*"
12-
- "tools/*"
4+
# push:
5+
# branches:
6+
# - "master"
7+
# - "maint-3.1"
8+
# - "sqlalchemy_pipeline"
9+
# - "django_pipeline"
10+
# paths-ignore:
11+
# - "docs/*"
12+
# - "tools/*"
1313
workflow_dispatch:
1414

1515
concurrency:

.github/workflows/ci.yml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
name: CI for gaussdb-python
2+
3+
on:
4+
push:
5+
branches:
6+
- "*"
7+
pull_request:
8+
workflow_dispatch:
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref_name }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
test:
16+
runs-on: ubuntu-22.04
17+
18+
services:
19+
opengauss:
20+
image: opengauss/opengauss-server:latest
21+
ports:
22+
- 5432:5432
23+
env:
24+
GS_USERNAME: root
25+
GS_USER_PASSWORD: ${{ secrets.OPENGAUSS_PASSWORD }}
26+
GS_PASSWORD: ${{ secrets.OPENGAUSS_PASSWORD }}
27+
options: >-
28+
--privileged=true
29+
--name opengauss-custom
30+
31+
steps:
32+
- name: Checkout code
33+
uses: actions/checkout@v4
34+
35+
- name: Set up Python
36+
uses: actions/setup-python@v5
37+
with:
38+
python-version: "3.9"
39+
cache: pip
40+
41+
- name: Create and activate virtual environment
42+
run: |
43+
python -m venv venv
44+
echo "VENV_PATH=$GITHUB_WORKSPACE/venv/bin" >> $GITHUB_ENV
45+
source venv/bin/activate
46+
47+
- name: Install gaussdb libpq driver
48+
run: |
49+
sudo apt update
50+
sudo apt install -y wget unzip
51+
wget -O /tmp/GaussDB_driver.zip https://dbs-download.obs.cn-north-1.myhuaweicloud.com/GaussDB/1730887196055/GaussDB_driver.zip
52+
unzip /tmp/GaussDB_driver.zip -d /tmp/ && rm -rf /tmp/GaussDB_driver.zip
53+
\cp /tmp/GaussDB_driver/Centralized/Hce2_X86_64/GaussDB-Kernel*64bit_Python.tar.gz /tmp/
54+
tar -zxvf /tmp/GaussDB-Kernel*64bit_Python.tar.gz -C /tmp/ && rm -rf /tmp/GaussDB-Kernel*64bit_Python.tar.gz && rm -rf /tmp/psycopg2 && rm -rf /tmp/GaussDB_driver
55+
echo /tmp/lib | sudo tee /etc/ld.so.conf.d/gauss-libpq.conf
56+
sudo sed -i '1s|^|/tmp/lib\n|' /etc/ld.so.conf
57+
sudo ldconfig
58+
ldconfig -p | grep pq
59+
60+
- name: Install dependencies
61+
run: |
62+
source venv/bin/activate
63+
python -m pip install --upgrade pip
64+
pip install -r requirements.txt
65+
pip install -e "./psycopg[dev,test]"
66+
pip install -e ./psycopg_pool
67+
68+
69+
- name: Wait for openGauss to be ready
70+
env:
71+
GSQL_PASSWORD: ${{ secrets.OPENGAUSS_PASSWORD }}
72+
run: |
73+
source venv/bin/activate
74+
for i in {1..15}; do
75+
pg_isready -h localhost -p 5432 -U root && break
76+
sleep 5
77+
done
78+
if ! pg_isready -h localhost -p 5432 -U root; then
79+
echo "openGauss is not ready"
80+
exit 1
81+
fi
82+
83+
- name: Create test database
84+
run: |
85+
docker exec opengauss-custom bash -c "su - omm -c 'gsql -d postgres -c \"CREATE DATABASE test DBCOMPATIBILITY '\''PG'\'';\"'"
86+
87+
- name: Create report directory
88+
run: |
89+
mkdir -p reports
90+
91+
- name: Run tests
92+
env:
93+
PYTHONPATH: ./psycopg:./psycopg_pool
94+
PSYCOPG_IMPL: python
95+
PSYCOPG_TEST_DSN: "host=127.0.0.1 port=5432 dbname=test user=root password=${{ secrets.OPENGAUSS_PASSWORD }} "
96+
run: |
97+
source venv/bin/activate
98+
pytest -s -v
99+
100+
- name: Cleanup
101+
if: always()
102+
run: |
103+
docker stop opengauss-custom
104+
docker rm opengauss-custom

.github/workflows/docs.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
name: Build documentation
22

33
on:
4-
push:
5-
branches:
6-
# This should match the DOC3_BRANCH value in the psycopg-website Makefile
7-
- master
4+
# push:
5+
# branches:
6+
# # This should match the DOC3_BRANCH value in the psycopg-website Makefile
7+
# - master
8+
pull_request:
89

910
concurrency:
1011
group: ${{ github.workflow }}-${{ github.ref_name }}

.github/workflows/lint.yml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,32 @@ jobs:
2020
steps:
2121
- uses: actions/checkout@v4
2222

23-
- uses: actions/setup-python@v5
23+
- name: Set up Python 3.9
24+
uses: actions/setup-python@v5
2425
with:
25-
python-version: "3.11"
26+
python-version: "3.9"
2627

2728
- name: install packages to tests
28-
run: pip install ./psycopg[dev,test]
29+
run: |
30+
pip install ./psycopg[dev,test]
31+
pip install types-polib
32+
pip install pre-commit
2933
3034
- name: Lint codebase
3135
run: pre-commit run -a --color=always
3236

37+
- name: Set up Python 3.11
38+
uses: actions/setup-python@v5
39+
with:
40+
python-version: "3.11"
41+
42+
- name: Install packages for async_to_sync
43+
run: |
44+
pip install ./psycopg[dev,test]
45+
pip install types-polib
46+
3347
- name: Check for sync/async inconsistencies
34-
run: ./tools/async_to_sync.py --check --all
48+
run: ./tools/async_to_sync.py --check $(find tests -name "*_async.py" -type f ! -path "tests/pq/test_async.py")
3549

3650
- name: Install requirements to generate docs
3751
run: sudo apt-get install -y libgeos-dev

.github/workflows/tests.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
name: Tests
22

33
on:
4-
push:
5-
# This should disable running the workflow on tags, according to the
6-
# on.<push|pull_request>.<branches|tags> GitHub Actions docs.
7-
branches:
8-
- "*"
4+
# push:
5+
# # This should disable running the workflow on tags, according to the
6+
# # on.<push|pull_request>.<branches|tags> GitHub Actions docs.
7+
# branches:
8+
# - "*"
99
pull_request:
1010
schedule:
1111
- cron: '48 6 * * *'

mypy.ini

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[mypy]
2+
python_version = 3.9
3+
ignore_missing_imports = True
4+
check_untyped_defs = True
5+
6+
[mypy-tools.async_to_sync]
7+
ignore_errors = True
8+
9+
[mypy-tools.bump_version]
10+
ignore_errors = True

psycopg/psycopg/_copy_base.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import sys
1111
import struct
1212
from abc import ABC, abstractmethod
13-
from typing import TYPE_CHECKING, Any, Generic
13+
from typing import TYPE_CHECKING, Any, Generic, Optional, Tuple
1414
from collections.abc import Sequence
1515

1616
from . import adapt
@@ -171,7 +171,7 @@ def _read_row_gen(self) -> PQGen[tuple[Any, ...] | None]:
171171

172172
row = self.formatter.parse_row(data)
173173

174-
if row == IS_BINARY_SIGNATURE:
174+
if isinstance(row, str) and row == IS_BINARY_SIGNATURE:
175175
row = yield from self._read_row_gen()
176176

177177
if row is None:
@@ -267,21 +267,19 @@ def __init__(self, transformer: Transformer):
267267
super().__init__(transformer)
268268
self._signature_sent = False
269269

270-
def parse_row(self, data: Buffer) -> tuple[Any, ...] | str | None:
271-
rv: tuple[Any, ...] | None = None
272-
270+
def parse_row(self, data: Buffer) -> Optional[Tuple[Any, ...]]:
273271
if not self._signature_sent:
274272
if data[: len(_binary_signature)] != _binary_signature:
275273
raise e.DataError(
276274
"binary copy doesn't start with the expected signature"
277275
)
278276
self._signature_sent = True
279-
return IS_BINARY_SIGNATURE
277+
return None
280278

281279
if data != _binary_trailer:
282-
rv = parse_row_binary(data, self.transformer)
280+
return parse_row_binary(data, self.transformer)
283281

284-
return rv
282+
return None
285283

286284
def write(self, buffer: Buffer | str) -> Buffer:
287285
data = self._ensure_bytes(buffer)

psycopg/psycopg/errors.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,9 @@ def severity(self) -> str | None:
440440

441441
@property
442442
def severity_nonlocalized(self) -> str | None:
443-
raise NotSupportedError("This is present only in reports generated by libpq versions 9.6 and later.")
443+
raise NotSupportedError(
444+
"This is present only in reports generated by libpq versions 9.6 and later."
445+
)
444446

445447
@property
446448
def sqlstate(self) -> str | None:

psycopg/psycopg/types/multirange.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from .. import _oids
1616
from .. import errors as e
17-
from .. import postgres, sql
17+
from .. import postgres
1818
from ..pq import Format
1919
from ..abc import AdaptContext, Buffer, Dumper, DumperKey, Query
2020
from .range import Range, T, dump_range_binary, dump_range_text, fail_dump
@@ -47,9 +47,7 @@ def __init__(
4747

4848
@classmethod
4949
def _get_info_query(cls, conn: BaseConnection[Any]) -> Query:
50-
raise e.NotSupportedError(
51-
"multirange types are not supported in GaussDB"
52-
)
50+
raise e.NotSupportedError("multirange types are not supported in GaussDB")
5351

5452
def _added(self, registry: TypesRegistry) -> None:
5553
# Map multiranges ranges and subtypes to info

0 commit comments

Comments
 (0)