Skip to content

Commit e167df2

Browse files
committed
Use docker and add some fixes
1 parent dc77a1f commit e167df2

File tree

3 files changed

+29
-48
lines changed

3 files changed

+29
-48
lines changed

.travis.yml

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,24 @@
1-
language: "python"
2-
31
sudo: required
42

53
services:
6-
- postgresql
7-
8-
env:
9-
- PG_VER=9.5
10-
- PG_VER=9.6
11-
- PG_VER=10
12-
13-
python:
14-
- "2.7"
15-
- "3.5"
16-
- "3.6"
17-
- "pypy"
18-
- "pypy3"
19-
20-
before_install:
21-
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get -y install -qq wget ca-certificates; fi
22-
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo sh ./travis/dep-ubuntu-postgres.sh; fi
23-
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get update -qq; fi
24-
25-
install:
26-
- sudo service postgresql stop
27-
- echo 'exit 0' | sudo tee /etc/init.d/postgresql
28-
- sudo chmod a+x /etc/init.d/postgresql
4+
- docker
295

306
before_script:
31-
- sudo pg_createcluster --start $PG_VER testgres -- -A trust
32-
- sudo chmod a+w /var/run/postgresql/
33-
- sudo /etc/init.d/postgresql restart
34-
- export PG_CONFIG=/usr/lib/postgresql/$PG_VER/bin/pg_config
35-
- virtualenv /tmp/envs/testgres
36-
- source /tmp/envs/testgres/bin/activate
37-
- pip install six psycopg2 pg8000 flake8
38-
- python setup.py install
7+
- sed -e 's/${PYTHON_VERSION}/'${PYTHON_VERSION}/g -e 's/${PG_VERSION}/'${PG_VERSION}/g Dockerfile.tmpl > Dockerfile
8+
- docker-compose build
399

4010
script:
41-
- cd testgres/tests
42-
- python -m unittest test_simple
43-
- flake8 --ignore=W191,F401,E501,F403 .
11+
- docker-compose run tests
4412

4513
notifications:
46-
email:
47-
on_success: change
48-
on_failure: always
14+
email:
15+
on_success: change
16+
on_failure: always
17+
18+
matrix:
19+
- PYTHON_VERSION=2 PG_VERSION=10
20+
- PYTHON_VERSION=2 PG_VERSION=9.6
21+
- PYTHON_VERSION=2 PG_VERSION=9.5
22+
- PYTHON_VERSION=3 PG_VERSION=10
23+
- PYTHON_VERSION=3 PG_VERSION=9.6
24+
- PYTHON_VERSION=3 PG_VERSION=9.5

testgres/testgres.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def connstr(self):
244244
def get_bin_path(self, filename):
245245
""" Returns full path to an executable """
246246
pg_config = get_config()
247-
if "BINDIR" not in pg_config:
247+
if pg_config is None or "BINDIR" not in pg_config:
248248
return filename
249249
else:
250250
return os.path.join(pg_config.get("BINDIR"), filename)
@@ -684,12 +684,15 @@ def get_config():
684684
pg_config_cmd = os.environ.get("PG_CONFIG") \
685685
if "PG_CONFIG" in os.environ else "pg_config"
686686

687-
out = six.StringIO(
688-
subprocess.check_output([pg_config_cmd], universal_newlines=True))
689-
for line in out:
690-
if line and "=" in line:
691-
key, value = line.split("=", 1)
692-
pg_config_data[key.strip()] = value.strip()
687+
try:
688+
out = six.StringIO(
689+
subprocess.check_output([pg_config_cmd], universal_newlines=True))
690+
for line in out:
691+
if line and "=" in line:
692+
key, value = line.split("=", 1)
693+
pg_config_data[key.strip()] = value.strip()
694+
except OSError:
695+
return None
693696

694697
# Numeric version format
695698
version_parts = pg_config_data.get("VERSION").split(" ")

testgres/tests/test_simple.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ def test_backup_and_replication(self):
3939
replica.start()
4040
res = replica.execute('postgres', 'select * from abc')
4141
self.assertEqual(len(res), 1)
42-
self.assertEqual(res[0], (1, 2))
42+
self.assertEqual(res[0][0], 1)
43+
self.assertEqual(res[0][1], 2)
4344

4445
# Prepare the query which would check whether record reached replica
4546
# (It is slightly different for Postgres 9.6 and Postgres 10+)
@@ -59,7 +60,8 @@ def test_backup_and_replication(self):
5960
# Check that this record was exported to replica
6061
res = replica.execute('postgres', 'select * from abc')
6162
self.assertEqual(len(res), 2)
62-
self.assertEqual(res[1], (3, 4))
63+
self.assertEqual(res[1][0], 3)
64+
self.assertEqual(res[1][1], 4)
6365

6466
node.stop()
6567
replica.stop()

0 commit comments

Comments
 (0)