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-11-01 17:01:21 -07:00

51 lines
1.3 KiB
Python

import os
import json
import unittest
from typing import Dict
from jc.parsers.foo_s import parse
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 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_foo_s_nodata(self):
"""
Test 'foo' with no data
"""
self.assertEqual(list(parse([], quiet=True)), [])
def test_foo_s_centos_7_7(self):
"""
Test 'foo' on Centos 7.7
"""
self.assertEqual(
list(parse(self.f_in['centos_7_7_foo'].splitlines(), quiet=True)),
self.f_json['centos_7_7_foo']
)
if __name__ == '__main__':
unittest.main()