Skip to content
This repository was archived by the owner on Mar 19, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions adr/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def __init__(self, table_cls=SingleTable):
self.table_cls = table_cls

def __call__(self, data):
print(data)
if isinstance(data, bytes):
data = json.loads(data)

Expand Down
Empty file.
1 change: 1 addition & 0 deletions test/formatter_tests/jsonformatter_expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"expected_json": ["[\n [\n \"Heading A\",\n \"Heading B\"\n ],\n [\n 1,\n 2\n ],\n [\n 3,\n 4\n ],\n [\n 5,\n 6\n ]\n]", "{\n \"names\": [\n \"Heading A\",\n \"Heading B\",\n \"Heading C\"\n ],\n \"Heading A\": [\n \"x\",\n \"y\"\n ],\n \"Heading B\": [\n 11,\n 20.5\n ],\n \"Heading C\": [\n 12,\n 30.5\n ]\n}"]}
1 change: 1 addition & 0 deletions test/formatter_tests/markdownformatter_expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"expected_markdown": ["\n| Heading A | Heading B |\n|-----------|-----------|\n| 1 | 2 |\n| 3 | 4 |\n| 5 | 6 |\n", "\n| Heading A | Heading B | Heading C |\n|-----------|-----------|-----------|\n| x | 11 | 12 |\n| y | 20.5 | 30.5 |"]}
1 change: 1 addition & 0 deletions test/formatter_tests/tableformatter_expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"expected_table": ["\n┌───────────┬───────────┐\n│ Heading A │ Heading B │\n├───────────┼───────────┤\n│ 1 │ 2 │\n│ 3 │ 4 │\n│ 5 │ 6 │\n└───────────┴───────────┘", "\n┌───────────┬───────────┬───────────┐\n│ Heading A │ Heading B │ Heading C │\n├───────────┼───────────┼───────────┤\n│ x │ 11 │ 12 │\n│ y │ 20.5 │ 30.5 │\n└───────────┴───────────┴───────────┘"]}
43 changes: 43 additions & 0 deletions test/test_formatter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import os
import io
import json
import pytest
import formatter_tests
from adr.formatter import all_formatters


test_data=([['Heading A', 'Heading B'],[1, 2],[3, 4],[5,6]],{'names': ['Heading A', 'Heading B', 'Heading C'],
'Heading A': ['x', 'y'],
'Heading B': [11, 20.5],
'Heading C': [12, 30.5]
})

def get_data(path):
with io.open(path,'r',encoding="utf-8") as f:
data = json.load(f)
return data


test_dir=os.path.dirname(formatter_tests.__file__)

expected_table=get_data(os.path.join(test_dir,'tableformatter_expected.json'))["expected_table"]
expected_json= get_data(os.path.join(test_dir,'jsonformatter_expected.json'))["expected_json"]
expected_markdown=get_data(os.path.join(test_dir,'markdownformatter_expected.json'))["expected_markdown"]



@pytest.mark.parametrize("test_data,expected_json",list(zip(test_data,expected_json)),ids=["jsonformat_case1", "jsonformat_case2"])
def test_jsonformatter(test_data,expected_json):
"""check MarkdownFormatter method """
assert all_formatters['json'](test_data)==expected_json.strip()


@pytest.mark.parametrize("test_data,expected_table",list(zip(test_data,expected_table)),ids=["tableformat_case1", "tableformat_case2"])
def test_tableformatter(test_data,expected_table):
"""check MarkdownFormatter method """
assert all_formatters['table'](test_data)==expected_table.strip()

@pytest.mark.parametrize("test_data,expected_markdown",list(zip(test_data,expected_markdown)),ids=["markdownformat1", "markdownformat2"])
def test_markdownformatter(test_data,expected_markdown):
"""check MarkdownFormatter method """
assert all_formatters['markdown'](test_data)==expected_markdown.strip()