Add --no-warnings option to suppress warning messages

Use `--no-warnings` option to hide warning messages. It only shows
problems marked as errors.
This commit is contained in:
ffapitalle
2019-12-12 05:12:53 -03:00
committed by Adrien Vergé
parent da3788e95a
commit 8fa9eb3ced
3 changed files with 49 additions and 4 deletions

View File

@@ -532,3 +532,38 @@ class CommandLineTestCase(unittest.TestCase):
'stdin:2:10: [error] syntax error: '
'mapping values are not allowed here\n'))
self.assertEqual(err, '')
def test_run_no_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)
def test_run_no_warnings_and_strict(self):
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', '-s'))
self.assertEqual(ctx.exception.code, 2)