Skip to content

Commit

Permalink
#887: add test for calculate avail mem
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Sep 20, 2016
1 parent 0f53f7f commit 043752f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions psutil/tests/test_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,22 @@ def open_mock(*args, **kwargs):
self.assertEqual(ret.active, 0)
self.assertEqual(ret.inactive, 0)

def test_calculate_avail(self):
from psutil._pslinux import calculate_avail_vmem
from psutil._pslinux import open_binary

mems = {}
with open_binary('/proc/meminfo') as f:
for line in f:
fields = line.split()
mems[fields[0]] = int(fields[1]) * 1024

a = calculate_avail_vmem(mems)
if b'MemAvailable:' in mems:
b = mems[b'MemAvailable:']
diff_percent = abs(a - b) / a * 100
self.assertLess(diff_percent, 2)


# =====================================================================
# system swap memory
Expand Down

0 comments on commit 043752f

Please sign in to comment.