Tests: cli: Detect and handle the -d '' case
This commit is contained in:
@@ -139,7 +139,19 @@ class CommandLineTestCase(unittest.TestCase):
|
||||
self.assertEqual(ctx.exception.code, -1)
|
||||
|
||||
out, err = sys.stdout.getvalue(), sys.stderr.getvalue()
|
||||
self.assertRegexpMatches(out + err, r'^invalid config')
|
||||
self.assertEqual(out, '')
|
||||
self.assertRegexpMatches(err, r'^invalid config: no such rule')
|
||||
|
||||
def test_run_with_empty_config(self):
|
||||
sys.stdout, sys.stderr = StringIO(), StringIO()
|
||||
with self.assertRaises(SystemExit) as ctx:
|
||||
cli.run(('-d', '', 'file'))
|
||||
|
||||
self.assertEqual(ctx.exception.code, -1)
|
||||
|
||||
out, err = sys.stdout.getvalue(), sys.stderr.getvalue()
|
||||
self.assertEqual(out, '')
|
||||
self.assertRegexpMatches(err, r'^invalid config: not a dict')
|
||||
|
||||
def test_run_version(self):
|
||||
sys.stdout, sys.stderr = StringIO(), StringIO()
|
||||
|
||||
@@ -88,7 +88,7 @@ def run(argv=None):
|
||||
|
||||
try:
|
||||
if args.config_data is not None:
|
||||
if ':' not in args.config_data:
|
||||
if args.config_data != '' and ':' not in args.config_data:
|
||||
args.config_data = 'extends: ' + args.config_data
|
||||
conf = YamlLintConfig(content=args.config_data)
|
||||
elif args.config_file is not None:
|
||||
|
||||
@@ -59,6 +59,9 @@ class YamlLintConfig(object):
|
||||
except Exception as e:
|
||||
raise YamlLintConfigError('invalid config: %s' % e)
|
||||
|
||||
if type(conf) != dict:
|
||||
raise YamlLintConfigError('invalid config: not a dict')
|
||||
|
||||
self.rules = conf.get('rules', {})
|
||||
|
||||
# Does this conf override another conf that we need to load?
|
||||
|
||||
Reference in New Issue
Block a user