fix: resolve CI linting and type checking errors
Some checks failed
CI / test (push) Failing after 16s
Some checks failed
CI / test (push) Failing after 16s
This commit is contained in:
108
tests/test_formatters.py
Normal file
108
tests/test_formatters.py
Normal file
@@ -0,0 +1,108 @@
|
||||
"""Tests for output formatting module."""
|
||||
|
||||
from cmdparse.formatters import format_csv, format_data, format_json, format_raw, format_yaml
|
||||
|
||||
|
||||
class TestFormatJson:
|
||||
def test_format_simple_list(self):
|
||||
data = [{'name': 'John', 'age': 30}]
|
||||
result = format_json(data)
|
||||
assert 'John' in result
|
||||
assert '30' in result
|
||||
|
||||
def test_format_empty_list(self):
|
||||
result = format_json([])
|
||||
assert result == '[]'
|
||||
|
||||
def test_pretty_format(self):
|
||||
data = [{'name': 'John'}]
|
||||
result = format_json(data, pretty=True)
|
||||
assert '\n' in result
|
||||
|
||||
def test_compact_format(self):
|
||||
data = [{'name': 'John'}]
|
||||
result = format_json(data, pretty=False)
|
||||
assert '\n' not in result
|
||||
|
||||
|
||||
class TestFormatYaml:
|
||||
def test_format_simple_list(self):
|
||||
data = [{'name': 'John', 'age': 30}]
|
||||
result = format_yaml(data)
|
||||
assert 'John' in result
|
||||
assert 'age' in result
|
||||
|
||||
def test_format_empty_list(self):
|
||||
result = format_yaml([])
|
||||
assert result == '[]\n'
|
||||
|
||||
def test_format_nested_structure(self):
|
||||
data = [{'user': {'name': 'John', 'tags': ['a', 'b']}}]
|
||||
result = format_yaml(data)
|
||||
assert 'John' in result
|
||||
|
||||
|
||||
class TestFormatCsv:
|
||||
def test_format_simple_list(self):
|
||||
data = [{'name': 'John', 'age': 30}]
|
||||
result = format_csv(data)
|
||||
assert 'name' in result
|
||||
assert 'John' in result
|
||||
assert 'age' in result
|
||||
|
||||
def test_format_empty_list(self):
|
||||
result = format_csv([])
|
||||
assert result == ''
|
||||
|
||||
def test_format_multiple_rows(self):
|
||||
data = [
|
||||
{'name': 'John', 'age': 30},
|
||||
{'name': 'Jane', 'age': 25}
|
||||
]
|
||||
result = format_csv(data)
|
||||
assert 'John' in result
|
||||
assert 'Jane' in result
|
||||
|
||||
|
||||
class TestFormatRaw:
|
||||
def test_format_simple_list(self):
|
||||
data = [{'name': 'John', 'age': 30}]
|
||||
result = format_raw(data)
|
||||
assert 'name: John' in result
|
||||
assert 'age: 30' in result
|
||||
|
||||
def test_format_empty_list(self):
|
||||
result = format_raw([])
|
||||
assert result == ''
|
||||
|
||||
|
||||
class TestFormatData:
|
||||
def test_json_format(self):
|
||||
data = [{'name': 'John'}]
|
||||
result = format_data(data, 'json')
|
||||
assert 'John' in result
|
||||
|
||||
def test_yaml_format(self):
|
||||
data = [{'name': 'John'}]
|
||||
result = format_data(data, 'yaml')
|
||||
assert 'John' in result
|
||||
|
||||
def test_csv_format(self):
|
||||
data = [{'name': 'John'}]
|
||||
result = format_data(data, 'csv')
|
||||
assert 'name' in result
|
||||
|
||||
def test_raw_format(self):
|
||||
data = [{'name': 'John'}]
|
||||
result = format_data(data, 'raw')
|
||||
assert 'John' in result
|
||||
|
||||
def test_default_to_json(self):
|
||||
data = [{'name': 'John'}]
|
||||
result = format_data(data, '')
|
||||
assert 'John' in result
|
||||
|
||||
def test_unknown_format_defaults_to_json(self):
|
||||
data = [{'name': 'John'}]
|
||||
result = format_data(data, 'unknown')
|
||||
assert 'John' in result
|
||||
Reference in New Issue
Block a user