diff --git a/ci/docker/pandas-db-test.dockerfile b/ci/docker/pandas-db-test.dockerfile new file mode 100644 index 0000000000000..9270054ef6867 --- /dev/null +++ b/ci/docker/pandas-db-test.dockerfile @@ -0,0 +1,19 @@ +FROM python + +RUN apt-get update + +RUN python -m pip install --upgrade pip +RUN python -m pip install \ + cython \ + hypothesis \ + numpy \ + pymysql \ + psycopg2 \ + pytest \ + pytest-asyncio \ + python-dateutil \ + pytz \ + sqlalchemy + +WORKDIR /pandas + diff --git a/ci/scripts/run-db-tests.sh b/ci/scripts/run-db-tests.sh new file mode 100755 index 0000000000000..b6e5356b97316 --- /dev/null +++ b/ci/scripts/run-db-tests.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +set -e + +python setup.py build_ext --inplace -j4 +python -m pytest pandas/tests/io/test_sql.py diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000000000..257bda50101df --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,21 @@ +services: + testing: + build: + context: . + dockerfile: ci/docker/pandas-db-test.dockerfile + volumes: + - .:/pandas + command: /pandas/ci/scripts/run-db-tests.sh + + postgres-db: + image: postgres + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: pandas + + mysql-db: + image: mysql + environment: + MYSQL_ALLOW_EMPTY_PASSWORD: yes + MYSQL_DATABASE: pandas diff --git a/pandas/tests/io/test_sql.py b/pandas/tests/io/test_sql.py index e4318f1d79102..e57293d445a7b 100644 --- a/pandas/tests/io/test_sql.py +++ b/pandas/tests/io/test_sql.py @@ -381,7 +381,7 @@ def mysql_pymysql_engine(iris_path, types_data): sqlalchemy = pytest.importorskip("sqlalchemy") pymysql = pytest.importorskip("pymysql") engine = sqlalchemy.create_engine( - "mysql+pymysql://root@localhost:3306/pandas", + "mysql+pymysql://root@mysql-db:3306/pandas", connect_args={"client_flag": pymysql.constants.CLIENT.MULTI_STATEMENTS}, ) insp = sqlalchemy.inspect(engine) @@ -409,7 +409,7 @@ def postgresql_psycopg2_engine(iris_path, types_data): sqlalchemy = pytest.importorskip("sqlalchemy") pytest.importorskip("psycopg2") engine = sqlalchemy.create_engine( - "postgresql+psycopg2://postgres:postgres@localhost:5432/pandas" + "postgresql+psycopg2://postgres:postgres@postgres-db:5432/pandas" ) insp = sqlalchemy.inspect(engine) if not insp.has_table("iris"): @@ -1528,7 +1528,7 @@ def test_sql_open_close(self, test_frame3): @pytest.mark.skipif(SQLALCHEMY_INSTALLED, reason="SQLAlchemy is installed") def test_con_string_import_error(self): - conn = "mysql://root@localhost/pandas" + conn = "mysql://root@mysql-db/pandas" msg = "Using URI string without sqlalchemy installed" with pytest.raises(ImportError, match=msg): sql.read_sql("SELECT * FROM iris", conn) @@ -2382,7 +2382,7 @@ class _TestMySQLAlchemy: @classmethod def connect(cls): return sqlalchemy.create_engine( - f"mysql+{cls.driver}://root@localhost:{cls.port}/pandas", + f"mysql+{cls.driver}://root@mysql-db:{cls.port}/pandas", connect_args=cls.connect_args, ) @@ -2408,7 +2408,7 @@ class _TestPostgreSQLAlchemy: @classmethod def connect(cls): return sqlalchemy.create_engine( - f"postgresql+{cls.driver}://postgres:postgres@localhost:{cls.port}/pandas" + f"postgresql+{cls.driver}://postgres:postgres@postgres-db:{cls.port}/pandas" ) @classmethod