mirror of
https://github.com/adrienverge/yamllint.git
synced 2024-11-22 07:36:25 -06:00
Specify config with environment variable YAMLLINT_CONFIG_FILE
Add option to specify config file with environment variable. Add test case.
This commit is contained in:
parent
a54cbce1b6
commit
94c0416f6b
@ -24,6 +24,7 @@ import os
|
||||
import pty
|
||||
import shutil
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
from tests.common import build_temp_workspace
|
||||
@ -285,6 +286,25 @@ class CommandLineTestCase(unittest.TestCase):
|
||||
cli.run((os.path.join(self.wd, 'a.yaml'), ))
|
||||
self.assertEqual(ctx.returncode, 1)
|
||||
|
||||
def test_run_with_user_yamllint_config_file_in_env(self):
|
||||
self.addCleanup(os.environ.__delitem__, 'YAMLLINT_CONFIG_FILE')
|
||||
|
||||
with tempfile.NamedTemporaryFile('w') as f:
|
||||
os.environ['YAMLLINT_CONFIG_FILE'] = f.name
|
||||
f.write('rules: {trailing-spaces: disable}')
|
||||
f.flush()
|
||||
with RunContext(self) as ctx:
|
||||
cli.run((os.path.join(self.wd, 'a.yaml'), ))
|
||||
self.assertEqual(ctx.returncode, 0)
|
||||
|
||||
with tempfile.NamedTemporaryFile('w') as f:
|
||||
os.environ['YAMLLINT_CONFIG_FILE'] = f.name
|
||||
f.write('rules: {trailing-spaces: enable}')
|
||||
f.flush()
|
||||
with RunContext(self) as ctx:
|
||||
cli.run((os.path.join(self.wd, 'a.yaml'), ))
|
||||
self.assertEqual(ctx.returncode, 1)
|
||||
|
||||
def test_run_version(self):
|
||||
with RunContext(self) as ctx:
|
||||
cli.run(('--version', ))
|
||||
|
@ -144,8 +144,11 @@ def run(argv=None):
|
||||
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
if 'YAMLLINT_CONFIG_FILE' in os.environ:
|
||||
user_global_config = os.path.expanduser(
|
||||
os.environ['YAMLLINT_CONFIG_FILE'])
|
||||
# User-global config is supposed to be in ~/.config/yamllint/config
|
||||
if 'XDG_CONFIG_HOME' in os.environ:
|
||||
elif 'XDG_CONFIG_HOME' in os.environ:
|
||||
user_global_config = os.path.join(
|
||||
os.environ['XDG_CONFIG_HOME'], 'yamllint', 'config')
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user