mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-08-10 22:41:51 +02:00
add proc_pid_stat tests
This commit is contained in:
1
tests/fixtures/linux-proc/pid_stat.json
vendored
Normal file
1
tests/fixtures/linux-proc/pid_stat.json
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"pid":1,"comm":"systemd","state":"S","ppid":0,"pgrp":1,"session":1,"tty_nr":0,"tpg_id":-1,"flags":4194560,"minflt":23478,"cminflt":350218,"majflt":99,"cmajflt":472,"utime":107,"stime":461,"cutime":2672,"cstime":4402,"priority":20,"nice":0,"num_threads":1,"itrealvalue":0,"starttime":128,"vsize":174063616,"rss":3313,"rsslim":18446744073709551615,"startcode":94188219072512,"endcode":94188219899461,"startstack":140725059845296,"kstkeep":0,"kstkeip":0,"signal":0,"blocked":671173123,"sigignore":4096,"sigcatch":1260,"wchan":1,"nswap":0,"cnswap":0,"exit_signal":17,"processor":0,"rt_priority":0,"policy":0,"delayacct_blkio_ticks":18,"guest_time":0,"cguest_time":0,"start_data":94188220274448,"end_data":94188220555504,"start_brk":94188243599360,"arg_start":140725059845923,"arg_end":140725059845934,"env_start":140725059845934,"env_end":140725059846125,"exit_code":0,"state_pretty":"Sleeping in an interruptible wait"}
|
44
tests/test_proc_pid_stat.py
Normal file
44
tests/test_proc_pid_stat.py
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
import os
|
||||||
|
import unittest
|
||||||
|
import json
|
||||||
|
from typing import Dict
|
||||||
|
import jc.parsers.proc_pid_stat
|
||||||
|
|
||||||
|
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_pid_stat': (
|
||||||
|
'fixtures/linux-proc/pid_stat',
|
||||||
|
'fixtures/linux-proc/pid_stat.json')
|
||||||
|
}
|
||||||
|
|
||||||
|
for file, filepaths in fixtures.items():
|
||||||
|
with open(os.path.join(THIS_DIR, filepaths[0]), 'r', encoding='utf-8') as a, \
|
||||||
|
open(os.path.join(THIS_DIR, filepaths[1]), 'r', encoding='utf-8') as b:
|
||||||
|
cls.f_in[file] = a.read()
|
||||||
|
cls.f_json[file] = json.loads(b.read())
|
||||||
|
|
||||||
|
|
||||||
|
def test_proc_pid_stat_nodata(self):
|
||||||
|
"""
|
||||||
|
Test 'proc_pid_stat' with no data
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.proc_pid_stat.parse('', quiet=True), {})
|
||||||
|
|
||||||
|
def test_proc_pid_stat(self):
|
||||||
|
"""
|
||||||
|
Test '/proc/<pid>/stat'
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.proc_pid_stat.parse(self.f_in['proc_pid_stat'], quiet=True),
|
||||||
|
self.f_json['proc_pid_stat'])
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
Reference in New Issue
Block a user