Beispiel #1
0
 def diagnose_binaryblock(klass, binaryblock, endianness=None):
     ''' Run checks over header binary data, return string '''
     hdr = klass(binaryblock, endianness=endianness, check=False)
     battrun = BatteryRunner(klass._get_checks())
     reports = battrun.check_only(hdr)
     return '\n'.join([report.message
                       for report in reports if report.message])
Beispiel #2
0
 def check_fix(self,
           logger=imageglobals.logger,
           error_level=imageglobals.error_level):
     ''' Check header data with checks '''
     battrun = BatteryRunner(self.__class__._get_checks())
     self, reports = battrun.check_fix(self)
     for report in reports:
         report.log_raise(logger, error_level)
def test_checks():
    battrun = BatteryRunner((chk1,))
    reports = battrun.check_only({})
    yield assert_equal, reports[0], Report({},
                                           KeyError,
                                           20,
                                           'no "testkey"',
                                           '')
    obj, reports = battrun.check_fix({})    
    yield assert_equal, reports[0], Report({'testkey':1},
                                           KeyError,
                                           0,
                                           'no "testkey"',
                                           'added "testkey"')
    yield assert_equal, obj, {'testkey':1}
    battrun = BatteryRunner((chk1,chk2))
    reports = battrun.check_only({})
    yield assert_equal, reports[0], Report({},
                                           KeyError,
                                           20,
                                           'no "testkey"',
                                           '')
    yield assert_equal, reports[1], Report({},
                                           KeyError,
                                           20,
                                           'no "testkey"',
                                           '')
    obj, reports = battrun.check_fix({})
    # In the case of fix, the previous fix exposes a different error
    # Note, because obj is mutable, first and second point to modified
    # (and final) dictionary
    output_obj = {'testkey':0}
    yield assert_equal, reports[0], Report(output_obj,
                                           KeyError,
                                           0,
                                           'no "testkey"',
                                           'added "testkey"')
    yield assert_equal, reports[1], Report(output_obj,
                                           ValueError,
                                           0,
                                           '"testkey" != 0',
                                           'set "testkey" to 0')
    yield assert_equal, obj, output_obj