From 37b587c887878a0a5626d1d60627971e478362a6 Mon Sep 17 00:00:00 2001 From: stephanbreimann Date: Fri, 3 May 2024 13:48:17 +0200 Subject: [PATCH] Update tests for read_fasts --- .../data_handling_tests/test_read_fasta.py | 49 +++++++++---------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/tests/unit/data_handling_tests/test_read_fasta.py b/tests/unit/data_handling_tests/test_read_fasta.py index 46808581..c8ad87cd 100644 --- a/tests/unit/data_handling_tests/test_read_fasta.py +++ b/tests/unit/data_handling_tests/test_read_fasta.py @@ -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 @@ -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 @@ -55,7 +54,7 @@ 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 @@ -63,56 +62,56 @@ 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)