mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-08-10 22:41:51 +02:00
new test templates
This commit is contained in:
@@ -1,20 +1,30 @@
|
|||||||
import os
|
import os
|
||||||
import unittest
|
import unittest
|
||||||
import json
|
import json
|
||||||
|
from typing import Dict
|
||||||
import jc.parsers.foo
|
import jc.parsers.foo
|
||||||
|
|
||||||
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
|
|
||||||
class MyTests(unittest.TestCase):
|
class MyTests(unittest.TestCase):
|
||||||
|
f_in: Dict = {}
|
||||||
|
f_json: Dict = {}
|
||||||
|
|
||||||
# input
|
@classmethod
|
||||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/foo.out'), 'r', encoding='utf-8') as f:
|
def setUpClass(cls):
|
||||||
centos_7_7_foo = f.read()
|
fixtures = {
|
||||||
|
'centos_7_7_foo': (
|
||||||
|
'fixtures/centos-7.7/foo.out',
|
||||||
|
'fixtures/centos-7.7/foo.json')
|
||||||
|
}
|
||||||
|
|
||||||
# output
|
for file, filepaths in fixtures.items():
|
||||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/foo.json'), 'r', encoding='utf-8') as f:
|
with open(os.path.join(THIS_DIR, filepaths[0]), 'r', encoding='utf-8') as f:
|
||||||
centos_7_7_foo_json = json.loads(f.read())
|
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_nodata(self):
|
def test_foo_nodata(self):
|
||||||
@@ -27,7 +37,8 @@ class MyTests(unittest.TestCase):
|
|||||||
"""
|
"""
|
||||||
Test 'foo' on Centos 7.7
|
Test 'foo' on Centos 7.7
|
||||||
"""
|
"""
|
||||||
self.assertEqual(jc.parsers.foo.parse(self.centos_7_7_foo, quiet=True), self.centos_7_7_foo_json)
|
self.assertEqual(jc.parsers.foo.parse(self.f_in['centos_7_7_foo'], quiet=True),
|
||||||
|
self.f_json['centos_7_7_foo'])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import unittest
|
import unittest
|
||||||
|
from typing import Dict
|
||||||
import jc.parsers.foo_s
|
import jc.parsers.foo_s
|
||||||
|
|
||||||
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
@@ -10,14 +11,24 @@ THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
|||||||
|
|
||||||
|
|
||||||
class MyTests(unittest.TestCase):
|
class MyTests(unittest.TestCase):
|
||||||
|
f_in: Dict = {}
|
||||||
|
f_json: Dict = {}
|
||||||
|
|
||||||
# input
|
@classmethod
|
||||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/foo.out'), 'r', encoding='utf-8') as f:
|
def setUpClass(cls):
|
||||||
centos_7_7_foo = f.read()
|
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())
|
||||||
|
|
||||||
# output
|
|
||||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/foo-streaming.json'), 'r', encoding='utf-8') as f:
|
|
||||||
centos_7_7_foo_streaming_json = json.loads(f.read())
|
|
||||||
|
|
||||||
def test_foo_s_nodata(self):
|
def test_foo_s_nodata(self):
|
||||||
"""
|
"""
|
||||||
@@ -29,7 +40,8 @@ class MyTests(unittest.TestCase):
|
|||||||
"""
|
"""
|
||||||
Test 'foo' on Centos 7.7
|
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)
|
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__':
|
if __name__ == '__main__':
|
||||||
|
Reference in New Issue
Block a user