From 1136c9339cc8b14d8682acaa3fabeba0cf5d211b Mon Sep 17 00:00:00 2001 From: Cunliang Geng Date: Tue, 5 Dec 2023 16:51:30 +0100 Subject: [PATCH] Update test_utils.py - add docstrings - rename test function names --- tests/genomics/test_utils.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/tests/genomics/test_utils.py b/tests/genomics/test_utils.py index bcd5371b..15f07a52 100644 --- a/tests/genomics/test_utils.py +++ b/tests/genomics/test_utils.py @@ -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 @@ -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" @@ -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") @@ -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") @@ -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) @@ -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 @@ -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: @@ -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) @@ -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)