Skip to content

Commit

Permalink
update test_gcf.py
Browse files Browse the repository at this point in the history
-  add unit tests for magic methods
- add docstring for test functions
  • Loading branch information
CunliangGeng committed Dec 11, 2023
1 parent 73e5180 commit dbaeb31
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion tests/genomics/test_gcf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@

@pytest.fixture()
def bgc_with_strain():
"""Return a BGC object that has a Strain."""
bgc = BGC("S0001", "NPR")
bgc.strain = Strain("strain001")
yield bgc


@pytest.fixture()
def bgc_without_strain():
"""Return a BGC object that does not have Strain."""
bgc = BGC("S002", "NPR")
yield bgc


def test_default():
def test_init():
"""Test the initialization of GCF."""
gcf = GCF("1")
assert gcf.gcf_id == "1"
assert gcf.bgcs == set()
Expand All @@ -27,14 +30,41 @@ def test_default():
assert gcf.bigscape_class is None


def test_str_repr_():
"""Test __str__ and __repr__ method."""
gcf = GCF("1")
assert str(gcf) == "GCF(id=1, #BGC_objects=0, #bgc_ids=0,#strains=0)."
assert repr(gcf) == "GCF(id=1, #BGC_objects=0, #bgc_ids=0,#strains=0)."


def test_eq():
"""Test __eq__ method."""
gcf1 = GCF("1")
gcf2 = GCF("1")
assert gcf1 == gcf2
gcf3 = GCF("2")
assert gcf1 != gcf3


def test_hash():
"""Test __hash__ method."""
gcf1 = GCF("1")
gcf2 = GCF("1")
assert hash(gcf1) == hash(gcf2)
gcf3 = GCF("2")
assert hash(gcf1) != hash(gcf3)


def test_add_bgc(bgc_with_strain):
"""Test add_bgc method."""
gcf = GCF("1")
gcf.add_bgc(bgc_with_strain)
assert gcf.bgcs == {bgc_with_strain}
assert bgc_with_strain.parents == {gcf}


def test_detach_bgc(bgc_with_strain):
"""Test detach_bgc method."""
gcf = GCF("1")
gcf.add_bgc(bgc_with_strain)
gcf.detach_bgc(bgc_with_strain)
Expand All @@ -44,6 +74,7 @@ def test_detach_bgc(bgc_with_strain):


def test_add_bgc_wo_strain(bgc_without_strain, caplog):
"""Test add_bgc method with a BGC that does have strain."""
gcf = GCF("1")
gcf.add_bgc(bgc_without_strain)
assert gcf.gcf_id == "1"
Expand All @@ -53,13 +84,15 @@ def test_add_bgc_wo_strain(bgc_without_strain, caplog):


def test_has_strain(bgc_with_strain):
"""Test has_strain method."""
gcf = GCF("1")
gcf.add_bgc(bgc_with_strain)
assert gcf.has_strain(Strain("strain001")) is True
assert gcf.has_strain(Strain("strain002")) is False


def test_has_mibig_only():
"""Test has_mibig_only method."""
mibig_bgc = BGC("BGC0000001", "NPR")
nonmibig_bgc = BGC("S0001", "NPR")
gcf = GCF("1")
Expand All @@ -73,6 +106,7 @@ def test_has_mibig_only():


def test_is_singleton():
"""Test is_singleton method."""
bgc1 = BGC("BGC0000001", "NPR")
bgc2 = BGC("BGC0000002", "NPR")
gcf = GCF("1")
Expand Down

0 comments on commit dbaeb31

Please sign in to comment.