File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed
Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -165,7 +165,19 @@ def test_run_with_empty_config(self):
165165
166166 out , err = sys .stdout .getvalue (), sys .stderr .getvalue ()
167167 self .assertEqual (out , '' )
168- self .assertRegexpMatches (err , r'^invalid config: not a dict' )
168+ self .assertRegexpMatches (err , r'No such file or directory' )
169+
170+ def test_run_with_environment_variable (self ):
171+ sys .stdout , sys .stderr = StringIO (), StringIO ()
172+ rules = '{extends: default, rules: {document-start: {present: false}}}'
173+ with self .assertRaises (SystemExit ) as ctx :
174+ os .environ ['YAMLLINT_CONFIG' ] = rules
175+ cli .run ((os .path .join (self .wd , 'warn.yaml' ), ))
176+
177+ self .assertEqual (ctx .exception .code , 0 )
178+ out = sys .stdout .getvalue ()
179+ self .assertEqual (out , '' )
180+ del os .environ ['YAMLLINT_CONFIG' ]
169181
170182 def test_run_with_config_file (self ):
171183 with open (os .path .join (self .wd , 'config' ), 'w' ) as f :
Original file line number Diff line number Diff line change @@ -94,6 +94,7 @@ def run(argv=None):
9494 help = 'path to a custom configuration' )
9595 config_group .add_argument ('-d' , '--config-data' , dest = 'config_data' ,
9696 action = 'store' ,
97+ default = os .environ .get ('YAMLLINT_CONFIG' , '' ),
9798 help = 'custom configuration (as YAML source)' )
9899 parser .add_argument ('-f' , '--format' ,
99100 choices = ('parsable' , 'standard' ), default = 'standard' ,
@@ -117,8 +118,8 @@ def run(argv=None):
117118 user_global_config = os .path .expanduser ('~/.config/yamllint/config' )
118119
119120 try :
120- if args .config_data is not None :
121- if args . config_data != '' and ':' not in args .config_data :
121+ if args .config_data != '' :
122+ if ':' not in args .config_data :
122123 args .config_data = 'extends: ' + args .config_data
123124 conf = YamlLintConfig (content = args .config_data )
124125 elif args .config_file is not None :
You can’t perform that action at this time.
0 commit comments