1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00
Files
jc/tests/templates/_test_foo_s.py
2022-09-23 16:19:35 -07:00

49 lines
1.3 KiB
Python

import os
import json
import unittest
from typing import Dict
import jc.parsers.foo_s
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
# To create streaming output use:
# $ cat foo.out | jc --foo-s | jello -c > foo-streaming.json
class MyTests(unittest.TestCase):
f_in: Dict = {}
f_json: Dict = {}
@classmethod
def setUpClass(cls):
fixtures = {
'centos_7_7_foo': (
'fixtures/centos-7.7/foo.out',
'fixtures/centos-7.7/foo-streaming.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_foo_s_nodata(self):
"""
Test 'foo' with no data
"""
self.assertEqual(list(jc.parsers.foo_s.parse([], quiet=True)), [])
def test_foo_s_centos_7_7(self):
"""
Test 'foo' on Centos 7.7
"""
self.assertEqual(list(jc.parsers.foo_s.parse(self.f_in['centos_7_7_foo'].splitlines(), quiet=True)),
self.f_json['centos_7_7_foo'])
if __name__ == '__main__':
unittest.main()