aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/db
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2022-02-14 06:56:32 +0300
committerFrederick Muriuki Muriithi2022-02-17 06:37:30 +0300
commit74044f3c7985308b4996da3a52f91c5c20a19194 (patch)
treed86714b859b31cbbd1755522f8abd8eed16e321b /tests/unit/db
parent67f517aa0f44f55dc691ffd791bf22ef7af0b02c (diff)
downloadgenenetwork3-74044f3c7985308b4996da3a52f91c5c20a19194.tar.gz
Use pytest's "mark" feature to categorise tests
Use pytest's `mark` feature to explicitly categorise the tests and run them per category
Diffstat (limited to 'tests/unit/db')
-rw-r--r--tests/unit/db/test_audit.py3
-rw-r--r--tests/unit/db/test_correlation.py4
-rw-r--r--tests/unit/db/test_datasets.py6
-rw-r--r--tests/unit/db/test_db.py8
-rw-r--r--tests/unit/db/test_genotypes.py6
-rw-r--r--tests/unit/db/test_species.py5
-rw-r--r--tests/unit/db/test_traits.py15
7 files changed, 47 insertions, 0 deletions
diff --git a/tests/unit/db/test_audit.py b/tests/unit/db/test_audit.py
index 7480169..884afc6 100644
--- a/tests/unit/db/test_audit.py
+++ b/tests/unit/db/test_audit.py
@@ -3,6 +3,8 @@ import json
from unittest import TestCase
from unittest import mock
+import pytest
+
from gn3.db import insert
from gn3.db.metadata_audit import MetadataAudit
@@ -10,6 +12,7 @@ from gn3.db.metadata_audit import MetadataAudit
class TestMetadatAudit(TestCase):
"""Test cases for fetching chromosomes"""
+ @pytest.mark.unit_test
def test_insert_into_metadata_audit(self):
"""Test that data is inserted correctly in the audit table
diff --git a/tests/unit/db/test_correlation.py b/tests/unit/db/test_correlation.py
index 3f940b2..5afe55f 100644
--- a/tests/unit/db/test_correlation.py
+++ b/tests/unit/db/test_correlation.py
@@ -4,6 +4,8 @@ Tests for the gn3.db.correlations module
from unittest import TestCase
+import pytest
+
from gn3.db.correlations import (
build_query_sgo_lit_corr,
build_query_tissue_corr)
@@ -12,6 +14,7 @@ class TestCorrelation(TestCase):
"""Test cases for correlation data fetching functions"""
maxDiff = None
+ @pytest.mark.unit_test
def test_build_query_sgo_lit_corr(self):
"""
Test that the literature correlation query is built correctly.
@@ -53,6 +56,7 @@ class TestCorrelation(TestCase):
"ORDER BY Probeset.Id"),
2))
+ @pytest.mark.unit_test
def test_build_query_tissue_corr(self):
"""
Test that the tissue correlation query is built correctly.
diff --git a/tests/unit/db/test_datasets.py b/tests/unit/db/test_datasets.py
index 0b8c2fe..5b86db9 100644
--- a/tests/unit/db/test_datasets.py
+++ b/tests/unit/db/test_datasets.py
@@ -1,6 +1,7 @@
"""Tests for gn3/db/datasets.py"""
from unittest import mock, TestCase
+import pytest
from gn3.db.datasets import (
retrieve_dataset_name,
retrieve_group_fields,
@@ -11,6 +12,7 @@ from gn3.db.datasets import (
class TestDatasetsDBFunctions(TestCase):
"""Test cases for datasets functions."""
+ @pytest.mark.unit_test
def test_retrieve_dataset_name(self):
"""Test that the function is called correctly."""
for trait_type, thresh, trait_name, dataset_name, columns, table, expected in [
@@ -42,6 +44,7 @@ class TestDatasetsDBFunctions(TestCase):
table=table, cols=columns),
{"threshold": thresh, "name": dataset_name})
+ @pytest.mark.unit_test
def test_retrieve_probeset_group_fields(self):
"""
Test that the `group` and `group_id` fields are retrieved appropriately
@@ -65,6 +68,7 @@ class TestDatasetsDBFunctions(TestCase):
" AND ProbeSetFreeze.Name = %(name)s"),
{"name": trait_name})
+ @pytest.mark.unit_test
def test_retrieve_group_fields(self):
"""
Test that the group fields are set up correctly for the different trait
@@ -90,6 +94,7 @@ class TestDatasetsDBFunctions(TestCase):
trait_type, trait_name, dataset_info, db_mock),
expected)
+ @pytest.mark.unit_test
def test_retrieve_publish_group_fields(self):
"""
Test that the `group` and `group_id` fields are retrieved appropriately
@@ -112,6 +117,7 @@ class TestDatasetsDBFunctions(TestCase):
" AND PublishFreeze.Name = %(name)s"),
{"name": trait_name})
+ @pytest.mark.unit_test
def test_retrieve_geno_group_fields(self):
"""
Test that the `group` and `group_id` fields are retrieved appropriately
diff --git a/tests/unit/db/test_db.py b/tests/unit/db/test_db.py
index e47c9fd..8ac468c 100644
--- a/tests/unit/db/test_db.py
+++ b/tests/unit/db/test_db.py
@@ -2,6 +2,8 @@
from unittest import TestCase
from unittest import mock
+import pytest
+
from gn3.db import fetchall
from gn3.db import fetchone
from gn3.db import update
@@ -14,6 +16,7 @@ from gn3.db.metadata_audit import MetadataAudit
class TestCrudMethods(TestCase):
"""Test cases for CRUD methods"""
+ @pytest.mark.unit_test
def test_update_phenotype_with_no_data(self):
"""Test that a phenotype is updated correctly if an empty Phenotype dataclass
is provided
@@ -24,6 +27,7 @@ class TestCrudMethods(TestCase):
conn=db_mock, table="Phenotype",
data=Phenotype(), where=Phenotype()), None)
+ @pytest.mark.unit_test
def test_update_phenotype_with_data(self):
"""
Test that a phenotype is updated correctly if some
@@ -46,6 +50,7 @@ class TestCrudMethods(TestCase):
"Submitter = %s WHERE id = %s AND Owner = %s",
('Test Pre Pub', 'Test Post Pub', 'Rob', 1, 'Rob'))
+ @pytest.mark.unit_test
def test_fetch_phenotype(self):
"""Test that a single phenotype is fetched properly
@@ -68,6 +73,7 @@ class TestCrudMethods(TestCase):
"SELECT * FROM Phenotype WHERE id = %s AND Owner = %s",
(35, 'Rob'))
+ @pytest.mark.unit_test
def test_fetchall_metadataaudit(self):
"""Test that multiple metadata_audit entries are fetched properly
@@ -96,6 +102,7 @@ class TestCrudMethods(TestCase):
"dataset_id = %s AND editor = %s"),
(35, 'Rob'))
+ @pytest.mark.unit_test
# pylint: disable=R0201
def test_probeset_called_with_right_columns(self):
"""Given a columns argument, test that the correct sql query is
@@ -112,6 +119,7 @@ class TestCrudMethods(TestCase):
"Name = %s",
("1446112_at",))
+ @pytest.mark.unit_test
def test_diff_from_dict(self):
"""Test that a correct diff is generated"""
self.assertEqual(diff_from_dict({"id": 1, "data": "a"},
diff --git a/tests/unit/db/test_genotypes.py b/tests/unit/db/test_genotypes.py
index c125224..28728bf 100644
--- a/tests/unit/db/test_genotypes.py
+++ b/tests/unit/db/test_genotypes.py
@@ -1,5 +1,6 @@
"""Tests gn3.db.genotypes"""
from unittest import TestCase
+import pytest
from gn3.db.genotypes import (
parse_genotype_file,
parse_genotype_labels,
@@ -10,6 +11,7 @@ from gn3.db.genotypes import (
class TestGenotypes(TestCase):
"""Tests for functions in `gn3.db.genotypes`."""
+ @pytest.mark.unit_test
def test_parse_genotype_labels(self):
"""Test that the genotype labels are parsed correctly."""
self.assertEqual(
@@ -22,6 +24,7 @@ class TestGenotypes(TestCase):
("type", "test_type"), ("mat", "test_mat"), ("pat", "test_pat"),
("het", "test_het"), ("unk", "test_unk")))
+ @pytest.mark.unit_test
def test_parse_genotype_header(self):
"""Test that the genotype header is parsed correctly."""
for header, expected in [
@@ -43,6 +46,7 @@ class TestGenotypes(TestCase):
with self.subTest(header=header):
self.assertEqual(parse_genotype_header(header), expected)
+ @pytest.mark.unit_test
def test_parse_genotype_data_line(self):
"""Test parsing of data lines."""
for line, geno_obj, parlist, expected in [
@@ -76,6 +80,7 @@ class TestGenotypes(TestCase):
parse_genotype_marker(line, geno_obj, parlist),
expected)
+ @pytest.mark.unit_test
def test_build_genotype_chromosomes(self):
"""
Given `markers` and `geno_obj`, test that `build_genotype_chromosomes`
@@ -115,6 +120,7 @@ class TestGenotypes(TestCase):
build_genotype_chromosomes(geno_obj, markers),
expected)
+ @pytest.mark.unit_test
def test_parse_genotype_file(self):
"""Test the parsing of genotype files. """
self.assertEqual(
diff --git a/tests/unit/db/test_species.py b/tests/unit/db/test_species.py
index b2c4844..e883b21 100644
--- a/tests/unit/db/test_species.py
+++ b/tests/unit/db/test_species.py
@@ -2,6 +2,8 @@
from unittest import TestCase
from unittest import mock
+import pytest
+
from gn3.db.species import get_chromosome
from gn3.db.species import get_all_species
@@ -9,6 +11,7 @@ from gn3.db.species import get_all_species
class TestChromosomes(TestCase):
"""Test cases for fetching chromosomes"""
+ @pytest.mark.unit_test
def test_get_chromosome_using_species_name(self):
"""Test that the chromosome is fetched using a species name"""
db_mock = mock.MagicMock()
@@ -24,6 +27,7 @@ class TestChromosomes(TestCase):
"Species.Name = 'TestCase' ORDER BY OrderId"
)
+ @pytest.mark.unit_test
def test_get_chromosome_using_group_name(self):
"""Test that the chromosome is fetched using a group name"""
db_mock = mock.MagicMock()
@@ -39,6 +43,7 @@ class TestChromosomes(TestCase):
"InbredSet.Name = 'TestCase' ORDER BY OrderId"
)
+ @pytest.mark.unit_test
def test_get_all_species(self):
"""Test that species are fetched correctly"""
db_mock = mock.MagicMock()
diff --git a/tests/unit/db/test_traits.py b/tests/unit/db/test_traits.py
index f3e0bab..d7c0b27 100644
--- a/tests/unit/db/test_traits.py
+++ b/tests/unit/db/test_traits.py
@@ -1,5 +1,6 @@
"""Tests for gn3/db/traits.py"""
from unittest import mock, TestCase
+import pytest
from gn3.db.traits import (
build_trait_name,
export_trait_data,
@@ -49,6 +50,7 @@ trait_data = {
class TestTraitsDBFunctions(TestCase):
"Test cases for traits functions"
+ @pytest.mark.unit_test
def test_retrieve_publish_trait_info(self):
"""Test retrieval of type `Publish` traits."""
db_mock = mock.MagicMock()
@@ -83,6 +85,7 @@ class TestTraitsDBFunctions(TestCase):
" AND PublishXRef.InbredSetId = %(trait_dataset_id)s"),
trait_source)
+ @pytest.mark.unit_test
def test_retrieve_probeset_trait_info(self):
"""Test retrieval of type `Probeset` traits."""
db_mock = mock.MagicMock()
@@ -118,6 +121,7 @@ class TestTraitsDBFunctions(TestCase):
"AND ProbeSetFreeze.Name = %(trait_dataset_name)s "
"AND ProbeSet.Name = %(trait_name)s"), trait_source)
+ @pytest.mark.unit_test
def test_retrieve_geno_trait_info(self):
"""Test retrieval of type `Geno` traits."""
db_mock = mock.MagicMock()
@@ -141,6 +145,7 @@ class TestTraitsDBFunctions(TestCase):
"AND Geno.Name = %(trait_name)s"),
trait_source)
+ @pytest.mark.unit_test
def test_retrieve_temp_trait_info(self):
"""Test retrieval of type `Temp` traits."""
db_mock = mock.MagicMock()
@@ -153,6 +158,7 @@ class TestTraitsDBFunctions(TestCase):
"SELECT name, description FROM Temp WHERE Name = %(trait_name)s",
trait_source)
+ @pytest.mark.unit_test
def test_build_trait_name_with_good_fullnames(self):
"""
Check that the name is built correctly.
@@ -169,6 +175,7 @@ class TestTraitsDBFunctions(TestCase):
with self.subTest(fullname=fullname):
self.assertEqual(build_trait_name(fullname), expected)
+ @pytest.mark.unit_test
def test_build_trait_name_with_bad_fullnames(self):
"""
Check that an exception is raised if the full name format is wrong.
@@ -178,6 +185,7 @@ class TestTraitsDBFunctions(TestCase):
with self.assertRaises(AssertionError, msg="Name format error"):
build_trait_name(fullname)
+ @pytest.mark.unit_test
def test_retrieve_trait_info(self):
"""Test that information on traits is retrieved as appropriate."""
for threshold, trait_fullname, expected in [
@@ -194,6 +202,7 @@ class TestTraitsDBFunctions(TestCase):
threshold, trait_fullname, db_mock),
expected)
+ @pytest.mark.unit_test
def test_update_sample_data(self):
"""Test that the SQL queries when calling update_sample_data are called with
the right calls.
@@ -242,6 +251,7 @@ class TestTraitsDBFunctions(TestCase):
mock.call(N_STRAIN_SQL, (2, 1, 1))]
)
+ @pytest.mark.unit_test
def test_set_haveinfo_field(self):
"""Test that the `haveinfo` field is set up correctly"""
for trait_info, expected in [
@@ -250,6 +260,7 @@ class TestTraitsDBFunctions(TestCase):
with self.subTest(trait_info=trait_info, expected=expected):
self.assertEqual(set_haveinfo_field(trait_info), expected)
+ @pytest.mark.unit_test
def test_set_homologene_id_field(self):
"""Test that the `homologene_id` field is set up correctly"""
for trait_type, trait_info, expected in [
@@ -264,6 +275,7 @@ class TestTraitsDBFunctions(TestCase):
self.assertEqual(
set_homologene_id_field(trait_type, trait_info, db_mock), expected)
+ @pytest.mark.unit_test
def test_set_confidential_field(self):
"""Test that the `confidential` field is set up correctly"""
for trait_type, trait_info, expected in [
@@ -275,6 +287,7 @@ class TestTraitsDBFunctions(TestCase):
self.assertEqual(
set_confidential_field(trait_type, trait_info), expected)
+ @pytest.mark.unit_test
def test_export_trait_data_dtype(self):
"""
Test `export_trait_data` with different values for the `dtype` keyword
@@ -290,6 +303,7 @@ class TestTraitsDBFunctions(TestCase):
export_trait_data(trait_data, samplelist, dtype=dtype),
expected)
+ @pytest.mark.unit_test
def test_export_trait_data_dtype_all_flags(self):
"""
Test `export_trait_data` with different values for the `dtype` keyword
@@ -331,6 +345,7 @@ class TestTraitsDBFunctions(TestCase):
n_exists=nflag),
expected)
+ @pytest.mark.unit_test
def test_export_informative(self):
"""Test that the function exports appropriate data."""
# pylint: disable=W0621