Skip to content

Commit

Permalink
Add GitHub worflow for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Cito committed Jan 29, 2022
1 parent ac66e2e commit 6ebd20f
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 103 deletions.
File renamed without changes.
65 changes: 65 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Run PyGreSQL test matrix

# this has been shamelessly copied from Psycopg

on:
push:
pull_request:

jobs:
tests:
name: Unit tests run
runs-on: ubuntu-18.04

strategy:
fail-fast: false
matrix:
include:
- {python: "2.7", postgres: "9.3"}
- {python: "3.5", postgres: "9.6"}
- {python: "3.6", postgres: "10"}
- {python: "3.7", postgres: "11"}
- {python: "3.8", postgres: "12"}
- {python: "3.9", postgres: "13"}
- {python: "3.10", postgres: "14"}

# Opposite extremes of the supported Py/PG range, other architecture
- {python: "2.7", postgres: "14", architecture: "x86"}
- {python: "3.5", postgres: "13", architecture: "x86"}
- {python: "3.6", postgres: "12", architecture: "x86"}
- {python: "3.7", postgres: "11", architecture: "x86"}
- {python: "3.8", postgres: "10", architecture: "x86"}
- {python: "3.9", postgres: "9.6", architecture: "x86"}
- {python: "3.10", postgres: "9.3", architecture: "x86"}

env:
PYGRESQL_DB: test
PYGRESQL_HOST: 127.0.0.1

services:
postgresql:
image: postgres:${{ matrix.postgres }}
env:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
ports:
- 5432:5432
# 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@v2
- name: Install tox
run: pip install tox
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
- name: Run tests
env:
MATRIX_PYTHON: ${{ matrix.python }}
run: tox -e py${MATRIX_PYTHON/./}
timeout-minutes: 5
26 changes: 26 additions & 0 deletions tests/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

from os import environ

# We need a database to test against.
# If LOCAL_PyGreSQL.py exists, we will get our information from that.
# Otherwise, we use the defaults.

# The tests should be run with various PostgreSQL versions and databases
# created with different encodings and locales. Particularly, make sure the
# tests are running against databases created with both SQL_ASCII and UTF8.

# The current user must have create schema privilege on the database.

dbname = environ.get('PYGRESQL_DB', 'unittest')
dbhost = environ.get('PYGRESQL_HOST', None)
dbport = environ.get('PYGRESQL_PORT', 5432)

try:
from .LOCAL_PyGreSQL import * # noqa: F401
except (ImportError, ValueError):
try:
from LOCAL_PyGreSQL import * # noqa: F401
except ImportError:
pass
14 changes: 1 addition & 13 deletions tests/test_classic.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,7 @@

from pg import *

# We need a database to test against. If LOCAL_PyGreSQL.py exists we will
# get our information from that. Otherwise we use the defaults.
dbname = 'unittest'
dbhost = None
dbport = 5432

try:
from .LOCAL_PyGreSQL import * # noqa: F401
except (ImportError, ValueError):
try:
from LOCAL_PyGreSQL import * # noqa: F401
except ImportError:
pass
from .config import dbname, dbhost, dbport


def open_db():
Expand Down
17 changes: 1 addition & 16 deletions tests/test_classic_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,7 @@

import pg # the module under test

# We need a database to test against. If LOCAL_PyGreSQL.py exists we will
# get our information from that. Otherwise we use the defaults.
# These tests should be run with various PostgreSQL versions and databases
# created with different encodings and locales. Particularly, make sure the
# tests are running against databases created with both SQL_ASCII and UTF8.
dbname = 'unittest'
dbhost = None
dbport = 5432

try:
from .LOCAL_PyGreSQL import * # noqa: F401
except (ImportError, ValueError):
try:
from LOCAL_PyGreSQL import * # noqa: F401
except ImportError:
pass
from .config import dbname, dbhost, dbport

try: # noinspection PyUnboundLocalVariable,PyUnresolvedReferences
long
Expand Down
15 changes: 1 addition & 14 deletions tests/test_classic_dbwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,10 @@
from time import strftime
from operator import itemgetter

# We need a database to test against. If LOCAL_PyGreSQL.py exists we will
# get our information from that. Otherwise we use the defaults.
# The current user must have create schema privilege on the database.
dbname = 'unittest'
dbhost = None
dbport = 5432
from .config import dbname, dbhost, dbport

debug = False # let DB wrapper print debugging output

try:
from .LOCAL_PyGreSQL import * # noqa: F401
except (ImportError, ValueError):
try:
from LOCAL_PyGreSQL import * # noqa: F401
except ImportError:
pass

try: # noinspection PyUnboundLocalVariable,PyUnresolvedReferences
long
except NameError: # Python >= 3.0
Expand Down
14 changes: 1 addition & 13 deletions tests/test_classic_largeobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,7 @@

import pg # the module under test

# We need a database to test against. If LOCAL_PyGreSQL.py exists we will
# get our information from that. Otherwise we use the defaults.
dbname = 'unittest'
dbhost = None
dbport = 5432

try:
from .LOCAL_PyGreSQL import * # noqa: F401
except (ImportError, ValueError):
try:
from LOCAL_PyGreSQL import * # noqa: F401
except ImportError:
pass
from .config import dbname, dbhost, dbport

windows = os.name == 'nt'

Expand Down
7 changes: 1 addition & 6 deletions tests/test_classic_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@

import pg # the module under test

# We need a database to test against. If LOCAL_PyGreSQL.py exists we will
# get our information from that. Otherwise we use the defaults.
# The current user must have create schema privilege on the database.
dbname = 'unittest'
dbhost = None
dbport = 5432
from .config import dbname, dbhost, dbport

debug = False # let DB wrapper print debugging output

Expand Down
14 changes: 1 addition & 13 deletions tests/test_dbapi20.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,7 @@
# noinspection PyUnresolvedReferences
import dbapi20

# We need a database to test against.
# If LOCAL_PyGreSQL.py exists we will get our information from that.
# Otherwise we use the defaults.
dbname = 'dbapi20_test'
dbhost = ''
dbport = 5432
try:
from .LOCAL_PyGreSQL import * # noqa: F401
except (ImportError, ValueError):
try:
from LOCAL_PyGreSQL import * # noqa: F401
except ImportError:
pass
from .config import dbname, dbhost, dbport

try: # noinspection PyUnboundLocalVariable,PyUnresolvedReferences
long
Expand Down
15 changes: 1 addition & 14 deletions tests/test_dbapi20_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,7 @@

import pgdb # the module under test

# We need a database to test against. If LOCAL_PyGreSQL.py exists we will
# get our information from that. Otherwise we use the defaults.
# The current user must have create schema privilege on the database.
dbname = 'unittest'
dbhost = None
dbport = 5432

try:
from .LOCAL_PyGreSQL import * # noqa: F401
except (ImportError, ValueError):
try:
from LOCAL_PyGreSQL import * # noqa: F401
except ImportError:
pass
from .config import dbname, dbhost, dbport

try: # noinspection PyUnboundLocalVariable,PyUnresolvedReferences
unicode
Expand Down
14 changes: 1 addition & 13 deletions tests/test_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,7 @@
from pg import DB
from pgdb import connect

# We need a database to test against. If LOCAL_PyGreSQL.py exists we will
# get our information from that. Otherwise we use the defaults.
dbname = 'unittest'
dbhost = None
dbport = 5432

try:
from .LOCAL_PyGreSQL import * # noqa: F401
except (ImportError, ValueError):
try:
from LOCAL_PyGreSQL import * # noqa: F401
except ImportError:
pass
from .config import dbname, dbhost, dbport


class TestClassicTutorial(unittest.TestCase):
Expand Down
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# config file for tox

[tox]
envlist = py{27,35,36,37,38,39,310},flake8,docs
envlist = 27,3{5,6,7,8,9,10},flake8,docs

[testenv:flake8]
basepython = python3.9
Expand All @@ -18,6 +18,8 @@ commands =
sphinx-build -b html -nEW docs docs/_build/html

[testenv]
passenv = PG* PYGRESQL_*
commands =
python setup.py clean --all build_ext --force --inplace --strict --ssl-info --memory-size
python -m unittest discover {posargs}

0 comments on commit 6ebd20f

Please sign in to comment.