def validate_log_output(self, passed, db_data, user_data, oper):
        """Format the validation log output to be easier to read.

        Args:
            passed (bool): The results of the validation test.
            db_data (str): The data store in Redis.
            user_data (str): The user provided data.
            oper (str): The comparison operator.

        Raises:
            RuntimeError: Raise error on validation failure if halt_on_fail is True.
        """
        truncate = self.args.truncate
        if db_data is not None and passed:
            if isinstance(db_data, (string_types)) and len(db_data) > truncate:
                db_data = db_data[:truncate]
            elif isinstance(db_data, (list)):
                db_data_truncated = []
                for d in db_data:
                    if d is not None and isinstance(d, string_types) and len(d) > truncate:
                        db_data_truncated.append('{} ...'.format(d[: self.args.truncate]))
                    else:
                        db_data_truncated.append(d)
                db_data = db_data_truncated

        if user_data is not None and passed:
            if isinstance(user_data, (string_types)) and len(user_data) > truncate:
                user_data = user_data[: self.args.truncate]
            elif isinstance(user_data, (list)):
                user_data_truncated = []
                for u in user_data:
                    if isinstance(db_data, (string_types)) and len(u) > truncate:
                        user_data_truncated.append('{} ...'.format(u[: self.args.truncate]))
                    else:
                        user_data_truncated.append(u)
                user_data = user_data_truncated

        self.log.info('[validate] DB Data   : ({}), Type: [{}]'.format(db_data, type(db_data)))
        self.log.info('[validate] Operator  : ({})'.format(oper))
        self.log.info('[validate] User Data : ({}), Type: [{}]'.format(user_data, type(user_data)))

        if passed:
            self.log.info('[validate] Results   : Passed')
        else:
            self.log.error('[validate] Results  : Failed')
            if db_data is not None and user_data is not None and oper in ['eq', 'ne']:
                try:
                    diff_count = 0
                    for i, diff in enumerate(difflib.ndiff(db_data, user_data)):
                        if diff[0] == ' ':  # no difference
                            continue
                        elif diff[0] == '-':
                            self.log.info(
                                '[validate] Diff      : Missing data at index {}'.format(i)
                            )
                        elif diff[0] == '+':
                            self.log.info('[validate] Diff      : Extra data at index {}'.format(i))
                        if diff_count > self.max_diff:
                            # don't spam the logs if string are vastly different
                            self.log.info('Max number of differences reached.')
                            break
                        diff_count += 1
                except TypeError:
                    pass
                except KeyError:
                    pass

            # halt all further actions
            if self.args.halt_on_fail:
                raise RuntimeError('Failed validating data.')
def validate_log_output ( self , passed , db_data , user_data , oper ) : truncate = self . args . truncate if db_data is not None and passed : if isinstance ( db_data , ( string_types ) ) and len ( db_data ) > truncate : db_data = db_data [ : truncate ] elif isinstance ( db_data , ( list ) ) : db_data_truncated = [ ] for d in db_data : if d is not None and isinstance ( d , string_types ) and len ( d ) > truncate : db_data_truncated . append ( '{} ...' . format ( d [ : self . args . truncate ] ) ) else : db_data_truncated . append ( d ) db_data = db_data_truncated if user_data is not None and passed : if isinstance ( user_data , ( string_types ) ) and len ( user_data ) > truncate : user_data = user_data [ : self . args . truncate ] elif isinstance ( user_data , ( list ) ) : user_data_truncated = [ ] for u in user_data : if isinstance ( db_data , ( string_types ) ) and len ( u ) > truncate : user_data_truncated . append ( '{} ...' . format ( u [ : self . args . truncate ] ) ) else : user_data_truncated . append ( u ) user_data = user_data_truncated self . log . info ( '[validate] DB Data   : ({}), Type: [{}]' . format ( db_data , type ( db_data ) ) ) self . log . info ( '[validate] Operator  : ({})' . format ( oper ) ) self . log . info ( '[validate] User Data : ({}), Type: [{}]' . format ( user_data , type ( user_data ) ) ) if passed : self . log . info ( '[validate] Results   : Passed' ) else : self . log . error ( '[validate] Results  : Failed' ) if db_data is not None and user_data is not None and oper in [ 'eq' , 'ne' ] : try : diff_count = 0 for i , diff in enumerate ( difflib . ndiff ( db_data , user_data ) ) : if diff [ 0 ] == ' ' : continue elif diff [ 0 ] == '-' : self . log . info ( '[validate] Diff      : Missing data at index {}' . format ( i ) ) elif diff [ 0 ] == '+' : self . log . info ( '[validate] Diff      : Extra data at index {}' . format ( i ) ) if diff_count > self . max_diff : self . log . info ( 'Max number of differences reached.' ) break diff_count += 1 except TypeError : pass except KeyError : pass if self . args . halt_on_fail : raise RuntimeError ( 'Failed validating data.' )
Format the validation log output to be easier to read.

        Args:
            passed (bool): The results of the validation test.
            db_data (str): The data store in Redis.
            user_data (str): The user provided data.
            oper (str): The comparison operator.

        Raises:
            RuntimeError: Raise error on validation failure if halt_on_fail is True.