From 55945f0842d19e189b470536a6f4f0fd82fbe38d Mon Sep 17 00:00:00 2001 From: Federico Fapitalle Date: Tue, 10 Dec 2019 10:29:03 -0300 Subject: [PATCH] Adds test case for no-warnings option Adds a test case to check --no-warning option. --- tests/test_cli.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/test_cli.py b/tests/test_cli.py index fbdf75f..d08f640 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -532,3 +532,29 @@ class CommandLineTestCase(unittest.TestCase): 'stdin:2:10: [error] syntax error: ' 'mapping values are not allowed here\n')) self.assertEqual(err, '') + + def test_run_supress_warnings(self): + file = os.path.join(self.wd, 'a.yaml') + + sys.stdout, sys.stderr = StringIO(), StringIO() + with self.assertRaises(SystemExit) as ctx: + cli.run((file, '--no-warnings', '-f', 'auto')) + + self.assertEqual(ctx.exception.code, 1) + + out, err = sys.stdout.getvalue(), sys.stderr.getvalue() + self.assertEqual(out, ( + '%s\n' + ' 2:4 error trailing spaces (trailing-spaces)\n' + ' 3:4 error no new line character at the end of file ' + '(new-line-at-end-of-file)\n' + '\n' % file)) + self.assertEqual(err, '') + + file = os.path.join(self.wd, 'warn.yaml') + + sys.stdout, sys.stderr = StringIO(), StringIO() + with self.assertRaises(SystemExit) as ctx: + cli.run((file, '--no-warnings', '-f', 'auto')) + + self.assertEqual(ctx.exception.code, 0)