mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-17 00:07:37 +02:00
fix rstrip and add tests
This commit is contained in:
@ -95,7 +95,7 @@ def _rstrip(string: str) -> str:
|
|||||||
rstrip_list = [x for x in string.splitlines() if not len(x.strip()) == 0]
|
rstrip_list = [x for x in string.splitlines() if not len(x.strip()) == 0]
|
||||||
end_points = (len(x.rstrip()) for x in rstrip_list)
|
end_points = (len(x.rstrip()) for x in rstrip_list)
|
||||||
max_point = max(end_points)
|
max_point = max(end_points)
|
||||||
new_rstrip_list = (x[:max_point] for x in rstrip_list)
|
new_rstrip_list = ((x + ' ' * max_point)[:max_point] for x in rstrip_list)
|
||||||
return '\n'.join(new_rstrip_list)
|
return '\n'.join(new_rstrip_list)
|
||||||
|
|
||||||
|
|
||||||
@ -341,6 +341,7 @@ def parse(
|
|||||||
if jc.utils.has_data(data):
|
if jc.utils.has_data(data):
|
||||||
data = _remove_ansi(data)
|
data = _remove_ansi(data)
|
||||||
data = _strip(data)
|
data = _strip(data)
|
||||||
|
print(data.replace(' ', '~'))
|
||||||
table_type = _table_sniff(data)
|
table_type = _table_sniff(data)
|
||||||
|
|
||||||
if table_type == 'pretty':
|
if table_type == 'pretty':
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import unittest
|
import unittest
|
||||||
|
from jc.exceptions import ParseError
|
||||||
import jc.parsers.asciitable_m
|
import jc.parsers.asciitable_m
|
||||||
|
|
||||||
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
@ -217,6 +218,32 @@ class MyTests(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(jc.parsers.asciitable_m.parse(input, quiet=True), expected)
|
self.assertEqual(jc.parsers.asciitable_m.parse(input, quiet=True), expected)
|
||||||
|
|
||||||
|
def test_asciitable_m_markdown(self):
|
||||||
|
"""
|
||||||
|
Test 'asciitable_m' with a markdown table. Should raise a ParseError
|
||||||
|
"""
|
||||||
|
input = '''
|
||||||
|
| type | total | used | free | shared | buff cache | available |
|
||||||
|
|--------|---------|--------|---------|----------|--------------|-------------|
|
||||||
|
| Mem | 3861332 | 222820 | 3364176 | 11832 | 274336 | 3389588 |
|
||||||
|
| Swap | 2097148 | 0 | 2097148 | | | |
|
||||||
|
'''
|
||||||
|
|
||||||
|
self.assertRaises(ParseError, jc.parsers.asciitable_m.parse, input, quiet=True)
|
||||||
|
|
||||||
|
def test_asciitable_m_simple(self):
|
||||||
|
"""
|
||||||
|
Test 'asciitable_m' with a simple table. Should raise a ParseError
|
||||||
|
"""
|
||||||
|
input = '''
|
||||||
|
type total used free shared buff cache available
|
||||||
|
------ ------- ------ ------- -------- ------------ -----------
|
||||||
|
Mem 3861332 222820 3364176 11832 274336 3389588
|
||||||
|
Swap 2097148 0 2097148
|
||||||
|
'''
|
||||||
|
|
||||||
|
self.assertRaises(ParseError, jc.parsers.asciitable_m.parse, input, quiet=True)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Reference in New Issue
Block a user