Skip to content

Commit

Permalink
Update test_utils.py
Browse files Browse the repository at this point in the history
- add docstrings
- rename test function names
  • Loading branch information
CunliangGeng committed Dec 5, 2023
1 parent d3b9eb9 commit 1136c93
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions tests/genomics/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@


def test_generate_mappings_genome_id_bgc_id(tmp_path):
"""Test generate_mappings_genome_id_bgc_id function."""
bgc_dir = DATA_DIR / "antismash"

# using default output file path
Expand Down Expand Up @@ -50,6 +51,7 @@ def test_generate_mappings_genome_id_bgc_id(tmp_path):


def test_generate_mappings_genome_id_bgc_id_empty_dir(tmp_path, caplog):
"""Test generate_mappings_genome_id_bgc_id function with empty dir."""
# prepare dir and file
bgc_dir = tmp_path / "GCF_1"
bgc_file = bgc_dir / "BGC_1.gbk"
Expand All @@ -70,6 +72,7 @@ def test_generate_mappings_genome_id_bgc_id_empty_dir(tmp_path, caplog):

@pytest.fixture
def strain_collection() -> StrainCollection:
"""Return a StrainCollection object."""
sc = StrainCollection()

strain = Strain("STRAIN_01")
Expand All @@ -89,11 +92,13 @@ def strain_collection() -> StrainCollection:

@pytest.fixture
def bgc_list() -> list[BGC]:
"""Return a list of BGC objects."""
return [BGC("BGC_01", "NPR"), BGC("BGC_02", "Alkaloid"), BGC("SAMPLE_BGC_03", "Polyketide")]


@pytest.fixture
def gcf_list() -> list[GCF]:
"""Return a list of GCF objects."""
gcf1 = GCF("1")
gcf1.bgc_ids |= {"BGC_01"}
gcf2 = GCF("2")
Expand All @@ -103,12 +108,14 @@ def gcf_list() -> list[GCF]:

@pytest.fixture
def gcf_list_error() -> list[GCF]:
"""Return a list of GCF objects for testing errors."""
gcf1 = GCF("1")
gcf1.bgc_ids |= {"SAMPLE_BGC_03", "BGC_04"}
return [gcf1]


def test_map_strain_to_bgc(strain_collection, bgc_list):
def test_add_strain_to_bgc(strain_collection, bgc_list):
"""Test add_strain_to_bgc function."""
for bgc in bgc_list:
assert bgc.strain is None
add_strain_to_bgc(strain_collection, bgc_list)
Expand All @@ -119,14 +126,16 @@ def test_map_strain_to_bgc(strain_collection, bgc_list):
assert bgc_list[2].strain.id == "SAMPLE_BGC_03"


def test_map_strain_to_bgc_error(strain_collection):
def test_add_strain_to_bgc_error(strain_collection):
"""Test add_strain_to_bgc function error."""
bgcs = [BGC("BGC_04", "NPR")]
with pytest.raises(ValueError) as e:
add_strain_to_bgc(strain_collection, bgcs)
assert "Strain id 'BGC_04' from BGC object 'BGC_04' not found" in e.value.args[0]


def test_map_bgc_to_gcf(bgc_list, gcf_list):
def test_add_bgc_to_gcf(bgc_list, gcf_list):
"""Test add_bgc_to_gcf function."""
assert gcf_list[0].bgc_ids == {"BGC_01"}
assert gcf_list[1].bgc_ids == {"BGC_02", "SAMPLE_BGC_03"}
assert len(gcf_list[0].bgcs) == 0
Expand All @@ -140,7 +149,8 @@ def test_map_bgc_to_gcf(bgc_list, gcf_list):
assert gcf_list[1].bgcs == set(bgc_list[1:])


def test_map_bgc_to_gcf_error(bgc_list, gcf_list_error):
def test_add_bgc_to_gcf_error(bgc_list, gcf_list_error):
"""Test add_bgc_to_gcf function error."""
assert gcf_list_error[0].bgc_ids == {"SAMPLE_BGC_03", "BGC_04"}
assert len(gcf_list_error[0].bgcs) == 0
with pytest.raises(KeyError) as e:
Expand All @@ -149,6 +159,7 @@ def test_map_bgc_to_gcf_error(bgc_list, gcf_list_error):


def test_get_bgcs_from_gcfs(bgc_list, gcf_list):
"""Test get_bgcs_from_gcfs function."""
add_bgc_to_gcf(bgc_list, gcf_list)
bgcs = get_bgcs_from_gcfs(gcf_list)
assert isinstance(bgcs, list)
Expand All @@ -158,6 +169,7 @@ def test_get_bgcs_from_gcfs(bgc_list, gcf_list):


def test_get_strains_from_bgcs(strain_collection, bgc_list):
"""Test get_strains_from_bgcs function."""
add_strain_to_bgc(strain_collection, bgc_list)
strains = get_strains_from_bgcs(bgc_list)
assert isinstance(strains, StrainCollection)
Expand Down

0 comments on commit 1136c93

Please sign in to comment.