Skip to content

Commit

Permalink
Merge f70c4f2 into ff9c823
Browse files Browse the repository at this point in the history
  • Loading branch information
fizyk authored Mar 18, 2021
2 parents ff9c823 + f70c4f2 commit d843d1a
Show file tree
Hide file tree
Showing 12 changed files with 232 additions and 40 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/automerge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Automerge Pull Requests
on:
pull_request:
types:
- labeled
- unlabeled
- synchronize
- opened
- edited
- ready_for_review
- reopened
- unlocked
pull_request_review:
types:
- submitted
check_suite:
types:
- completed
status: {}

jobs:
automerge:
name: Automerge Dependabot
runs-on: ubuntu-latest
if: github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]'
steps:
- name: 'Wait for status checks'
id: waitforstatuschecks
uses: "WyriHaximus/github-action-wait-for-status@v1.2"
with:
ignoreActions: Automerge Dependabot
checkInterval: 13
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- name: Merge pull requests
uses: pascalgn/automerge-action@v0.12.0
if: steps.waitforstatuschecks.outputs.status == 'success'
env:
MERGE_METHOD: "squash"
MERGE_LABELS: ""
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
26 changes: 26 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Test build package

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
name: Build Python 🐍 distributions 📦
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install build tools
run: pip install pep517
- name: Build a wheel package
run: python -m pep517.build .
- name: Install twine to check the package
run: pip install twine
- name: Check the package
run: twine check dist/*
52 changes: 52 additions & 0 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Run linters

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
pydocstyle:
runs-on: ubuntu-latest
strategy:
fail-fast: false

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-lint.txt
- name: Run pydocstyle
run: |
pydocstyle src/ tests/
pycodestyle:
runs-on: ubuntu-latest
strategy:
fail-fast: false

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-lint.txt
- name: Run pydocstyle
run: |
pycodestyle src/ tests/
# black:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# - uses: actions/setup-python@v2
# - uses: psf/black@stable
29 changes: 29 additions & 0 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Package and publish
on:
push:
tags:
- v*
jobs:
build-n-publish:
name: Build and publish Python 🐍 distributions 📦 to PyPI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install build tools
run: pip install pep517
- name: Build a wheel package
run: python -m pep517.build .
# - name: Publish distribution 📦 to Test PyPI
# uses: pypa/gh-action-pypi-publish@master
# with:
# password: ${{ secrets.test_pypi_password }}
# repository_url: https://test.pypi.org/legacy/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.pypi_password }}
verbose: true
57 changes: 57 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Run tests

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [3.7, 3.8, 3.9, pypy3]
postgres-version: [9.5, 9.6, 10, 11, 12, 13]
env:
OS: ubuntu-latest
PYTHON: ${{ matrix.python-version }}
POSTGRES: ${{ matrix.postgres-version }}

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install postgresql
run: |
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg ${{ matrix.postgres-version }}" > /etc/apt/sources.list.d/pgdg.list'
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo sh -c 'echo "Package: *" > /etc/apt/preferences.d/psql'
sudo sh -c 'echo "Pin: release c=${{ matrix.poxtgresql-version }}" >> /etc/apt/preferences.d/psql'
sudo sh -c 'echo "Pin-Priority: 1000" >> /etc/apt/preferences.d/psql'
sudo apt update
sudo apt install -y postgresql-${{ matrix.postgres-version }} postgresql-client-${{ matrix.postgres-version }}
- name: Check installed locales
run: |
locale -a
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-test.txt
- name: Run test
run: |
py.test -n 0 --postgresql-exec="/usr/lib/postgresql/${{ matrix.postgres-version }}/bin/pg_ctl" --cov-report=xml
- name: Run xdist test
run: |
py.test -n 1 --postgresql-exec="/usr/lib/postgresql/${{ matrix.postgres-version }}/bin/pg_ctl" --cov-report=xml:coverage-xdist.xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
file: ./coverage.xml ./coverage-xdist.xml
flags: unittests
env_vars: OS,PYTHON
fail_ci_if_error: true
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
dist: bionic
language: python
python:
- 3.9
- 3.8
- 3.7
- 3.6
- 3.9
- nightly
- pypy3
# blocklist branches
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ You can pick which you prefer, but remember that these settings are handled in t
- --postgresql-exec
- postgresql_exec
- -
- /usr/lib/postgresql/9.1/bin/pg_ctl
- /usr/lib/postgresql/9.5/bin/pg_ctl
* - host
- host
- --postgresql-host
Expand Down
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[build-system]
requires = ["setuptools >= 40.6.0", "wheel"]
build-backend = "setuptools.build_meta"

[tool.black]
line-length = 100
target-version = ['py38']
include = '.*\.pyi?$'
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ match = '(?!docs|build|venv).*\.py'

[tool:pytest]
addopts = --max-worker-restart=0 --showlocals --verbose --cov src/pytest_postgresql --cov tests
postgresql_exec = /usr/lib/postgresql/10/bin/pg_ctl
testpaths = tests
xfail_strict = true
pytester_example_dir = tests/examples
Expand Down
10 changes: 3 additions & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pytest_postgresql import factories

pytest_plugins = ['pytester']
POSTGRESQL_VERSION = os.environ.get("POSTGRES", "13")


def find_pg_ctl(path: str) -> Path:
Expand Down Expand Up @@ -33,15 +34,10 @@ def create_version(ver: str) -> Path:
TEST_SQL_DIR = os.path.dirname(os.path.abspath(__file__)) + '/test_sql/'

# pylint:disable=invalid-name
postgresql95 = factories.postgresql_proc(create_version(ver='9.5'), port=None)
postgresql96 = factories.postgresql_proc(create_version(ver='9.6'), port=None)
postgresql10 = factories.postgresql_proc(create_version(ver='10'), port=None)
postgresql11 = factories.postgresql_proc(create_version(ver='11'), port=None)
postgresql12 = factories.postgresql_proc(create_version(ver='12'), port=None)
postgresql13 = factories.postgresql_proc(create_version(ver='13'), port=None)
postgresql_proc_version = factories.postgresql_proc(create_version(ver=POSTGRESQL_VERSION), port=None)
postgresql_version = factories.postgresql('postgresql_proc_version')

postgresql_proc2 = factories.postgresql_proc(port=9876)
postgres10 = factories.postgresql('postgresql10')
postgresql2 = factories.postgresql('postgresql_proc2', db_name='test-db')
postgresql_load_1 = factories.postgresql('postgresql_proc2', db_name='test-db',
load=[TEST_SQL_DIR + 'test.sql', ])
Expand Down
27 changes: 10 additions & 17 deletions tests/test_noopexecutor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,19 @@
from pytest_postgresql.factories import NoopExecutor


def test_nooproc_version_9(postgresql_proc):
"""Test the way postgresql version is being read for versions < 10."""
postgresql_nooproc = NoopExecutor(
postgresql_proc.host,
postgresql_proc.port,
postgresql_proc.user,
postgresql_proc.options
)
assert postgresql_proc.version == postgresql_nooproc.version

def test_nooproc_version(postgresql_proc_version):
"""
Test the way postgresql version is being read.
def test_nooproc_version_post_10(postgresql11):
"""Test the way postgresql version is being read for versions >= 10."""
Version behaves differently for postgresql >= 10 and differently for older ones
"""
postgresql_nooproc = NoopExecutor(
postgresql11.host,
postgresql11.port,
postgresql11.user,
postgresql11.options
postgresql_proc_version.host,
postgresql_proc_version.port,
postgresql_proc_version.user,
postgresql_proc_version.options
)
assert postgresql11.version == postgresql_nooproc.version
assert postgresql_proc_version.version == postgresql_nooproc.version


def test_nooproc_cached_version(postgresql_proc):
Expand Down
17 changes: 4 additions & 13 deletions tests/test_postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,9 @@
SELECT_Q = "SELECT * FROM test;"


@pytest.mark.parametrize('postgres', (
'postgresql95',
'postgresql96',
'postgresql10',
'postgresql11',
'postgresql12',
'postgresql13'
))
def test_postgresql_proc(request, postgres):
def test_postgresql_proc(postgresql_proc_version):
"""Test different postgresql versions."""
postgresql_proc = request.getfixturevalue(postgres)
assert postgresql_proc.running() is True
assert postgresql_proc_version.running() is True


def test_main_postgres(postgresql):
Expand Down Expand Up @@ -67,13 +58,13 @@ def test_rand_postgres_port(postgresql_rand):

@pytest.mark.parametrize('_', range(2))
def test_postgres_terminate_connection(
postgres10, _):
postgresql_version, _):
"""
Test that connections are terminated between tests.
And check that only one exists at a time.
"""
cur = postgres10.cursor()
cur = postgresql_version.cursor()
cur.execute(
'SELECT * FROM pg_stat_activity '
'WHERE backend_type = \'client backend\';'
Expand Down

0 comments on commit d843d1a

Please sign in to comment.