From f5f040d7c8ed960362a60ff9e1bc2fde067b5a8f Mon Sep 17 00:00:00 2001 From: Mike Taves Date: Wed, 12 May 2021 19:37:13 +1200 Subject: [PATCH] TST: add PGPORT env var, rewrite setup_postgres.sh to scripts dir (#1932) --- .github/workflows/tests.yaml | 3 ++- ci/envs/setup_postgres.sh | 21 --------------------- ci/scripts/setup_postgres.sh | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 22 deletions(-) delete mode 100644 ci/envs/setup_postgres.sh create mode 100644 ci/scripts/setup_postgres.sh diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index a1327c8..1c303c9 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -110,10 +110,11 @@ jobs: PGUSER: postgres PGPASSWORD: postgres PGHOST: "127.0.0.1" + PGPORT: 5432 run: | source activate test conda install postgis -c conda-forge - source ci/envs/setup_postgres.sh + sh ci/scripts/setup_postgres.sh pytest -v -r s --color=yes --cov=geopandas --cov-append --cov-report term-missing --cov-report xml geopandas/io/tests/test_sql.py | tee /dev/stderr | if grep SKIPPED >/dev/null;then echo "TESTS SKIPPED, FAILING" && exit 1;fi - name: Test docstrings diff --git a/ci/envs/setup_postgres.sh b/ci/envs/setup_postgres.sh deleted file mode 100644 index 32defae..0000000 --- a/ci/envs/setup_postgres.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -echo "Setting up Postgresql" - -mkdir -p ${HOME}/var -rm -rf ${HOME}/var/db - -pg_ctl initdb -D ${HOME}/var/db -pg_ctl start -D ${HOME}/var/db - -echo -n 'waiting for postgres' -while [ ! -e /tmp/.s.PGSQL.5432 ]; do - sleep 1 - echo -n '.' -done - -createuser -U ${USER} -s postgres -createdb --owner=postgres test_geopandas -psql -d test_geopandas -q -c "CREATE EXTENSION postgis" - -echo "Done setting up Postgresql" diff --git a/ci/scripts/setup_postgres.sh b/ci/scripts/setup_postgres.sh new file mode 100644 index 0000000..1a5a3d7 --- /dev/null +++ b/ci/scripts/setup_postgres.sh @@ -0,0 +1,33 @@ +#!/bin/sh +set -e + +if [ -z "${PGUSER}" ] || [ -z "${PGPORT}" ]; then + echo "Environment variables PGUSER and PGPORT must be set" + exit 1 +fi + +PGDATA=$(mktemp -d /tmp/postgres.XXXXXX) +echo "Setting up PostgreSQL in ${PGDATA} on port ${PGPORT}" + +pg_ctl -D ${PGDATA} initdb +pg_ctl -D ${PGDATA} start + +SOCKETPATH="/tmp/.s.PGSQL.${PGPORT}" +echo -n 'waiting for postgres' +while [ ! -e ${SOCKETPATH} ]; do + sleep 1 + echo -n '.' +done +echo + +echo "Done setting up PostgreSQL. When finished, stop and cleanup using:" +echo +echo " pg_ctl -D ${PGDATA} stop" +echo " rm -rf ${PGDATA}" +echo + +createuser -U ${USER} -s ${PGUSER} +createdb --owner=${PGUSER} test_geopandas +psql -d test_geopandas -q -c "CREATE EXTENSION postgis" + +echo "PostGIS server ready."