Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Other header information should not change
self.assertEqual(info0['aggregationMethod'],
info1['aggregationMethod'])
self.assertEqual(info0['maxRetention'], info1['maxRetention'])
self.assertEqual(info0['archives'], info1['archives'])
# packing and unpacking because
# AssertionError: 0.20000000298023224 != 0.2
target_xff = struct.unpack("!f", struct.pack("!f", target_xff))[0]
self.assertEqual(info1['xFilesFactor'], target_xff)
with AssertRaisesException(
whisper.InvalidXFilesFactor('Invalid xFilesFactor zero, not a '
'float')):
whisper.setXFilesFactor(self.filename, "zero")
for invalid_xff in -1, 2:
with AssertRaisesException(
whisper.InvalidXFilesFactor('Invalid xFilesFactor %s, not '
'between 0 and 1' %
float(invalid_xff))):
whisper.setXFilesFactor(self.filename, invalid_xff)
# packing and unpacking because
# AssertionError: 0.20000000298023224 != 0.2
target_xff = struct.unpack("!f", struct.pack("!f", target_xff))[0]
self.assertEqual(info1['xFilesFactor'], target_xff)
with AssertRaisesException(
whisper.InvalidXFilesFactor('Invalid xFilesFactor zero, not a '
'float')):
whisper.setXFilesFactor(self.filename, "zero")
for invalid_xff in -1, 2:
with AssertRaisesException(
whisper.InvalidXFilesFactor('Invalid xFilesFactor %s, not '
'between 0 and 1' %
float(invalid_xff))):
whisper.setXFilesFactor(self.filename, invalid_xff)
def test_set_xfilesfactor(self):
"""
Create a whisper file
Update xFilesFactor
Check if update succeeded
Check if exceptions get raised with wrong input
"""
whisper.create(self.filename, [(1, 20)])
target_xff = 0.42
info0 = whisper.info(self.filename)
old_xff = whisper.setXFilesFactor(self.filename, target_xff)
# return value should match old xff
self.assertEqual(info0['xFilesFactor'], old_xff)
info1 = whisper.info(self.filename)
# Other header information should not change
self.assertEqual(info0['aggregationMethod'],
info1['aggregationMethod'])
self.assertEqual(info0['maxRetention'], info1['maxRetention'])
self.assertEqual(info0['archives'], info1['archives'])
# packing and unpacking because
# AssertionError: 0.20000000298023224 != 0.2
target_xff = struct.unpack("!f", struct.pack("!f", target_xff))[0]
self.assertEqual(info1['xFilesFactor'], target_xff)
with AssertRaisesException(
def main():
"""Set xFilesFactor for existing whisper file"""
parser = argparse.ArgumentParser(
description='Set xFilesFactor for existing whisper file')
parser.add_argument('path', type=str, help='path to whisper file')
parser.add_argument('xff', metavar='xFilesFactor', type=float,
help='new xFilesFactor, a float between 0 and 1')
args = parser.parse_args()
try:
old_xff = whisper.setXFilesFactor(args.path, args.xff)
except IOError:
sys.stderr.write("[ERROR] File '%s' does not exist!\n\n" % args.path)
parser.print_help()
sys.exit(1)
except whisper.WhisperException as exc:
raise SystemExit('[ERROR] %s' % str(exc))
print('Updated xFilesFactor: %s (%s -> %s)' %
(args.path, old_xff, args.xff))