2022-12-12 15:33:40 +01:00
|
|
|
import json
|
2022-12-12 15:10:59 +01:00
|
|
|
import os
|
|
|
|
import unittest
|
|
|
|
from jc.exceptions import ParseError
|
|
|
|
import jc.parsers.cbt
|
|
|
|
|
|
|
|
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
|
|
|
|
|
|
|
class MyTests(unittest.TestCase):
|
2022-12-12 15:33:40 +01:00
|
|
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/cbt-single.out'), 'r', encoding='utf-8') as f:
|
|
|
|
single = f.read()
|
|
|
|
|
|
|
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/cbt-multiple-columns.out'), 'r', encoding='utf-8') as f:
|
|
|
|
multiple_columns = f.read()
|
|
|
|
|
|
|
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/cbt-multiple-rows.out'), 'r', encoding='utf-8') as f:
|
|
|
|
multiple_rows = f.read()
|
|
|
|
|
|
|
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/cbt-single.json'), 'r', encoding='utf-8') as f:
|
|
|
|
single_json = json.loads(f.read())
|
|
|
|
|
|
|
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/cbt-multiple-columns.json'), 'r', encoding='utf-8') as f:
|
|
|
|
multiple_columns_json = json.loads(f.read())
|
|
|
|
|
|
|
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/cbt-multiple-rows.json'), 'r', encoding='utf-8') as f:
|
|
|
|
multiple_rows_json = json.loads(f.read())
|
|
|
|
|
|
|
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/cbt-multiple-rows-raw.json'), 'r', encoding='utf-8') as f:
|
|
|
|
multiple_rows_raw_json = json.loads(f.read())
|
2022-12-12 15:10:59 +01:00
|
|
|
|
|
|
|
def test_cbt_nodata(self):
|
|
|
|
"""
|
|
|
|
Test 'cbt' with no data
|
|
|
|
"""
|
|
|
|
self.assertEqual(jc.parsers.cbt.parse('', quiet=True), [])
|
|
|
|
|
|
|
|
def test_cbt_single_row(self):
|
|
|
|
"""
|
|
|
|
Test 'cbt' with a single row
|
|
|
|
"""
|
2022-12-12 15:33:40 +01:00
|
|
|
self.assertEqual(jc.parsers.cbt.parse(self.single, quiet=True), self.single_json)
|
2022-12-12 15:10:59 +01:00
|
|
|
|
|
|
|
def test_cbt_multiple_column_families(self):
|
|
|
|
"""
|
2022-12-12 15:33:40 +01:00
|
|
|
Test 'cbt' with multiple columns from multiple column families
|
2022-12-12 15:10:59 +01:00
|
|
|
"""
|
2022-12-12 15:33:40 +01:00
|
|
|
self.assertEqual(jc.parsers.cbt.parse(self.multiple_columns, quiet=True), self.multiple_columns_json)
|
2022-12-12 15:10:59 +01:00
|
|
|
|
|
|
|
def test_cbt_multiple_rows(self):
|
|
|
|
"""
|
|
|
|
Test 'cbt' with multiple rows
|
|
|
|
"""
|
2022-12-12 15:33:40 +01:00
|
|
|
self.assertEqual(jc.parsers.cbt.parse(self.multiple_rows, quiet=True), self.multiple_rows_json)
|
2022-12-12 15:10:59 +01:00
|
|
|
|
|
|
|
def test_cbt_multiple_rows_raw(self):
|
|
|
|
"""
|
|
|
|
Test 'cbt' with multiple rows raw
|
|
|
|
"""
|
2022-12-12 15:33:40 +01:00
|
|
|
self.assertEqual(jc.parsers.cbt.parse(self.multiple_rows, quiet=True, raw=True), self.multiple_rows_raw_json)
|
2022-12-12 15:10:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|