pull/119/merge
Johan Bergström 5 years ago committed by GitHub
commit 8f301c09eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -239,7 +239,19 @@ class CommandLineTestCase(unittest.TestCase):
out, err = sys.stdout.getvalue(), sys.stderr.getvalue() out, err = sys.stdout.getvalue(), sys.stderr.getvalue()
self.assertEqual(out, '') 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): def test_run_with_config_file(self):
with open(os.path.join(self.wd, 'config'), 'w') as f: with open(os.path.join(self.wd, 'config'), 'w') as f:

@ -127,6 +127,7 @@ def run(argv=None):
help='path to a custom configuration') help='path to a custom configuration')
config_group.add_argument('-d', '--config-data', dest='config_data', config_group.add_argument('-d', '--config-data', dest='config_data',
action='store', action='store',
default=os.environ.get('YAMLLINT_CONFIG', ''),
help='custom configuration (as YAML source)') help='custom configuration (as YAML source)')
parser.add_argument('-f', '--format', parser.add_argument('-f', '--format',
choices=('parsable', 'standard', 'colored', 'auto'), choices=('parsable', 'standard', 'colored', 'auto'),
@ -151,8 +152,8 @@ def run(argv=None):
user_global_config = os.path.expanduser('~/.config/yamllint/config') user_global_config = os.path.expanduser('~/.config/yamllint/config')
try: try:
if args.config_data is not None: if args.config_data != '':
if args.config_data != '' and ':' not in args.config_data: if ':' not in args.config_data:
args.config_data = 'extends: ' + args.config_data args.config_data = 'extends: ' + args.config_data
conf = YamlLintConfig(content=args.config_data) conf = YamlLintConfig(content=args.config_data)
elif args.config_file is not None: elif args.config_file is not None:

Loading…
Cancel
Save