summaryrefslogtreecommitdiff
path: root/psutil/tests/test_bsd.py
diff options
context:
space:
mode:
authorDenis Krienbühl <denis@href.ch>2018-03-29 20:12:10 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2018-03-29 14:12:10 -0400
commita4c07e9da0f7a3a92b27c856eec09954ccc824ca (patch)
tree429c2abe56e35217f56e9b6b7d6519a063f7af27 /psutil/tests/test_bsd.py
parentbf9f8ff572d946b069660278cfe15054b05804e1 (diff)
downloadpsutil-a4c07e9da0f7a3a92b27c856eec09954ccc824ca.tar.gz
Fixes swap_memory not returning bytes on FreeBSD (#1260)
Diffstat (limited to 'psutil/tests/test_bsd.py')
-rwxr-xr-xpsutil/tests/test_bsd.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/psutil/tests/test_bsd.py b/psutil/tests/test_bsd.py
index d3868ada..63cae66a 100755
--- a/psutil/tests/test_bsd.py
+++ b/psutil/tests/test_bsd.py
@@ -344,6 +344,40 @@ class FreeBSDSpecificTestCase(unittest.TestCase):
# self.assertAlmostEqual(psutil.cpu_stats().traps,
# sysctl('vm.stats.sys.v_trap'), delta=1000)
+ # --- swap memory
+ @staticmethod
+ def parse_swapinfo():
+
+ # the last line is always the total
+ output = sh("swapinfo -k").splitlines()[-1]
+ parts = re.split(r'\s+', output)
+
+ if not parts:
+ raise ValueError("Can't parse swapinfo: %s" % output)
+
+ # the size is in 1k units, so multiply by 1024
+ total, used, free = (int(p) * 1024 for p in parts[1:4])
+
+ return total, used, free
+
+ def test_swapmem_free(self):
+ total, used, free = self.parse_swapinfo()
+
+ self.assertAlmostEqual(
+ psutil.swap_memory().free, free, delta=MEMORY_TOLERANCE)
+
+ def test_swapmem_used(self):
+ total, used, free = self.parse_swapinfo()
+
+ self.assertAlmostEqual(
+ psutil.swap_memory().used, used, delta=MEMORY_TOLERANCE)
+
+ def test_swapmem_total(self):
+ total, used, free = self.parse_swapinfo()
+
+ self.assertAlmostEqual(
+ psutil.swap_memory().total, total, delta=MEMORY_TOLERANCE)
+
# --- others
def test_boot_time(self):