Skip to content

Commit

Permalink
Add initial tests for the database
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Feb 12, 2024
1 parent cf71cc3 commit 13f7fba
Show file tree
Hide file tree
Showing 4 changed files with 230 additions and 1 deletion.
163 changes: 162 additions & 1 deletion poetry.lock

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

4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ ipdb = ">=0.12.3"
black = ">=24.1.1"
ruff = ">=0.1.0"
pandas-stubs = "^2.1.4.231227"
pytest = "^8.0.0"
pytest-sugar = "^1.0.0"
pytest-cov = "^4.1.0"
coverage = "^7.4.1"

[tool.black]
line-length = 88
Expand Down
27 changes: 27 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# @Author: José Sánchez-Gallego ([email protected])
# @Date: 2024-02-11
# @Filename: conftest.py
# @License: BSD 3-clause (http://www.opensource.org/licenses/BSD-3-Clause)

from __future__ import annotations

import pytest


DBNAME: str = "sdss5db_too_test"


@pytest.fixture(autouse=True, scope="session")
def sdss5db():
"""A fixture that returns a connection to the ToO test database."""

from sdssdb.peewee import sdss5db

sdss5db.database.connect(DBNAME)

yield

sdss5db.database.close()
37 changes: 37 additions & 0 deletions tests/test_database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# @Author: José Sánchez-Gallego ([email protected])
# @Date: 2024-02-11
# @Filename: test_database.py
# @License: BSD 3-clause (http://www.opensource.org/licenses/BSD-3-Clause)

from __future__ import annotations

from conftest import DBNAME
from sdssdb.peewee.sdss5db import catalogdb


def test_database_exists():
assert catalogdb.Catalog.table_exists()
assert catalogdb.database.dbname == DBNAME

n_catalog = catalogdb.Catalog.select().count()
assert n_catalog > 1000000 and n_catalog < 10000000


def test_models_exist():
assert catalogdb.SDSS_DR13_PhotoObj.table_exists()
assert catalogdb.CatalogToSDSS_DR13_PhotoObj_Primary.table_exists() # type: ignore
assert catalogdb.SDSS_DR13_PhotoObj.select().count() > 1
assert catalogdb.CatalogToSDSS_DR13_PhotoObj_Primary.select().count() > 1 # type: ignore

assert catalogdb.Gaia_DR3.table_exists()
assert catalogdb.CatalogToGaia_DR3.table_exists() # type: ignore
assert catalogdb.Gaia_DR3.select().count() > 1
assert catalogdb.CatalogToGaia_DR3.select().count() > 1 # type: ignore

assert catalogdb.TwoMassPSC.table_exists()
assert catalogdb.CatalogToTwoMassPSC.table_exists() # type: ignore
assert catalogdb.TwoMassPSC.select().count() > 1
assert catalogdb.CatalogToTwoMassPSC.select().count() > 1 # type: ignore

0 comments on commit 13f7fba

Please sign in to comment.