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

Move test stuff to fixtures

This commit is contained in:
Andreas Weiden
2022-12-12 15:33:40 +01:00
parent 7f4a951065
commit 532c37140c
8 changed files with 50 additions and 107 deletions

View File

@ -0,0 +1 @@
[{"key":"foo","cells":{"bat":{"bar":"baz"},"foo":{"bar1":"baz1","bar2":"baz2"}}}]

View File

@ -0,0 +1,8 @@
----------------------------------------
foo
foo:bar1 @ 1970/01/01-01:00:00.000000
"baz1"
foo:bar2 @ 1970/01/01-01:00:00.000000
"baz2"
bat:bar @ 1970/01/01-01:00:00.000000
"baz"

View File

@ -0,0 +1 @@
[{"key":"foo","cells":[{"column_family":"foo","column":"bar","timestamp":"1970-01-01T01:00:00","value":"baz1"}]},{"key":"bar","cells":[{"column_family":"foo","column":"bar","timestamp":"1970-01-01T01:00:00","value":"baz2"}]}]

View File

@ -0,0 +1 @@
[{"key":"foo","cells":{"foo":{"bar":"baz1"}}},{"key":"bar","cells":{"foo":{"bar":"baz2"}}}]

View File

@ -0,0 +1,8 @@
----------------------------------------
foo
foo:bar @ 1970/01/01-01:00:00.000000
"baz1"
----------------------------------------
bar
foo:bar @ 1970/01/01-01:00:00.000000
"baz2"

View File

@ -0,0 +1 @@
[{"key":"foo","cells":{"foo":{"bar":"baz"}}}]

4
tests/fixtures/generic/cbt-single.out vendored Normal file
View File

@ -0,0 +1,4 @@
----------------------------------------
foo
foo:bar @ 1970/01/01-01:00:00.000000
"baz"

View File

@ -1,3 +1,4 @@
import json
import os import os
import unittest import unittest
from jc.exceptions import ParseError from jc.exceptions import ParseError
@ -7,6 +8,26 @@ THIS_DIR = os.path.dirname(os.path.abspath(__file__))
class MyTests(unittest.TestCase): class MyTests(unittest.TestCase):
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())
def test_cbt_nodata(self): def test_cbt_nodata(self):
""" """
@ -18,127 +39,25 @@ class MyTests(unittest.TestCase):
""" """
Test 'cbt' with a single row Test 'cbt' with a single row
""" """
input = ''' self.assertEqual(jc.parsers.cbt.parse(self.single, quiet=True), self.single_json)
----------------------------------------
foo
foo:bar @ 1970/01/01-01:00:00.000000
"baz"
'''
expected = [
{
"key": "foo",
"cells": {
"foo": {
"bar": "baz"
}
}
}
]
self.assertEqual(jc.parsers.cbt.parse(input, quiet=True), expected)
def test_cbt_multiple_column_families(self): def test_cbt_multiple_column_families(self):
""" """
Test 'cbt' with multiple column families Test 'cbt' with multiple columns from multiple column families
""" """
input = ''' self.assertEqual(jc.parsers.cbt.parse(self.multiple_columns, quiet=True), self.multiple_columns_json)
----------------------------------------
foo
foo:bar1 @ 1970/01/01-01:00:00.000000
"baz1"
foo:bar2 @ 1970/01/01-01:00:00.000000
"baz2"
bat:bar @ 1970/01/01-01:00:00.000000
"baz"
'''
expected = [
{
"key": "foo",
"cells": {
"foo": {
"bar1": "baz1",
"bar2": "baz2",
},
"bat": {
"bar": "baz"
}
}
}
]
self.assertEqual(jc.parsers.cbt.parse(input, quiet=True), expected)
def test_cbt_multiple_rows(self): def test_cbt_multiple_rows(self):
""" """
Test 'cbt' with multiple rows Test 'cbt' with multiple rows
""" """
input = ''' self.assertEqual(jc.parsers.cbt.parse(self.multiple_rows, quiet=True), self.multiple_rows_json)
----------------------------------------
foo
foo:bar @ 1970/01/01-01:00:00.000000
"baz1"
----------------------------------------
bar
foo:bar @ 1970/01/01-01:00:00.000000
"baz2"
'''
expected = [
{
"key": "foo",
"cells": {
"foo": {
"bar": "baz1",
}
}
},
{
"key": "bar",
"cells": {
"foo": {
"bar": "baz2",
}
}
}
]
self.assertEqual(jc.parsers.cbt.parse(input, quiet=True), expected)
def test_cbt_multiple_rows_raw(self): def test_cbt_multiple_rows_raw(self):
""" """
Test 'cbt' with multiple rows raw Test 'cbt' with multiple rows raw
""" """
input = ''' self.assertEqual(jc.parsers.cbt.parse(self.multiple_rows, quiet=True, raw=True), self.multiple_rows_raw_json)
----------------------------------------
foo
foo:bar @ 1970/01/01-01:00:00.000000
"baz1"
----------------------------------------
bar
foo:bar @ 1970/01/01-01:00:00.000000
"baz2"
'''
expected = [
{
"key": "foo",
"cells": [
{
"column_family": "foo",
"column": "bar",
"timestamp": "1970-01-01T01:00:00",
"value": "baz1",
}
]
},
{
"key": "bar",
"cells": [
{
"column_family": "foo",
"column": "bar",
"timestamp": "1970-01-01T01:00:00",
"value": "baz2",
}
]
}
]
self.assertEqual(jc.parsers.cbt.parse(input, quiet=True, raw=True), expected)
if __name__ == '__main__': if __name__ == '__main__':