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.
This commit is contained in:
parent
d1de6c5fa3
commit
12c74674f2
@ -18,8 +18,9 @@ class Openfiles(IntervalModule):
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|
||||||
cur_filenr = open(self.filenr_path, 'r').readlines()
|
cur_filenr = open(self.filenr_path, 'r')
|
||||||
openfiles, unused, maxfiles = cur_filenr[0].split()
|
openfiles, unused, maxfiles = cur_filenr.readlines()[0].split()
|
||||||
|
cur_filenr.close()
|
||||||
|
|
||||||
cdict = {'openfiles': openfiles,
|
cdict = {'openfiles': openfiles,
|
||||||
'maxfiles': maxfiles}
|
'maxfiles': maxfiles}
|
||||||
|
29
tests/test_openfiles.py
Normal file
29
tests/test_openfiles.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
"""
|
||||||
|
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()
|
Loading…
Reference in New Issue
Block a user