Skip to content

Commit

Permalink
Merge pull request #939 from sebastic/python3
Browse files Browse the repository at this point in the history
Use Python 3 for regression-test.py.
  • Loading branch information
pnorman committed Jul 27, 2019
2 parents 90e17f0 + c89b143 commit ea23dc9
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 37 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ addons_shortcuts:
apt:
sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-trusty-3.8']
packages: ['clang-3.8', 'postgresql-9.2-postgis-2.3',
'python-psycopg2', 'libexpat1-dev', 'libpq-dev', 'libbz2-dev', 'libproj-dev',
'python3-psycopg2', 'libexpat1-dev', 'libpq-dev', 'libbz2-dev', 'libproj-dev',
'lua5.2', 'liblua5.2-dev', 'libluajit-5.1-dev',
'libboost1.55-dev', 'libboost-system1.55-dev', 'libboost-filesystem1.55-dev']

Expand All @@ -27,7 +27,7 @@ addons_shortcuts:
key_url: https://apt.llvm.org/llvm-snapshot.gpg.key
- ubuntu-toolchain-r-test
packages: ['clang-7','postgresql-9.6-postgis-2.3',
'python-psycopg2', 'libexpat1-dev', 'libpq-dev', 'libbz2-dev', 'libproj-dev',
'python3-psycopg2', 'libexpat1-dev', 'libpq-dev', 'libbz2-dev', 'libproj-dev',
'lua5.2', 'liblua5.2-dev', 'libluajit-5.1-dev',
'libboost1.55-dev', 'libboost-system1.55-dev', 'libboost-filesystem1.55-dev']

Expand All @@ -36,7 +36,7 @@ addons_shortcuts:
apt:
sources: ["ubuntu-toolchain-r-test"]
packages: ['g++-4.8','postgresql-9.6-postgis-2.3',
'python-psycopg2', 'libexpat1-dev', 'libpq-dev', 'libbz2-dev', 'libproj-dev',
'python3-psycopg2', 'libexpat1-dev', 'libpq-dev', 'libbz2-dev', 'libproj-dev',
'lua5.2', 'liblua5.2-dev', 'libluajit-5.1-dev',
'libboost1.55-dev', 'libboost-system1.55-dev', 'libboost-filesystem1.55-dev']

Expand All @@ -46,7 +46,7 @@ addons_shortcuts:
apt:
sources: ["ubuntu-toolchain-r-test"]
packages: ['g++-8','postgresql-9.6-postgis-2.3',
'python-psycopg2', 'libexpat1-dev', 'libpq-dev', 'libbz2-dev', 'libproj-dev',
'python3-psycopg2', 'libexpat1-dev', 'libpq-dev', 'libbz2-dev', 'libproj-dev',
'lua5.2', 'liblua5.2-dev', 'libluajit-5.1-dev',
'libboost1.55-dev', 'libboost-system1.55-dev', 'libboost-filesystem1.55-dev']

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ executing ``ctest``.
Regression tests require python and psycopg to be installed. On Ubuntu run:

```sh
sudo apt-get install python-psycopg2
sudo apt-get install python3-psycopg2
```

Most of these tests depend on being able to set up a database and run osm2pgsql
Expand Down
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ if (NOT HAVE_LUA)
set_tests_properties(test-output-multi-tags PROPERTIES WILL_FAIL on)
endif()

find_package(PythonInterp)
find_package(PythonInterp 3)

if (PYTHONINTERP_FOUND)
add_test(NAME regression-test-pbf COMMAND ${PYTHON_EXECUTABLE} tests/regression-test.py -f tests/liechtenstein-2013-08-03.osm.pbf -x $<TARGET_FILE:osm2pgsql>
Expand Down
62 changes: 31 additions & 31 deletions tests/regression-test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

import unittest
import psycopg2
Expand Down Expand Up @@ -317,14 +317,14 @@ def dbConnect(self):
self.conn.autocommit = True
self.cur = self.conn.cursor()
except Exception as e:
print "I am unable to connect to the database." + e
print("I am unable to connect to the database." + e)

def dbClose(self):
self.cur.close()
self.conn.close()

def executeStatements(self, seq):
print "*********************************"
print("*********************************")
self.dbConnect()
try:
for i in seq:
Expand Down Expand Up @@ -393,8 +393,8 @@ def setUp(self):
self.setUpGeneric(self.parameters, full_import_file)

def runTest(self):
print "****************************************"
print "Running initial import for " + self.name
print("****************************************")
print("Running initial import for " + self.name)
self.executeStatements(self.initialStatements)


Expand All @@ -412,10 +412,10 @@ def setUp(self):


def runTest(self):
print "****************************************"
print "Running initial import for " + self.name
print("****************************************")
print("Running initial import for " + self.name)
self.executeStatements(self.initialStatements)
print "Running diff-import for " + self.name
print("Running diff-import for " + self.name)
self.updateGeneric(self.parameters, diff_import_file)
self.executeStatements(self.postDiffStatements)

Expand All @@ -433,10 +433,10 @@ def setUp(self):


def runTest(self):
print "****************************************"
print "Running initial import for " + self.name
print("****************************************")
print("Running initial import for " + self.name)
self.executeStatements(self.initialStatements)
print "Running diff-import for " + self.name
print("Running diff-import for " + self.name)
self.updateGeneric(self.parameters, diff_multipoly_import_file)
self.executeStatements(self.postDiffStatements)

Expand All @@ -455,10 +455,10 @@ def setUp(self):


def runTest(self):
print "****************************************"
print "Running initial import in gazetteer mode for " + self.name
print("****************************************")
print("Running initial import in gazetteer mode for " + self.name)
self.executeStatements(self.initialStatements)
print "Running diff-import in gazetteer mode for " + self.name
print("Running diff-import in gazetteer mode for " + self.name)
self.updateGeneric(self.parameters, diff_import_file)
self.executeStatements(self.postDiffStatements)

Expand All @@ -483,26 +483,26 @@ def findContribSql(filename):
#****************************************************************
#****************************************************************
def setupDB():
print "Setting up test database"
print("Setting up test database")
try:
gen_conn=psycopg2.connect("dbname='template1'")
gen_conn.autocommit = True
except Exception as e:
print "I am unable to connect to the database."
print("I am unable to connect to the database.")
exit(1)

try:
gen_cur = gen_conn.cursor()
except Exception as e:
gen_conn.close()
print "I am unable to connect to the database."
print("I am unable to connect to the database.")
exit(1)

try:
gen_cur.execute("""DROP DATABASE IF EXISTS \"osm2pgsql-test\"""")
gen_cur.execute("""CREATE DATABASE \"osm2pgsql-test\" WITH ENCODING 'UTF8'""")
except Exception as e:
print "Failed to create osm2pgsql-test db" + e.pgerror
print("Failed to create osm2pgsql-test db" + e.pgerror)
exit(1);
finally:
gen_cur.close()
Expand All @@ -512,13 +512,13 @@ def setupDB():
test_conn=psycopg2.connect("dbname='osm2pgsql-test'")
test_conn.autocommit = True
except Exception as e:
print "I am unable to connect to the database." + e
print("I am unable to connect to the database." + e)
exit(1)

try:
test_cur = test_conn.cursor()
except Exception as e:
print "I am unable to connect to the database." + e
print("I am unable to connect to the database." + e)
gen_conn.close()
exit(1)

Expand All @@ -531,15 +531,15 @@ def setupDB():

test_cur.execute("""SELECT spcname FROM pg_tablespace WHERE spcname = 'tablespacetest'""")
if test_cur.fetchone():
print "We already have a tablespace, can use that"
print("We already have a tablespace, can use that")
else:
print "The test needs a temporary tablespace to run in, but it does not exist. Please create the temporary tablespace. On Linux, you can do this by running:"
print " sudo mkdir -p /tmp/psql-tablespace"
print " sudo /bin/chown postgres.postgres /tmp/psql-tablespace"
print " psql -c \"CREATE TABLESPACE tablespacetest LOCATION '/tmp/psql-tablespace'\" postgres"
print("The test needs a temporary tablespace to run in, but it does not exist. Please create the temporary tablespace. On Linux, you can do this by running:")
print(" sudo mkdir -p /tmp/psql-tablespace")
print(" sudo /bin/chown postgres.postgres /tmp/psql-tablespace")
print(" psql -c \"CREATE TABLESPACE tablespacetest LOCATION '/tmp/psql-tablespace'\" postgres")
exit(77)
except Exception as e:
print "Failed to create directory for tablespace" + str(e)
print("Failed to create directory for tablespace" + str(e))

# Check for postgis
try:
Expand Down Expand Up @@ -568,21 +568,21 @@ def setupDB():
test_conn.close()

def tearDownDB():
print "Cleaning up test database"
print("Cleaning up test database")
try:
gen_conn=psycopg2.connect("dbname='template1'")
gen_conn.autocommit = True
gen_cur = gen_conn.cursor()
except Exception as e:
print "I am unable to connect to the database."
print("I am unable to connect to the database.")
exit(1)

try:
gen_cur.execute("""DROP DATABASE IF EXISTS \"osm2pgsql-test\"""")
if (created_tablespace == 1):
gen_cur.execute("""DROP TABLESPACE IF EXISTS \"tablespacetest\"""")
except Exception as e:
print "Failed to clean up osm2pgsql-test db" + e.pgerror
print("Failed to clean up osm2pgsql-test db" + e.pgerror)
exit(1);

gen_cur.close()
Expand Down Expand Up @@ -621,8 +621,8 @@ def tearDownDB():
tearDownDB()

if success:
print "All tests passed :-)"
print("All tests passed :-)")
exit(0)
else:
print "Some tests failed :-("
print("Some tests failed :-(")
exit(1)

0 comments on commit ea23dc9

Please sign in to comment.