Skip to content

Commit

Permalink
#887: add test for warnings on missing values
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Sep 20, 2016
1 parent 029b200 commit 0f53f7f
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions psutil/tests/test_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,36 @@ def test_available(self):
free_value, psutil_value, delta=MEMORY_TOLERANCE,
msg='%s %s \n%s' % (free_value, psutil_value, out))

def test_warnings_mocked(self):
def open_mock(*args, **kwargs):
return io.BytesIO(textwrap.dedent("""\
Active(anon): 6145416 kB
Active(file): 2950064 kB
Buffers: 287952 kB
Inactive(anon): 574764 kB
Inactive(file): 1567648 kB
MemAvailable: 6574984 kB
MemFree: 2057400 kB
MemTotal: 16325648 kB
Shmem: 577588 kB
SReclaimable: 346648 kB
""").encode())

with mock.patch('psutil._pslinux.open', create=True,
side_effect=open_mock) 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)


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

0 comments on commit 0f53f7f

Please sign in to comment.