From d30edb2dae16f9d229ce9dce3aa6faa9104c77f4 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Fri, 20 May 2022 18:15:56 -0700 Subject: [PATCH] add yaml_out tests --- tests/test_cli.py | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/tests/test_cli.py b/tests/test_cli.py index 55b42bea..0f0ecd66 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -195,7 +195,59 @@ class MyTests(unittest.TestCase): for test_dict, expected_json in zip(test_input, expected_output): self.assertEqual(jc.cli.json_out(test_dict, pretty=True), expected_json) + def test_cli_yaml_out(self): + test_input = [ + None, + {}, + [], + '', + {"key1": "value1", "key2": 2, "key3": None, "key4": 3.14, "key5": True}, + ] + + if pygments.__version__.startswith('2.3.'): + expected_output = [ + '---\n...', + '--- {}', + '--- []', + "--- \x1b[32m'\x1b[39m\x1b[32m'\x1b[39m", + '---\nkey1: value1\nkey2: 2\nkey3:\nkey4: 3.14\nkey5: true' + ] + else: + expected_output = [ + '---\n...', + '--- {}', + '--- []', + "--- \x1b[32m'\x1b[39m\x1b[32m'\x1b[39m", + '---\n\x1b[34;01mkey1\x1b[39;00m: value1\n\x1b[34;01mkey2\x1b[39;00m: 2\n\x1b[34;01mkey3\x1b[39;00m:\n\x1b[34;01mkey4\x1b[39;00m: 3.14\n\x1b[34;01mkey5\x1b[39;00m: true' + ] + + for test_dict, expected_json in zip(test_input, expected_output): + self.assertEqual(jc.cli.yaml_out(test_dict), expected_json) + + def test_cli_yaml_out_mono(self): + test_input = [ + None, + {}, + [], + '', + {"key1": "value1", "key2": 2, "key3": None, "key4": 3.14, "key5": True}, + ] + + expected_output = [ + '---\n...', + '--- {}', + '--- []', + "--- ''", + '---\nkey1: value1\nkey2: 2\nkey3:\nkey4: 3.14\nkey5: true' + ] + + for test_dict, expected_json in zip(test_input, expected_output): + self.assertEqual(jc.cli.yaml_out(test_dict, mono=True), expected_json) + def test_cli_about_jc(self): self.assertEqual(jc.cli.about_jc()['name'], 'jc') self.assertGreaterEqual(jc.cli.about_jc()['parser_count'], 55) self.assertEqual(jc.cli.about_jc()['parser_count'], len(jc.cli.about_jc()['parsers'])) + +if __name__ == '__main__': + unittest.main() \ No newline at end of file