@@ -706,5 +706,42 @@ def test_read_inchikey_error(self):
706706 self .assertTrue ('InChIKey is a write-only format' in str (cm .exception ))
707707
708708
709+ class IdentifierFailureLoggingTest (unittest .TestCase ):
710+ """When neither backend can canonicalize a molecule into InChI / InChIKey
711+ (e.g. malformed resonance structures from RMG perception), the translator
712+ and the four Molecule wrappers must raise ValueError but emit nothing at
713+ WARNING level or above. The caller (resonance dedup, etc.) routinely
714+ swallows the ValueError; the previous WARNING + ERROR-with-traceback pair
715+ was log spam."""
716+
717+ def _assert_wrapper_logs_below_warning (self , wrapper_name , translator_func_name ):
718+ """Patch the underlying translator function to raise, call the
719+ Molecule wrapper, and verify the wrapper re-raises while emitting only
720+ DEBUG-level (not WARNING/ERROR) log records."""
721+ from arc .molecule import translator as t
722+ mol = Molecule ().from_smiles ('C' )
723+ with patch .object (t , translator_func_name ,
724+ side_effect = ValueError ('mocked-out backend' )):
725+ with self .assertLogs ('arc' , level = 'DEBUG' ) as cm :
726+ with self .assertRaises (ValueError ):
727+ getattr (mol , wrapper_name )()
728+ for record in cm .records :
729+ self .assertLess (record .levelno , 30 , # WARNING == 30
730+ f"Unexpected { record .levelname } log line from "
731+ f"{ wrapper_name } : { record .getMessage ()} " )
732+
733+ def test_to_inchi_wrapper_logs_only_at_debug_on_failure (self ):
734+ self ._assert_wrapper_logs_below_warning ('to_inchi' , 'to_inchi' )
735+
736+ def test_to_inchi_key_wrapper_logs_only_at_debug_on_failure (self ):
737+ self ._assert_wrapper_logs_below_warning ('to_inchi_key' , 'to_inchi_key' )
738+
739+ def test_to_augmented_inchi_wrapper_logs_only_at_debug_on_failure (self ):
740+ self ._assert_wrapper_logs_below_warning ('to_augmented_inchi' , 'to_inchi' )
741+
742+ def test_to_augmented_inchi_key_wrapper_logs_only_at_debug_on_failure (self ):
743+ self ._assert_wrapper_logs_below_warning ('to_augmented_inchi_key' , 'to_inchi_key' )
744+
745+
709746if __name__ == '__main__' :
710747 unittest .main (testRunner = unittest .TextTestRunner (verbosity = 2 ))
0 commit comments