@@ -411,8 +411,7 @@ def test_convert_to_date(self, MockLookUpData):
411411 # 5. Not a string input (should trigger "Value is not a string")
412412 result = checker ._convertToDate ("%Y%m%d" , "fieldName" , 12345678 , False , True )
413413 self .assertEqual (result , "" )
414-
415-
414+
416415 # 6. Future date for birthDate (should trigger "Date cannot be in the future")
417416 future_date = (datetime .now () + timedelta (days = 365 )).strftime ("%Y%m%d" )
418417 result = checker ._convertToDate ("%Y%m%d" , "contained|#:Patient|birthDate" , future_date , False , True )
@@ -475,6 +474,38 @@ def test_convert_to_date_time(self, MockLookUpData):
475474 result = checker ._convertToDateTime ("format:%Y%m%dT%H%M%S" , "fieldName" , "" , False , True )
476475 self .assertEqual (result , "" )
477476
477+ @patch ("ConversionChecker.LookUpData" )
478+ def test_convert_to_boolean (self , MockLookUpData ):
479+ dataParser = Mock ()
480+
481+ checker = ConversionChecker (dataParser , summarise = False , report_unexpected_exception = True )
482+
483+ # Arrange
484+ dataParser = Mock ()
485+ checker = ConversionChecker (dataParser , summarise = False , report_unexpected_exception = True )
486+
487+ # 1. Boolean True passes through
488+ result = checker ._convertToBoolean (None , "f" , True , False , True )
489+ self .assertTrue (result )
490+
491+ # 2. Boolean False passes through
492+ result = checker ._convertToBoolean (None , "f" , False , False , True )
493+ self .assertFalse (result )
494+
495+ # 3. String "true" variants
496+ for val in ["true" , "TRUE" , " True " , "\t TrUe\n " ]:
497+ result = checker ._convertToBoolean (None , "f" , val , False , False )
498+ self .assertTrue (result )
499+
500+ # 4. String "false" variants
501+ for val in ["false" , "FALSE" , " False " , "\n FaLsE\t " ]:
502+ result = checker ._convertToBoolean (None , "f" , val , False , False )
503+ self .assertFalse (result )
504+
505+ # 5. Invalid string with report_unexpected_exception=False → no log
506+ result = checker ._convertToBoolean (None , "f" , "notbool" , False , False )
507+ self .assertEqual (result , "" )
508+
478509 #check for dose sequence
479510 @patch ("ConversionChecker.LookUpData" )
480511 def test_convert_to_dose (self , MockLookUpData ):
0 commit comments