refactor: moved output at the end of the tests

pull/442/head
QuentinN42 3 years ago
parent b858cbbb82
commit 3601817dd2
No known key found for this signature in database
GPG Key ID: 2CD7D563712B3A50

@ -26,7 +26,7 @@ from yamllint import APP_DESCRIPTION, APP_NAME, APP_VERSION
from yamllint import linter
from yamllint.config import YamlLintConfig, YamlLintConfigError
from yamllint.linter import PROBLEM_LEVELS
from yamllint.format import show_problems
from yamllint.format import show_all_problems
def find_files_recursively(items, conf):
@ -107,7 +107,8 @@ def run(argv=None):
if conf.locale is not None:
locale.setlocale(locale.LC_ALL, conf.locale)
max_level = 0
# problems dict: {file: problems}
all_problems = dict()
for file in find_files_recursively(args.files, conf):
filepath = file[2:] if file.startswith('./') else file
@ -117,20 +118,22 @@ def run(argv=None):
except EnvironmentError as e:
print(e, file=sys.stderr)
sys.exit(-1)
prob_level = show_problems(problems, file, args_format=args.format,
no_warn=args.no_warnings)
max_level = max(max_level, prob_level)
all_problems[file] = problems
# read yaml from stdin
if args.stdin:
# read yaml from stdin
try:
problems = linter.run(sys.stdin, conf, '')
except EnvironmentError as e:
print(e, file=sys.stderr)
sys.exit(-1)
prob_level = show_problems(problems, 'stdin', args_format=args.format,
no_warn=args.no_warnings)
max_level = max(max_level, prob_level)
all_problems['stdin'] = problems
max_level = show_all_problems(
all_problems,
args_format=args.format,
no_warn=args.no_warnings
)
if max_level == PROBLEM_LEVELS['error']:
return_code = 1

@ -16,6 +16,7 @@ def supports_color():
return (supported_platform and
hasattr(sys.stdout, 'isatty') and sys.stdout.isatty())
class Format(object):
@staticmethod
def parsable(problem, filename):
@ -109,3 +110,12 @@ def show_problems(problems, file, args_format, no_warn):
print('')
return max_level
def show_all_problems(all_problems, args_format, no_warn):
"""Print all problems, return the max level."""
max_level = 0
for file, problem in all_problems.items():
curr_level = show_problems(problem, file, args_format, no_warn)
max_level = max(curr_level, max_level)

Loading…
Cancel
Save