Skip to content

Commit

Permalink
Note/dev (#22)
Browse files Browse the repository at this point in the history
* Add testing steps into the CI/CD pipeline.
* edit Unix timestamp to be able to handle in a different timezone.
  • Loading branch information
silenus092 authored May 5, 2023
1 parent d2b2648 commit 03ef30c
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 20 deletions.
47 changes: 46 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,50 @@ on:
- main
- dev
jobs:
testing:
runs-on: ubuntu-latest
services:
redis:
image: redis
ports:
- 6379:6379
mariadb:
image: mariadb:10.11
env:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: mpx_test_04
MYSQL_USER: test_user
MYSQL_PASSWORD: test_password
ports:
- 3306:3306
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.10'
- name: Install dependencies
run: |
sudo apt install libmariadb3 libmariadb-dev
pip install poetry
- name: Poetry install env.
run: poetry install
- name: Load database
run: |
mysql --protocol=tcp -h localhost --user=root --password=password -e "CREATE DATABASE IF NOT EXISTS mpx_test_04;"
mysql --protocol=tcp -h localhost --user=root --password=password -e "GRANT ALL PRIVILEGES ON mpx_test_04.* TO 'test_user'@'%' IDENTIFIED BY 'test_password';"
mysql --protocol=tcp -h localhost --user=root --password=password mpx_test_04 < tests/sql_dumps/mpx_test_04.sql
mysql --protocol=tcp -h localhost --user=root --password=password -e "use mpx_test_04; SHOW TABLES;"
- name: Run pytest
env:
DB_URL: "https://test_user:[email protected]:3306/mpx_test_04"
REDIS_URL: "redis://127.0.0.1:6379"
REDIS_DB_BROKER: 1
REDIS_DB_BACKEND: 1
DEBUG: True
LOG_LEVEL: "DEBUG"
run: poetry run pytest -rfeP -x tests/
format-checker:
runs-on: ubuntu-latest
steps:
Expand All @@ -15,6 +59,7 @@ jobs:
uses: actions/setup-python@v3
with:
python-version: '3.10'
- run: pip install flake8 poetry
- name: Install dependencies
run: pip install flake8 poetry
- name: Run flake8 - Code style check
run: poetry run flake8 . --config=.flake8 -v
26 changes: 13 additions & 13 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mpire = "2.6.0"
pandas = "~1.4.0"
requests = "^2.28.0"
python-dotenv = "^0.21.0"
mariadb = "^1.1.4"
mariadb = "^1.1.6"
psutil = "^5.9.3"
dash-bootstrap-components = "^1.2.1"
dash = {extras = ["celery"], version = "^2.7.1"}
Expand Down
43 changes: 43 additions & 0 deletions tests/sql_dumps/mpx_test_04.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
-- Table structure for table `alignment`
--

CREATE DATABASE IF NOT EXISTS mpx_test_04;

DROP TABLE IF EXISTS `alignment`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
Expand Down Expand Up @@ -464,6 +466,47 @@ CREATE TABLE `variantView` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

-- Function Table
CREATE FUNCTION IF NOT EXISTS `mpx_test_04`.DB_VERSION() RETURNS INTEGER RETURN 1;
-- VIEW Table
DROP VIEW IF EXISTS `mpx_test_04`.`referenceView`;
CREATE VIEW `mpx_test_04`.`referenceView` AS
SELECT
`reference`.id AS "reference.id",
`reference`.accession AS "reference.accession",
`reference`.`description` AS "reference.description",
`reference`.organism AS "reference.organism",
`reference`.standard AS "reference.standard",
`reference`.translation_id AS "translation.id",
molecule.id AS "molecule.id",
molecule.`type` AS "molecule.type",
molecule.accession AS "molecule.accession",
molecule.symbol AS "molecule.symbol",
molecule.`description` AS "molecule.description",
molecule.`length` AS "molecule.length",
molecule.segment AS "molecule.segment",
molecule.standard AS "molecule.standard",
element.id AS "element.id",
element.type AS "element.type",
element.accession AS "element.accession",
element.symbol AS "element.symbol",
element.description AS "element.description",
element.start AS "element.start",
element.`end` AS "element.end",
element.strand AS "element.strand",
element.sequence AS "element.sequence",
elempart.`start` AS "elempart.start",
elempart.`end` AS "elempart.end",
elempart.strand AS "elempart.strand",
elempart.segment AS "elempart.segment"
FROM
`mpx_test_04`.reference
LEFT JOIN `mpx_test_04`.molecule ON reference.id = molecule.reference_id
LEFT JOIN `mpx_test_04`.element ON molecule.id = element.molecule_id
LEFT JOIN `mpx_test_04`.elempart ON element.id = elempart.element_id;



--
-- Dumping data for table `variantView`
--
Expand Down
25 changes: 21 additions & 4 deletions tests/test_date_slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from pages.utils_worldMap_explorer import DateSlider

DB_DUMP_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), "sql_dumps")
# os.environ['TZ'] = 'Europe/Germany'
# os.system('tzutil /s "Central Standard Time"')


class TestDateSlider(unittest.TestCase):
Expand All @@ -26,14 +28,29 @@ def test_dates(self):
assert len(self.date_slider.date_list) == 96

def test_unix_time_millis(self):
assert 1670022000 == DateSlider.unix_time_millis(date(2022, 12, 3))
# HACK: the problem is if you're using Unix timestamps in your pytest tests
# and the timezone of the Github Actions or any testing instance
# environment is different from the timezone used
# to generate the Unix timestamps, you may get unexpected results.
# , that is why we use list to capture either 2022-12-2 or 2022-12-3.
assert DateSlider.unix_time_millis(date(2022, 12, 3)) in [
1670022000,
1670025600,
]
# assert 1670022000 == DateSlider.unix_time_millis(date(2022, 12, 3))

def test_unix_to_date(self):
assert DateSlider.unix_to_date(1669935600) == date(2022, 12, 2)
assert DateSlider.unix_to_date(1672527600) == date(2023, 1, 1)
assert DateSlider.unix_to_date(1669939200) == date(2022, 12, 2)
assert DateSlider.unix_to_date(1672531200) == date(2023, 1, 1)

# assert DateSlider.unix_to_date(1669935600) == date(2022, 12, 2)
# assert DateSlider.unix_to_date(1672527600) == date(2023, 1, 1)

def test_get_all_dates_in_interval(self):
dates = [1669935600, 1672527600]
dates = [1671840000, 1672531200]

# dates = [1671836400, 1672527600] start from date(2022, 12, 24)
# dates = [1669935600, 1672527600] default
interval = 9
date_list = self.date_slider.get_all_dates_in_interval(dates, interval)
correct_dates = [
Expand Down
2 changes: 1 addition & 1 deletion tests/test_db_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_world_df(self):
}
for reference in [2, 4]:
for completeness in ["complete", "partial"]:
print((world_dfs[completeness][reference].head()))
# print((world_dfs[completeness][reference].head()))
assert (
list(world_dfs[completeness][reference].columns)
== DbProperties.world_df_columns
Expand Down

0 comments on commit 03ef30c

Please sign in to comment.