cli: read optional config from YAMLLINT_CONFIG

This is a "minor" abi break since empty configs are
disregarded instead of failing.

Fixes: https://github.com/adrienverge/yamllint/issues/107
This commit is contained in:
Johan Bergström
2018-06-28 11:10:16 -04:00
parent e4e99f0aba
commit e52c1acd2a
2 changed files with 16 additions and 3 deletions

View File

@@ -165,7 +165,19 @@ class CommandLineTestCase(unittest.TestCase):
out, err = sys.stdout.getvalue(), sys.stderr.getvalue()
self.assertEqual(out, '')
self.assertRegexpMatches(err, r'^invalid config: not a dict')
self.assertRegexpMatches(err, r'No such file or directory')
def test_run_with_environment_variable(self):
sys.stdout, sys.stderr = StringIO(), StringIO()
rules = '{extends: default, rules: {document-start: {present: false}}}'
with self.assertRaises(SystemExit) as ctx:
os.environ['YAMLLINT_CONFIG'] = rules
cli.run((os.path.join(self.wd, 'warn.yaml'), ))
self.assertEqual(ctx.exception.code, 0)
out = sys.stdout.getvalue()
self.assertEqual(out, '')
del os.environ['YAMLLINT_CONFIG']
def test_run_with_config_file(self):
with open(os.path.join(self.wd, 'config'), 'w') as f: