i3pystatus/tests/test_openfiles.py
David Wahlstrom 12c74674f2 openfiles: add tests and close files
Added a functional test and included a close() call on files that are
opened when the module/test run.
2016-05-06 09:12:33 -07:00

30 lines
924 B
Python

"""
Basic test for the openfiles module
"""
import unittest
from tempfile import TemporaryDirectory
from shutil import copyfile
from i3pystatus import openfiles
class OpenfilesTest(unittest.TestCase):
def test_openfiles(self):
"""
Test output of open files
"""
# copy file-nr so we have a known/unchanged source file
with TemporaryDirectory() as tmpdirname:
copyfile('/proc/sys/fs/file-nr', tmpdirname + '/file-nr')
cur_filenr = open(tmpdirname + '/file-nr', 'r')
openfilehandles, ununsed, maxfiles = cur_filenr.readlines()[0].split()
cur_filenr.close()
i3openfiles = openfiles.Openfiles(filenr_path=tmpdirname + '/file-nr')
i3openfiles.run()
self.assertTrue(i3openfiles.output['full_text'] == 'open/max: %s/%s' % (openfilehandles, maxfiles))
if __name__ == '__main__':
unittest.main()