22import sys
33import types
44from types import SimpleNamespace
5- from unittest .mock import MagicMock , patch
5+ from unittest .mock import MagicMock , call , patch
66
77import pytest
88
@@ -73,13 +73,23 @@ def test_execute_calls_level_dag_and_entropy_graph_and_logs_tables():
7373 wf ._reporter .log_tables .assert_called_once ()
7474
7575
76- def test_execute_water_entropy_branch_calls_water_entropy_solver ():
76+ @pytest .mark .parametrize (
77+ ("nonwater_groups" , "expect_warning" ),
78+ [
79+ ({0 : [0 ]}, False ),
80+ ({}, True ),
81+ ],
82+ )
83+ def test_execute_water_entropy_branch_calls_water_entropy_solver (
84+ nonwater_groups , expect_warning
85+ ):
7786 args = SimpleNamespace (
7887 start = 0 ,
7988 end = - 1 ,
8089 step = 1 ,
8190 grouping = "molecules" ,
8291 water_entropy = True ,
92+ water_entropy_parallel = True ,
8393 selection_string = "all" ,
8494 output_file = "out.json" ,
8595 )
@@ -105,15 +115,19 @@ def test_execute_water_entropy_branch_calls_water_entropy_solver():
105115 wf ._build_reduced_universe = MagicMock (return_value = MagicMock ())
106116 wf ._detect_levels = MagicMock (return_value = {0 : ["united_atom" ]})
107117
108- wf ._split_water_groups = MagicMock (return_value = ({ 0 : [ 0 ]} , {9 : [1 , 2 ]}))
118+ wf ._split_water_groups = MagicMock (return_value = (nonwater_groups , {9 : [1 , 2 ]}))
109119 wf ._finalize_molecule_results = MagicMock ()
110120
111- wf ._group_molecules .grouping_molecules .return_value = {0 : [0 ], 9 : [1 , 2 ]}
121+ wf ._group_molecules .grouping_molecules .return_value = {
122+ ** nonwater_groups ,
123+ 9 : [1 , 2 ],
124+ }
112125
113126 with (
114127 patch ("CodeEntropy.entropy.workflow.WaterEntropy" ) as WaterCls ,
115128 patch ("CodeEntropy.entropy.workflow.LevelDAG" ) as LevelDAGCls ,
116129 patch ("CodeEntropy.entropy.workflow.EntropyGraph" ) as GraphCls ,
130+ patch ("CodeEntropy.entropy.workflow.logger" ) as logger ,
117131 ):
118132 water_instance = WaterCls .return_value
119133 water_instance .calculate_and_log = MagicMock ()
@@ -125,6 +139,8 @@ def test_execute_water_entropy_branch_calls_water_entropy_solver():
125139
126140 water_instance .calculate_and_log .assert_called_once ()
127141 _ , kwargs = water_instance .calculate_and_log .call_args
142+ warning = call ("You are running waterEntropy on bulk water, this will be slow!" )
143+ assert (warning in logger .warning .call_args_list ) is expect_warning
128144 assert kwargs ["universe" ] is universe
129145 assert kwargs ["start" ] == 0
130146 assert kwargs ["end" ] == 5
@@ -291,6 +307,7 @@ def test_compute_water_entropy_updates_selection_string_and_calls_internal_metho
291307 args = SimpleNamespace (
292308 selection_string = "all" ,
293309 water_entropy = True ,
310+ water_entropy_parallel = True ,
294311 temperature = 298.0 ,
295312 )
296313 wf = EntropyWorkflow (
@@ -317,6 +334,7 @@ def test_compute_water_entropy_updates_selection_string_and_calls_internal_metho
317334 start = 0 ,
318335 end = 5 ,
319336 step = 1 ,
337+ parallel = True ,
320338 group_id = 9 ,
321339 )
322340 assert wf ._args .selection_string == "not water"
@@ -428,6 +446,7 @@ def test_compute_water_entropy_instantiates_waterentropy_and_updates_selection_s
428446 args = SimpleNamespace (
429447 selection_string = "all" ,
430448 water_entropy = True ,
449+ water_entropy_parallel = True ,
431450 temperature = 298.0 ,
432451 )
433452 universe = MagicMock ()
@@ -458,6 +477,7 @@ def test_compute_water_entropy_instantiates_waterentropy_and_updates_selection_s
458477 start = 0 ,
459478 end = 5 ,
460479 step = 1 ,
480+ parallel = True ,
461481 group_id = 9 ,
462482 )
463483 assert args .selection_string == "not water"
@@ -771,6 +791,7 @@ def test_compute_water_entropy_appends_not_water_to_existing_selection():
771791 args = SimpleNamespace (
772792 selection_string = "protein" ,
773793 water_entropy = True ,
794+ water_entropy_parallel = True ,
774795 temperature = 298.0 ,
775796 output_file = "out.json" ,
776797 )
@@ -789,6 +810,7 @@ def test_compute_water_entropy_appends_not_water_to_existing_selection():
789810 start = 0 ,
790811 end = 5 ,
791812 step = 1 ,
813+ parallel = True ,
792814 group_id = 9 ,
793815 )
794816 assert args .selection_string == "protein and not water"
0 commit comments