Skip to content

Commit

Permalink
Merge pull request #1128 from biozz/fix-mem-info-not-reliable
Browse files Browse the repository at this point in the history
Fix mem_info readings to be more reliable
  • Loading branch information
k4nar authored Apr 3, 2020
2 parents 422d64d + 29738ad commit bfa2189
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions circus/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ def test_convert_opt(self):
self.assertEqual(util.convert_opt('test', 1), '1')

def test_bytes2human(self):
self.assertEqual(bytes2human(10000), '9K')
self.assertEqual(bytes2human(100001221), '95M')
self.assertEqual(bytes2human(100), '100B')
self.assertEqual(bytes2human(10000), '9.77K')
self.assertEqual(bytes2human(100001221), '95.37M')
self.assertEqual(bytes2human(1024 * 1024 * 2047), '2.00G')
self.assertRaises(TypeError, bytes2human, '1')

def test_human2bytes(self):
Expand All @@ -102,6 +104,8 @@ def test_human2bytes(self):
self.assertEqual(human2bytes('1129M'), 1183842304)
self.assertEqual(human2bytes('67T'), 73667279060992)
self.assertEqual(human2bytes('13P'), 14636698788954112)
self.assertEqual(human2bytes('1.99G'), 2136746229)
self.assertEqual(human2bytes('2.00G'), 2147483648)
self.assertRaises(ValueError, human2bytes, '')
self.assertRaises(ValueError, human2bytes, 'faoej')
self.assertRaises(ValueError, human2bytes, '123KB')
Expand Down
4 changes: 2 additions & 2 deletions circus/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ def bytes2human(n):

for s in reversed(_SYMBOLS):
if n >= prefix[s]:
value = int(float(n) / prefix[s])
return '%s%s' % (value, s)
value = round(float(n) / prefix[s], 2)
return '{:.2f}{}'.format(value, s)
return "%sB" % n


Expand Down

0 comments on commit bfa2189

Please sign in to comment.