77import pytest
88import numpy as np
99import sys
10+ import warnings
1011from unittest .mock import patch , MagicMock , call
1112from basicrta .cluster import ProcessProtein
1213from basicrta .tests .utils import work_in
@@ -22,10 +23,11 @@ def test_init_with_default_values(self):
2223 assert pp .niter == 110000
2324 assert pp .prot == "test_protein"
2425 assert pp .cutoff == 7.0
25- assert pp .gskip == 1000 # Default value from paper
26+ assert pp .gskip == 100 # Default value from paper
2627 assert pp .burnin == 10000 # Default value from paper
2728 assert pp .taus is None
2829 assert pp .bars is None
30+ assert pp .residues is None
2931
3032 def test_init_with_custom_values (self ):
3133 """Test initialization with custom gskip and burnin values."""
@@ -50,7 +52,7 @@ def test_getitem_method(self):
5052 assert pp ["niter" ] == 110000
5153 assert pp ["prot" ] == "test_protein"
5254 assert pp ["cutoff" ] == 7.0
53- assert pp ["gskip" ] == 1000
55+ assert pp ["gskip" ] == 100
5456 assert pp ["burnin" ] == 10000
5557
5658 def test_single_residue_missing_file (self , tmp_path ):
@@ -69,8 +71,9 @@ def test_single_residue_missing_file(self, tmp_path):
6971 assert tau == [0 , 0 , 0 ]
7072 assert result is None
7173
74+ @pytest .mark .parametrize ("gskip" , [111 , 100 , 50 , 10 ])
7275 @patch ('basicrta.cluster.Gibbs' )
73- def test_single_residue_with_file (self , mock_gibbs , tmp_path ):
76+ def test_single_residue_with_file (self , mock_gibbs , tmp_path , gskip ):
7477 """Test _single_residue method when gibbs file exists."""
7578 # Create a mock directory structure
7679 residue_dir = tmp_path / "basicrta-7.0" / "R123"
@@ -83,23 +86,53 @@ def test_single_residue_with_file(self, mock_gibbs, tmp_path):
8386 # Configure the mock
8487 mock_gibbs_instance = MagicMock ()
8588 mock_gibbs_instance .estimate_tau .return_value = [0.1 , 1.5 , 3.0 ]
89+ mock_gibbs_instance .g = 50
8690 mock_gibbs .return_value .load .return_value = mock_gibbs_instance
8791
88- pp = ProcessProtein (niter = 110000 , prot = "test_protein" , cutoff = 7.0 )
92+ pp = ProcessProtein (niter = 110000 , prot = "test_protein" , gskip = gskip , cutoff = 7.0 )
8993
9094 # Call the method with processing enabled
91- residue , tau , result = pp ._single_residue (str (residue_dir ), process = True )
95+ with warnings .catch_warnings ():
96+ warnings .simplefilter ("ignore" , UserWarning )
97+ residue , tau , result = pp ._single_residue (str (residue_dir ), process = True )
9298
93- # Verify results
9499 assert residue == "R123"
95100 assert tau == [0.1 , 1.5 , 3.0 ]
96101 assert result == str (gibbs_file )
97102
98- # Verify the Gibbs object was configured correctly
99- assert mock_gibbs_instance .gskip == 1000
103+ # Verify the Gibbs object was re-configured correctly
104+ ggskip = gskip // mock_gibbs_instance .g
105+ if ggskip < 1 :
106+ ggskip = 1
107+ assert mock_gibbs_instance .gskip == ggskip
100108 assert mock_gibbs_instance .burnin == 10000
101109 mock_gibbs_instance .process_gibbs .assert_called_once ()
102110
111+ @patch ('basicrta.cluster.Gibbs' )
112+ def test_single_residue_with_file_gskip_warning (self , mock_gibbs , tmp_path ):
113+ """Test _single_residue method warns when gskip is less than g."""
114+ # Create a mock directory structure
115+ residue_dir = tmp_path / "basicrta-7.0" / "R123"
116+ residue_dir .mkdir (parents = True )
117+
118+ # Create a mock gibbs pickle file
119+ gibbs_file = residue_dir / "gibbs_110000.pkl"
120+ gibbs_file .touch ()
121+
122+ # Configure the mock
123+ mock_gibbs_instance = MagicMock ()
124+ mock_gibbs_instance .estimate_tau .return_value = [0.1 , 1.5 , 3.0 ]
125+ mock_gibbs_instance .g = 50
126+ mock_gibbs .return_value .load .return_value = mock_gibbs_instance
127+
128+ pp = ProcessProtein (niter = 110000 , prot = "test_protein" , gskip = 10 , cutoff = 7.0 )
129+ with pytest .warns (UserWarning ,
130+ match = "WARNING: gskip=10 is less than g=50, setting gskip to 1" ):
131+ residue , tau , result = pp ._single_residue (str (residue_dir ), process = True )
132+
133+ assert pp .gskip == 10
134+ assert mock_gibbs_instance .gskip == 1
135+
103136 @patch ('basicrta.cluster.Gibbs' )
104137 def test_single_residue_exception_handling (self , mock_gibbs , tmp_path ):
105138 """Test _single_residue method handles exceptions gracefully."""
0 commit comments