diff --git a/tests/fixtures/linux-proc/buddyinfo b/tests/fixtures/linux-proc/buddyinfo new file mode 100644 index 00000000..8ec94511 --- /dev/null +++ b/tests/fixtures/linux-proc/buddyinfo @@ -0,0 +1,3 @@ +Node 0, zone DMA 0 0 0 1 1 1 1 1 0 1 3 +Node 0, zone DMA32 78 114 82 52 38 25 13 9 3 4 629 +Node 0, zone Normal 0 22 8 10 1 1 2 11 13 0 0 diff --git a/tests/fixtures/linux-proc/buddyinfo.json b/tests/fixtures/linux-proc/buddyinfo.json new file mode 100644 index 00000000..b10535e1 --- /dev/null +++ b/tests/fixtures/linux-proc/buddyinfo.json @@ -0,0 +1 @@ +[{"node":0,"zone":"DMA","free_chunks":[0,0,0,1,1,1,1,1,0,1,3]},{"node":0,"zone":"DMA32","free_chunks":[78,114,82,52,38,25,13,9,3,4,629]},{"node":0,"zone":"Normal","free_chunks":[0,22,8,10,1,1,2,11,13,0,0]}] diff --git a/tests/test_proc_buddyinfo.py b/tests/test_proc_buddyinfo.py new file mode 100644 index 00000000..6418a0bd --- /dev/null +++ b/tests/test_proc_buddyinfo.py @@ -0,0 +1,45 @@ +import os +import unittest +import json +from typing import Dict +import jc.parsers.proc_buddyinfo + +THIS_DIR = os.path.dirname(os.path.abspath(__file__)) + + +class MyTests(unittest.TestCase): + f_in: Dict = {} + f_json: Dict = {} + + @classmethod + def setUpClass(cls): + fixtures = { + 'proc_buddyinfo': ( + 'fixtures/linux-proc/buddyinfo', + 'fixtures/linux-proc/buddyinfo.json') + } + + for file, filepaths in fixtures.items(): + with open(os.path.join(THIS_DIR, filepaths[0]), 'r', encoding='utf-8') as f: + cls.f_in[file] = f.read() + + with open(os.path.join(THIS_DIR, filepaths[1]), 'r', encoding='utf-8') as f: + cls.f_json[file] = json.loads(f.read()) + + + def test_proc_buddyinfo_nodata(self): + """ + Test 'proc_buddyinfo' with no data + """ + self.assertEqual(jc.parsers.proc_buddyinfo.parse('', quiet=True), []) + + def test_proc_buddyinfo(self): + """ + Test '/proc/buddyinfo' + """ + self.assertEqual(jc.parsers.proc_buddyinfo.parse(self.f_in['proc_buddyinfo'], quiet=True), + self.f_json['proc_buddyinfo']) + + +if __name__ == '__main__': + unittest.main()