1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00

proc-buddyinfo tests

This commit is contained in:
Kelly Brazil
2022-09-23 16:19:52 -07:00
parent fa1699298b
commit ae9c1746f1
3 changed files with 49 additions and 0 deletions

3
tests/fixtures/linux-proc/buddyinfo vendored Normal file
View File

@ -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

View File

@ -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]}]

View File

@ -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()