diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2016-09-18 16:01:37 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2016-09-18 16:01:37 +0200 |
commit | 4ef75441af929750309fecbe6a0e49a2a6f03b05 (patch) | |
tree | be62cf9d90221dc1b2e8fa83c43747932956a3c4 | |
parent | ea08d4cf941c23e1c16bba1e84e7f6e80207c5b5 (diff) | |
download | psutil-4ef75441af929750309fecbe6a0e49a2a6f03b05.tar.gz |
#887: add test to matche 'avail' column of 'free'
-rw-r--r-- | psutil/tests/test_linux.py | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/psutil/tests/test_linux.py b/psutil/tests/test_linux.py index f9a1478f..87765107 100644 --- a/psutil/tests/test_linux.py +++ b/psutil/tests/test_linux.py @@ -202,22 +202,18 @@ class TestSystemVirtualMemory(unittest.TestCase): free_value, psutil_value, delta=MEMORY_TOLERANCE, msg='%s %s \n%s' % (free_value, psutil_value, free.output)) - # --- mocked tests - - def test_warnings_mocked(self): - with mock.patch('psutil._pslinux.open', create=True) as m: - with warnings.catch_warnings(record=True) as ws: - warnings.simplefilter("always") - ret = psutil._pslinux.virtual_memory() - assert m.called - self.assertEqual(len(ws), 1) - w = ws[0] - self.assertTrue(w.filename.endswith('psutil/_pslinux.py')) - self.assertIn( - "memory stats couldn't be determined", str(w.message)) - self.assertEqual(ret.cached, 0) - self.assertEqual(ret.active, 0) - self.assertEqual(ret.inactive, 0) + def test_available(self): + # "free" output format has changed at some point: + # https://github.com/giampaolo/psutil/issues/538#issuecomment-147192098 + out = sh("free -b") + lines = out.split('\n') + if 'available' in lines[0]: + raise unittest.SkipTest("free does not support 'available' column") + free_value = int(lines[1].split()[-1]) + psutil_value = psutil.virtual_memory().available + self.assertAlmostEqual( + free_value, psutil_value, delta=MEMORY_TOLERANCE, + msg='%s %s \n%s' % (free_value, psutil_value, out)) # ===================================================================== |