Skip to content

Commit

Permalink
Runs full testsuite including containerized MariaDB test service
Browse files Browse the repository at this point in the history
  • Loading branch information
gremid committed Dec 16, 2024
1 parent 4929e2d commit b69c966
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 51 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ jobs:
db:
image: mariadb:10
env:
MYSQL_DATABASE: "test"
MYSQL_USER: "test"
MYSQL_PASSWORD: "test"
MYSQL_DATABASE: "wp"
MYSQL_USER: "wp"
MYSQL_PASSWORD: "wp"
MYSQL_RANDOM_ROOT_PASSWORD: "yes"
ports:
- 3306:3306
Expand All @@ -36,4 +36,4 @@ jobs:
pip install -U pip pipenv
pipenv install --system --deploy --categories='packages api build prep dev-packages'
- name: Run tests
run: pytest tests/integration_test.py tests/test_connector.py
run: WP_SKIP_TEST_DB_FIXTURE=1 pytest
11 changes: 9 additions & 2 deletions docker-compose.yml → compose.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
name: wordprofile
services:
db:
image: mariadb:10
Expand All @@ -6,15 +7,21 @@ services:
MYSQL_USER: "wp"
MYSQL_PASSWORD: "wp"
MYSQL_RANDOM_ROOT_PASSWORD: "yes"
user: ${USER_GROUP}
volumes:
- ./data/db:/var/lib/mysql
- db:/var/lib/mysql
ports:
- "3306:3306"
command:
- "mysqld"
- "--character-set-server=utf8mb4"
- "--collation-server=utf8mb4_unicode_ci"
healthcheck:
test: [ "CMD", "healthcheck.sh", "--connect", "--innodb_initialized" ]
start_period: 1m
start_interval: 10s
interval: 1m
timeout: 5s
retries: 3
api:
image: docker.zdl.org/zdl-wordprofile/api
build:
Expand Down
29 changes: 0 additions & 29 deletions docker-compose-test.yml

This file was deleted.

20 changes: 17 additions & 3 deletions tests/test_connector.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import os
import pathlib
from subprocess import check_call
import unittest
from time import sleep

import pytest
import sqlalchemy as sq

import wordprofile.wpse.create as wc
Expand All @@ -10,9 +14,19 @@
from wordprofile.wpse.processing import load_files_into_db


@pytest.fixture(autouse=True, scope="session")
def test_db():
if os.environ.get("WP_SKIP_TEST_DB_FIXTURE"):
yield False
else:
check_call(["docker", "compose", "-p", "wp_test", "up", "db", "--wait"])
yield True
check_call(["docker", "compose", "-p", "wp_test", "down", "db", "-v"])


def create_database():
engine = sq.create_engine(
"mysql+pymysql://test:test@localhost:3306/test?charset=utf8mb4&local_infile=1"
"mysql+pymysql://wp:wp@localhost:3306/wp?charset=utf8mb4&local_infile=1"
)
with engine.connect() as conn:
wc.init_word_profile_tables(conn, "test")
Expand All @@ -27,7 +41,7 @@ class WPConnectTest(unittest.TestCase):
def setUpClass(cls):
create_database()
cls.connector = WPConnect(
host="localhost", user="test", passwd="test", dbname="test"
host="localhost", user="wp", passwd="wp", dbname="wp"
)

def test_random_examples_extracted(self):
Expand Down Expand Up @@ -309,7 +323,7 @@ class WPMweConnectTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.connector = WPMweConnect(
host="localhost", user="test", passwd="test", dbname="test"
host="localhost", user="wp", passwd="wp", dbname="wp"
)

def test_random_examples_extracted_for_mwe(self):
Expand Down
5 changes: 0 additions & 5 deletions tests/test_db.py

This file was deleted.

8 changes: 0 additions & 8 deletions wordprofile/wpse/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@


def init_word_profile_tables(connection: Connection, database: str):
connection.execute(text(f"DROP DATABASE IF EXISTS {database}"))
connection.execute(
text(
f"CREATE DATABASE {database} CHARACTER SET = utf8mb4 COLLATE = utf8mb4_bin"
)
)
connection.execute(text("USE " + database))

meta = MetaData()
wordprofile.wpse.db_tables.get_table_corpus_files(meta)
wordprofile.wpse.db_tables.get_table_concord_sentences(meta)
Expand Down

0 comments on commit b69c966

Please sign in to comment.