Skip to content

Commit 46108ca

Browse files
keitherskineMichael Kleehammer
authored and
Michael Kleehammer
committed
Run unit tests on Travis
1 parent 0c7531f commit 46108ca

File tree

2 files changed

+148
-12
lines changed

2 files changed

+148
-12
lines changed

.travis.yml

Lines changed: 139 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,148 @@
1+
# To increase the output in the log, set the environment variable
2+
# TRVS_VERBOSE to "true" in the repository settings in the Travis UI.
3+
4+
os: linux
5+
dist: bionic
16
language: python
2-
sudo: false
3-
python:
4-
- "2.7"
5-
- "3.4"
6-
- "3.5"
7-
- "3.6"
7+
8+
jobs:
9+
include:
10+
- name: Python2.7
11+
python: "2.7"
12+
env:
13+
- TESTS_DIR=tests2
14+
- name: Python3.6
15+
python: "3.6"
16+
env:
17+
- TESTS_DIR=tests3
18+
- name: Python3.7
19+
python: "3.7"
20+
env:
21+
- TESTS_DIR=tests3
22+
- name: Python3.8
23+
python: "3.8"
24+
env:
25+
- TESTS_DIR=tests3
26+
- name: Python3.9
27+
python: "3.9"
28+
env:
29+
- TESTS_DIR=tests3
30+
31+
env:
32+
global:
33+
- CURL_OUTPUT_FORMAT="%{http_code} %{filename_effective} %{size_download} %{time_total}"
34+
- MYSQL_DRIVER=mysql-connector-odbc-8.0.22-linux-glibc2.12-x86-64bit
35+
- UNIXODBC_DM=unixODBC-2.3.9
36+
37+
services:
38+
- docker
39+
- mysql
40+
- postgresql
841

942
addons:
43+
postgresql: "11"
1044
apt:
11-
sources:
12-
- ubuntu-toolchain-r-test
1345
packages:
14-
- gcc-4.8
15-
- g++-4.8
16-
- unixodbc-dev
46+
- unixodbc
47+
- unixodbc-dev
48+
- odbc-postgresql
49+
50+
cache:
51+
directories:
52+
- travis_cache
1753

1854
install:
55+
# show cache
56+
- mkdir "$TRAVIS_BUILD_DIR/travis_cache" || true
57+
- ls -l "$TRAVIS_BUILD_DIR/travis_cache"
58+
# install the latest unixODBC driver manager (v2.3.4 is 5 years old and buggy)
59+
# https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-driver-manager
60+
- odbcinst --version
61+
- cd /tmp
62+
- |
63+
if [ -f "$TRAVIS_BUILD_DIR/travis_cache/${UNIXODBC_DM}.tar.gz" ]; then
64+
cp -v "$TRAVIS_BUILD_DIR/travis_cache/${UNIXODBC_DM}.tar.gz" .
65+
else
66+
curl -sS -w "$CURL_OUTPUT_FORMAT" -O "http://www.unixodbc.org/${UNIXODBC_DM}.tar.gz"
67+
fi
68+
- ls -l "${UNIXODBC_DM}.tar.gz"
69+
- |
70+
if [ ! -f "$TRAVIS_BUILD_DIR/travis_cache/${UNIXODBC_DM}.tar.gz" ]; then
71+
cp -v "${UNIXODBC_DM}.tar.gz" "$TRAVIS_BUILD_DIR/travis_cache"
72+
fi
73+
- tar -xz -f "${UNIXODBC_DM}.tar.gz"
74+
- cd "${UNIXODBC_DM}"
75+
- CPPFLAGS="-DSIZEOF_LONG_INT=8"
76+
- export CPPFLAGS
77+
- ./configure --prefix=/usr --sysconfdir=/etc --enable-iconv --with-iconv-char-enc=UTF8 --with-iconv-ucode-enc=UTF16LE 1> zzz_log_configure_std 2> zzz_log_configure_err
78+
- make 1> zzz_log_make_std 2> zzz_log_make_err
79+
- sudo make install 1> zzz_log_install_std 2> zzz_log_install_err
80+
- odbcinst --version
81+
# install MSSQL driver
82+
- sudo bash -c 'curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -'
83+
- sudo bash -c 'curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list > /etc/apt/sources.list.d/mssql-release.list'
84+
- sudo apt-get update
85+
- sudo ACCEPT_EULA=Y apt-get install msodbcsql17
86+
# install MySQL driver
87+
- cd /tmp
88+
- |
89+
if [ -f "$TRAVIS_BUILD_DIR/travis_cache/${MYSQL_DRIVER}.tar.gz" ]; then
90+
cp -v "$TRAVIS_BUILD_DIR/travis_cache/${MYSQL_DRIVER}.tar.gz" .
91+
else
92+
curl -sS -w "$CURL_OUTPUT_FORMAT" -O "https://www.mirrorservice.org/sites/ftp.mysql.com/Downloads/Connector-ODBC/8.0/${MYSQL_DRIVER}.tar.gz"
93+
fi
94+
- ls -l "${MYSQL_DRIVER}.tar.gz"
95+
- |
96+
if [ ! -f "$TRAVIS_BUILD_DIR/travis_cache/${MYSQL_DRIVER}.tar.gz" ]; then
97+
cp -v "${MYSQL_DRIVER}.tar.gz" "$TRAVIS_BUILD_DIR/travis_cache"
98+
fi
99+
- tar -v -xz -f "${MYSQL_DRIVER}.tar.gz"
100+
- sudo cp -v "${MYSQL_DRIVER}/lib/libmyodbc8a.so" /usr/lib/x86_64-linux-gnu/odbc/
101+
- sudo chmod a+r /usr/lib/x86_64-linux-gnu/odbc/libmyodbc8a.so
102+
- echo '[MySQL ODBC 8.0 ANSI Driver]' > mysql_odbcinst.ini
103+
- echo 'Driver = /usr/lib/x86_64-linux-gnu/odbc/libmyodbc8a.so' >> mysql_odbcinst.ini
104+
- echo 'UsageCount = 1' >> mysql_odbcinst.ini
105+
- echo 'Threading = 2' >> mysql_odbcinst.ini
106+
- sudo odbcinst -i -d -f mysql_odbcinst.ini
107+
# show cache
108+
- ls -l "$TRAVIS_BUILD_DIR/travis_cache"
109+
# odbc info
110+
- odbcinst -j
111+
- cat /etc/odbcinst.ini
112+
- cat /etc/odbc.ini
113+
# install pyodbc
114+
- cd "$TRAVIS_BUILD_DIR"
115+
- python -VV
19116
- python setup.py install
117+
- python -m pip freeze --all
118+
- python -c "import pyodbc; print(pyodbc.version)"
119+
120+
before_script:
121+
# set up SQL Server 2017 and 2019 in docker containers
122+
- docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=StrongPassword2017' -p 1401:1433 --name mssql2017 -d mcr.microsoft.com/mssql/server:2017-latest
123+
- docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=StrongPassword2019' -p 1402:1433 --name mssql2019 -d mcr.microsoft.com/mssql/server:2019-latest
124+
- sleep 10 # MSSQL in docker needs time to warm up: https://github.com/microsoft/mssql-docker/issues/203
125+
# create test databases in SQL Server
126+
- docker exec -it mssql2017 /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'StrongPassword2017' -Q "SELECT @@VERSION" || sleep 5
127+
- docker exec -it mssql2017 /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'StrongPassword2017' -Q "CREATE DATABASE test"
128+
- docker exec -it mssql2019 /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'StrongPassword2019' -Q "SELECT @@VERSION" || sleep 5
129+
- docker exec -it mssql2019 /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'StrongPassword2019' -Q "CREATE DATABASE test"
130+
# create test database in PostgreSQL
131+
- psql -c "SELECT version()" -U postgres
132+
- psql -c "CREATE DATABASE test WITH encoding='UTF8' LC_COLLATE='en_US.UTF-8' LC_CTYPE='en_US.UTF-8'" -U postgres
133+
- psql -l
134+
# create test database in MySQL
135+
- mysql -e "STATUS"
136+
- mysql -e "CREATE DATABASE test"
20137

21-
script: true
138+
script:
139+
- cd "$TRAVIS_BUILD_DIR"
140+
- if [ "$TRVS_VERBOSE" = "true" ]; then TESTARGS="--verbose"; else TESTARGS=""; fi
141+
# run SQL Server tests on MSSQL2017
142+
- python "./$TESTS_DIR/sqlservertests.py" $TESTARGS "DRIVER={ODBC Driver 17 for SQL Server};SERVER=localhost,1401;UID=sa;PWD=StrongPassword2017;DATABASE=test"
143+
# run SQL Server tests on MSSQL2019
144+
- python "./$TESTS_DIR/sqlservertests.py" $TESTARGS "DRIVER={ODBC Driver 17 for SQL Server};SERVER=localhost,1402;UID=sa;PWD=StrongPassword2019;DATABASE=test"
145+
# run PostgreSQL tests
146+
- python "./$TESTS_DIR/pgtests.py" $TESTARGS "DRIVER={PostgreSQL Unicode};SERVER=localhost;UID=postgres;DATABASE=test"
147+
# run MySQL tests
148+
- python "./$TESTS_DIR/mysqltests.py" $TESTARGS "DRIVER={MySQL ODBC 8.0 ANSI Driver};SERVER=localhost;DATABASE=test;CHARSET=utf8mb4"

tests3/pgtests.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,15 @@ def test_cursor_messages(self):
652652
self.assertTrue(type(self.cursor.messages[0][1]) is str)
653653
self.assertEqual('[01000] (-1)', self.cursor.messages[0][0])
654654
self.assertTrue(self.cursor.messages[0][1].endswith('hello world'))
655+
if os.getenv('CI') == 'true' and os.getenv('TRAVIS') == 'true':
656+
# On the current Travis CI platform (i.e. Ubuntu), this test generates the wrong
657+
# result, which appears to be a PostgreSQL issue. A bug report has been raised
658+
# with PostgreSQL: https://www.postgresql.org/message-id/16469-11c82a64f17f51f4%40postgresql.org
659+
# Nevertheless, the result is predictable so we will still test for that incorrect value.
660+
# This ensures the build passes and if this behavior ever changes, we will know about it.
661+
self.assertEqual(result, v.encode('utf-8').decode('latin-1'))
662+
else:
663+
self.assertEqual(result, v)
655664

656665
def test_output_conversion(self):
657666
# Note the use of SQL_WVARCHAR, not SQL_VARCHAR.

0 commit comments

Comments
 (0)