mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-17 00:07:37 +02:00
add slurp test. fix cli_json_out_pretty test
This commit is contained in:
@ -8,6 +8,7 @@ try:
|
||||
except ModuleNotFoundError:
|
||||
PYGMENTS_INSTALLED=False
|
||||
from jc.cli import JcCli
|
||||
import jc.parsers.url as url_parser
|
||||
|
||||
|
||||
class MyTests(unittest.TestCase):
|
||||
@ -203,29 +204,29 @@ class MyTests(unittest.TestCase):
|
||||
cli.data_out = test_dict
|
||||
self.assertEqual(cli.json_out(), expected_json)
|
||||
|
||||
def test_cli_json_out_pretty(self):
|
||||
test_input = [
|
||||
{"key1": "value1", "key2": 2, "key3": None, "key4": 3.14, "key5": True},
|
||||
{"key1": [{"subkey1": "subvalue1"}, {"subkey2": [1, 2, 3]}], "key2": True}
|
||||
def test_cli_json_out_pretty(self):
|
||||
test_input = [
|
||||
{"key1": "value1", "key2": 2, "key3": None, "key4": 3.14, "key5": True},
|
||||
{"key1": [{"subkey1": "subvalue1"}, {"subkey2": [1, 2, 3]}], "key2": True}
|
||||
]
|
||||
|
||||
if pygments.__version__.startswith('2.3.'):
|
||||
expected_output = [
|
||||
'{\n \x1b[34;01m"key1"\x1b[39;00m: \x1b[32m"value1"\x1b[39m,\n \x1b[34;01m"key2"\x1b[39;00m: \x1b[35m2\x1b[39m,\n \x1b[34;01m"key3"\x1b[39;00m: \x1b[30;01mnull\x1b[39;00m,\n \x1b[34;01m"key4"\x1b[39;00m: \x1b[35m3.14\x1b[39m,\n \x1b[34;01m"key5"\x1b[39;00m: \x1b[30;01mtrue\x1b[39;00m\n}',
|
||||
'{\n \x1b[34;01m"key1"\x1b[39;00m: [\n {\n \x1b[34;01m"subkey1"\x1b[39;00m: \x1b[32m"subvalue1"\x1b[39m\n },\n {\n \x1b[34;01m"subkey2"\x1b[39;00m: [\n \x1b[35m1\x1b[39m,\n \x1b[35m2\x1b[39m,\n \x1b[35m3\x1b[39m\n ]\n }\n ],\n \x1b[34;01m"key2"\x1b[39;00m: \x1b[30;01mtrue\x1b[39;00m\n}'
|
||||
]
|
||||
else:
|
||||
expected_output = [
|
||||
'{\n \x1b[34;01m"key1"\x1b[39;00m: \x1b[32m"value1"\x1b[39m,\n \x1b[34;01m"key2"\x1b[39;00m: \x1b[35m2\x1b[39m,\n \x1b[34;01m"key3"\x1b[39;00m: \x1b[90mnull\x1b[39m,\n \x1b[34;01m"key4"\x1b[39;00m: \x1b[35m3.14\x1b[39m,\n \x1b[34;01m"key5"\x1b[39;00m: \x1b[90mtrue\x1b[39m\n}',
|
||||
'{\n \x1b[34;01m"key1"\x1b[39;00m: [\n {\n \x1b[34;01m"subkey1"\x1b[39;00m: \x1b[32m"subvalue1"\x1b[39m\n },\n {\n \x1b[34;01m"subkey2"\x1b[39;00m: [\n \x1b[35m1\x1b[39m,\n \x1b[35m2\x1b[39m,\n \x1b[35m3\x1b[39m\n ]\n }\n ],\n \x1b[34;01m"key2"\x1b[39;00m: \x1b[90mtrue\x1b[39m\n}'
|
||||
]
|
||||
|
||||
if pygments.__version__.startswith('2.3.'):
|
||||
expected_output = [
|
||||
'{\n \x1b[34;01m"key1"\x1b[39;00m: \x1b[32m"value1"\x1b[39m,\n \x1b[34;01m"key2"\x1b[39;00m: \x1b[35m2\x1b[39m,\n \x1b[34;01m"key3"\x1b[39;00m: \x1b[30;01mnull\x1b[39;00m,\n \x1b[34;01m"key4"\x1b[39;00m: \x1b[35m3.14\x1b[39m,\n \x1b[34;01m"key5"\x1b[39;00m: \x1b[30;01mtrue\x1b[39;00m\n}',
|
||||
'{\n \x1b[34;01m"key1"\x1b[39;00m: [\n {\n \x1b[34;01m"subkey1"\x1b[39;00m: \x1b[32m"subvalue1"\x1b[39m\n },\n {\n \x1b[34;01m"subkey2"\x1b[39;00m: [\n \x1b[35m1\x1b[39m,\n \x1b[35m2\x1b[39m,\n \x1b[35m3\x1b[39m\n ]\n }\n ],\n \x1b[34;01m"key2"\x1b[39;00m: \x1b[30;01mtrue\x1b[39;00m\n}'
|
||||
]
|
||||
else:
|
||||
expected_output = [
|
||||
'{\n \x1b[34;01m"key1"\x1b[39;00m: \x1b[32m"value1"\x1b[39m,\n \x1b[34;01m"key2"\x1b[39;00m: \x1b[35m2\x1b[39m,\n \x1b[34;01m"key3"\x1b[39;00m: \x1b[90mnull\x1b[39m,\n \x1b[34;01m"key4"\x1b[39;00m: \x1b[35m3.14\x1b[39m,\n \x1b[34;01m"key5"\x1b[39;00m: \x1b[90mtrue\x1b[39m\n}',
|
||||
'{\n \x1b[34;01m"key1"\x1b[39;00m: [\n {\n \x1b[34;01m"subkey1"\x1b[39;00m: \x1b[32m"subvalue1"\x1b[39m\n },\n {\n \x1b[34;01m"subkey2"\x1b[39;00m: [\n \x1b[35m1\x1b[39m,\n \x1b[35m2\x1b[39m,\n \x1b[35m3\x1b[39m\n ]\n }\n ],\n \x1b[34;01m"key2"\x1b[39;00m: \x1b[90mtrue\x1b[39m\n}'
|
||||
]
|
||||
|
||||
for test_dict, expected_json in zip(test_input, expected_output):
|
||||
cli = JcCli()
|
||||
cli.pretty = True
|
||||
cli.set_custom_colors()
|
||||
cli.data_out = test_dict
|
||||
self.assertEqual(cli.json_out(), expected_json)
|
||||
for test_dict, expected_json in zip(test_input, expected_output):
|
||||
cli = JcCli()
|
||||
cli.pretty = True
|
||||
cli.set_custom_colors()
|
||||
cli.data_out = test_dict
|
||||
self.assertEqual(cli.json_out(), expected_json)
|
||||
|
||||
def test_cli_yaml_out(self):
|
||||
if PYGMENTS_INSTALLED:
|
||||
@ -461,5 +462,15 @@ class MyTests(unittest.TestCase):
|
||||
cli.slicer()
|
||||
self.assertEqual(list(cli.data_in), expected)
|
||||
|
||||
def test_slurp(self):
|
||||
cli = JcCli()
|
||||
cli.parser_module = url_parser
|
||||
cli.data_in = '''http://www.google.com
|
||||
https://www.kelly.com/testing
|
||||
https://mail.apple.com'''
|
||||
expected = [{"url":"http://www.google.com","scheme":"http","netloc":"www.google.com","path":None,"parent":None,"filename":None,"stem":None,"extension":None,"path_list":None,"query":None,"query_obj":None,"fragment":None,"username":None,"password":None,"hostname":"www.google.com","port":None,"encoded":{"url":"http://www.google.com","scheme":"http","netloc":"www.google.com","path":None,"parent":None,"filename":None,"stem":None,"extension":None,"path_list":None,"query":None,"fragment":None,"username":None,"password":None,"hostname":"www.google.com","port":None},"decoded":{"url":"http://www.google.com","scheme":"http","netloc":"www.google.com","path":None,"parent":None,"filename":None,"stem":None,"extension":None,"path_list":None,"query":None,"fragment":None,"username":None,"password":None,"hostname":"www.google.com","port":None}},{"url":"https://www.kelly.com/testing","scheme":"https","netloc":"www.kelly.com","path":"/testing","parent":"/","filename":"testing","stem":"testing","extension":None,"path_list":["testing"],"query":None,"query_obj":None,"fragment":None,"username":None,"password":None,"hostname":"www.kelly.com","port":None,"encoded":{"url":"https://www.kelly.com/testing","scheme":"https","netloc":"www.kelly.com","path":"/testing","parent":"/","filename":"testing","stem":"testing","extension":None,"path_list":["testing"],"query":None,"fragment":None,"username":None,"password":None,"hostname":"www.kelly.com","port":None},"decoded":{"url":"https://www.kelly.com/testing","scheme":"https","netloc":"www.kelly.com","path":"/testing","parent":"/","filename":"testing","stem":"testing","extension":None,"path_list":["testing"],"query":None,"fragment":None,"username":None,"password":None,"hostname":"www.kelly.com","port":None}},{"url":"https://mail.apple.com","scheme":"https","netloc":"mail.apple.com","path":None,"parent":None,"filename":None,"stem":None,"extension":None,"path_list":None,"query":None,"query_obj":None,"fragment":None,"username":None,"password":None,"hostname":"mail.apple.com","port":None,"encoded":{"url":"https://mail.apple.com","scheme":"https","netloc":"mail.apple.com","path":None,"parent":None,"filename":None,"stem":None,"extension":None,"path_list":None,"query":None,"fragment":None,"username":None,"password":None,"hostname":"mail.apple.com","port":None},"decoded":{"url":"https://mail.apple.com","scheme":"https","netloc":"mail.apple.com","path":None,"parent":None,"filename":None,"stem":None,"extension":None,"path_list":None,"query":None,"fragment":None,"username":None,"password":None,"hostname":"mail.apple.com","port":None}}]
|
||||
cli.create_slurp_output()
|
||||
self.assertEqual(cli.data_out, expected)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Reference in New Issue
Block a user