Skip to content

Commit

Permalink
Merge pull request #145 from Knowledge-Graph-Hub/add_tests
Browse files Browse the repository at this point in the history
Add tests
  • Loading branch information
deepakunni3 committed May 9, 2020
2 parents 83e5f46 + ae58c67 commit 985eab2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
Binary file added tests/resources/gene2ensembl.gz
Binary file not shown.
Binary file added tests/resources/gene_info.gz
Binary file not shown.
4 changes: 3 additions & 1 deletion tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ def test_transform(self):

def test_merge_missing_file_error(self):
with self.assertRaises(FileNotFoundError) as context:
self.runner.invoke(catch_exceptions=False,
result = self.runner.invoke(catch_exceptions=False,
cli=load,
args=['-y',
'tests/resources/merge_MISSING_FILE.yaml']
)
self.assertNotEqual(result.exit_code, 0)
self.assertRegexpMatches(result.output, "does not exist")

41 changes: 41 additions & 0 deletions tests/test_transform_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,19 @@
from unittest import TestCase

from parameterized import parameterized
from kg_covid_19.transform import DATA_SOURCES
from kg_covid_19.transform_utils.transform import Transform
from kg_covid_19.transform_utils.drug_central.drug_central import DrugCentralTransform
from kg_covid_19.transform_utils.intact.intact import IntAct
from kg_covid_19.transform_utils.ontology import OntologyTransform
from kg_covid_19.transform_utils.ontology.ontology_transform import ONTOLOGIES
from kg_covid_19.transform_utils.\
sars_cov_2_gene_annot.sars_cov_2_gene_annot import SARSCoV2GeneAnnot
from kg_covid_19.transform_utils.pharmgkb import PharmGKB
from kg_covid_19.transform_utils.scibite_cord import ScibiteCordTransform
from kg_covid_19.transform_utils.string_ppi import StringTransform
from kg_covid_19.transform_utils.ttd.ttd import TTDTransform
from kg_covid_19.transform_utils.zhou_host_proteins.zhou_transform import ZhouTransform


class TestTransform(TestCase):
Expand Down Expand Up @@ -30,6 +42,35 @@ def test_attributes(self, attr, default):
self.assertTrue(hasattr(self.transform_instance, attr))
self.assertEqual(getattr(self.transform_instance, attr), default)

@parameterized.expand([
('DEFAULT_INPUT_DIR', 'data/raw'),
('DEFAULT_OUTPUT_DIR', 'data/transformed')])
def test_default_dir(self, dir_var_name, dir_var_value):
self.assertEqual(getattr(Transform, dir_var_name), dir_var_value)

@parameterized.expand(list(DATA_SOURCES.keys()),)
def test_transform_child_classes(self, src_name):
"""
Make sure Transform child classes:
- properly set default input_dir and output_dir
- properly pass and set input_dir and output from constructor
- implement run()
:param src_name:
:return: None
"""
input_dir = os.path.join('tests','resources')
output_dir = os.path.join('output')
def_input_dir = os.path.join('data', 'raw')
def_output_dir = os.path.join('data', 'transformed')

t = DATA_SOURCES[src_name](input_dir=input_dir, output_dir=output_dir)
self.assertEqual(t.input_base_dir, input_dir)
self.assertEqual(t.output_base_dir, output_dir)
self.assertTrue(hasattr(t, 'run'))
self.assertEqual(t.DEFAULT_INPUT_DIR, def_input_dir)
self.assertEqual(t.DEFAULT_OUTPUT_DIR, def_output_dir)


class TransformChildClass(Transform):
def __init__(self):
Expand Down

0 comments on commit 985eab2

Please sign in to comment.