Skip to content

Commit

Permalink
Update tests for read_fasts
Browse files Browse the repository at this point in the history
  • Loading branch information
breimanntools committed May 3, 2024
1 parent b116798 commit 37b587c
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions tests/unit/data_handling_tests/test_read_fasta.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,35 @@
settings.register_profile("ci", deadline=400)
settings.load_profile("ci")

FILE_IN = "valid_path.fasta"
FILE_DB_IN = "valid_path_db.fasta"


class TestReadFasta:
"""Test the aa.read_fasta function by testing each parameter individually."""

# Property-based testing for positive cases
@given(file_path=st.text())
def test_file_path(self, file_path):
def test_file_path(self):
"""Test the 'file_path' parameter with valid and invalid paths."""
try:
df = aa.read_fasta(file_path)
assert isinstance(df, pd.DataFrame) # Expecting a DataFrame to be returned
except Exception as e:
assert isinstance(e, (FileNotFoundError, ValueError))
df = aa.read_fasta(file_path=FILE_IN)
assert isinstance(df, pd.DataFrame) # Expecting a DataFrame to be returned

@given(col_id=st.text(min_size=1))
def test_col_id(self, col_id):
"""Test valid 'col_id' parameter."""
df = aa.read_fasta("valid_path.fasta", col_id=col_id)
df = aa.read_fasta(file_path=FILE_IN, col_id=col_id)
assert col_id in df.columns

@given(col_seq=st.text(min_size=1))
def test_col_seq(self, col_seq):
"""Test valid 'col_seq' parameter."""
df = aa.read_fasta("valid_path.fasta", col_seq=col_seq)
df = aa.read_fasta(file_path=FILE_IN, col_seq=col_seq)
assert col_seq in df.columns

@given(cols_info=st.lists(st.text(min_size=1), min_size=1, max_size=1))
def test_cols_info(self, cols_info):
"""Test valid 'cols_info' parameter."""
df = aa.read_fasta("valid_path.fasta", cols_info=cols_info)
df = aa.read_fasta(file_path=FILE_IN, cols_info=cols_info)
for col in cols_info:
assert col in df.columns

Expand All @@ -46,7 +45,7 @@ def test_col_db(self, col_db):
"""Test valid 'col_db' parameter."""
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=UserWarning)
df = aa.read_fasta("valid_path_db.fasta", col_db=col_db)
df = aa.read_fasta(file_path=FILE_DB_IN, col_db=col_db)
if col_db:
assert col_db in df.columns

Expand All @@ -55,64 +54,64 @@ def test_sep(self, sep):
"""Test valid 'sep' parameter."""
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=UserWarning)
df = aa.read_fasta("valid_path.fasta", sep=sep)
df = aa.read_fasta(file_path=FILE_IN, sep=sep)
assert isinstance(df, pd.DataFrame)

# Property-based testing for negative cases
def test_invalid_col_id(self):
"""Test invalid 'col_id' parameter."""
for col_id in [None, [], {}, 34]:
with pytest.raises(ValueError):
aa.read_fasta("valid_path.fasta", col_id=col_id)
aa.read_fasta(file_path=FILE_IN, col_id=col_id)

def test_invalid_col_seq(self):
"""Test invalid 'col_seq' parameter."""
for col_seq in [None, [], {}, 34]:
with pytest.raises(ValueError):
aa.read_fasta("valid_path.fasta", col_seq=col_seq)
aa.read_fasta(file_path=FILE_IN, col_seq=col_seq)

def test_invalid_col_db(self):
"""Test invalid 'col_db' parameter."""
for col_db in [[], {}, 34]:
with pytest.raises(ValueError):
aa.read_fasta("valid_path_db.fasta", col_db=col_db)
aa.read_fasta(file_path=FILE_DB_IN, col_db=col_db)

def test_invalid_cols_info(self):
"""Test invalid 'cols_info' parameter."""
with pytest.raises(ValueError):
aa.read_fasta("valid_path.fasta", cols_info={})
aa.read_fasta(file_path=FILE_IN, cols_info={})
with pytest.raises(ValueError):
aa.read_fasta("valid_path.fasta", cols_info=34)
aa.read_fasta(file_path=FILE_IN, cols_info=34)
with pytest.raises(ValueError):
aa.read_fasta("valid_path.fasta", cols_info=[None])
aa.read_fasta(file_path=FILE_IN, cols_info=[None])

def test_invalid_sep(self):
"""Test invalid 'sep' parameter."""
for sep in [[], {}, 34]:
with pytest.raises(ValueError):
aa.read_fasta("valid_path.fasta", sep=sep)
aa.read_fasta(file_path=FILE_IN, sep=sep)


class TestReadFastaComplex:
"""Test aa.read_fasta function with complex scenarios"""

@given(file_path=st.text(), col_id=st.text(min_size=1), col_seq=st.text(min_size=1), sep=st.text(min_size=1, max_size=1))
def test_combination_valid_inputs(self, file_path, col_id, col_seq, sep):
@given(col_id=st.text(min_size=1), col_seq=st.text(min_size=1), sep=st.text(min_size=1, max_size=1))
def test_combination_valid_inputs(self, col_id, col_seq, sep):
"""Test valid combinations of parameters."""
try:
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=UserWarning)
df = aa.read_fasta(file_path, col_id=col_id, col_seq=col_seq, sep=sep)
df = aa.read_fasta(file_path=FILE_IN, col_id=col_id, col_seq=col_seq, sep=sep)
assert isinstance(df, pd.DataFrame)
assert col_id in df.columns
assert col_seq in df.columns
except Exception as e:
assert isinstance(e, (FileNotFoundError, ValueError))

@given(file_path=st.text(), col_id=st.text(max_size=0), col_seq=st.text(min_size=1), sep=st.text(min_size=1, max_size=1))
def test_combination_invalid(self, file_path, col_id, col_seq, sep):
@given(col_id=st.text(max_size=0), col_seq=st.text(min_size=1), sep=st.integers())
def test_combination_invalid(self, col_id, col_seq, sep):
"""Test invalid 'col_id' in combination with other parameters."""
with pytest.raises(ValueError):
aa.read_fasta(file_path, col_id=col_id, col_seq=col_seq, sep=sep)
aa.read_fasta(file_path=FILE_IN, col_id=col_id, col_seq=col_seq, sep=sep)


0 comments on commit 37b587c

Please sign in to comment.