1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-07-13 01:20:24 +02:00

add streaming test template

This commit is contained in:
Kelly Brazil
2022-03-10 09:04:12 -08:00
parent 4f0616190b
commit 696338c1a3

38
tests/_test_foo_s.py Normal file
View File

@ -0,0 +1,38 @@
import os
import json
import unittest
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):
def setUp(self):
pass
# input
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/foo.out'), 'r', encoding='utf-8') as f:
self.centos_7_7_foo = f.read()
# output
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/foo-streaming.json'), 'r', encoding='utf-8') as f:
self.centos_7_7_foo_streaming_json = 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.centos_7_7_foo.splitlines(), quiet=True)), self.centos_7_7_foo_streaming_json)
if __name__ == '__main__':
unittest.main()