From ad46f33b1d09ffada9bd259d5cc1fa8a612f1c12 Mon Sep 17 00:00:00 2001 From: QuentinN42 Date: Fri, 11 Feb 2022 13:55:52 +0100 Subject: [PATCH] test: remaining tests done --- tests/test_format.py | 52 ++++++++++++++++++++++++++++++++++++++++++-- yamllint/format.py | 6 ++--- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/tests/test_format.py b/tests/test_format.py index f1d6ac4..1d08f9a 100644 --- a/tests/test_format.py +++ b/tests/test_format.py @@ -8,6 +8,7 @@ from yamllint.linter import LintProblem from yamllint.format import ( escape_xml, severity_from_level, + max_level, Formater, ParsableFormater, GithubFormater, @@ -218,5 +219,52 @@ class FormatersTestCase(unittest.TestCase): ) -# TODO : test max level -# TODO : test junit +@ddt.ddt +class MaxLevelTestCase(unittest.TestCase): + + @ddt.data( + (NONE, 0), + (NO_ERROR, 0), + (ONE_NOTHING, 0), + (ONE_ERROR, 2), + (ONE_WARNING, 1), + (MIXED_ONE_FILE, 2), + (MIXED_MULT_FILE, 2), + ) + @ddt.unpack + def test_all_formaters(self, inp, ret): + self.assertEqual(max_level(inp), ret) + +@ddt.ddt +class JunitTestCase(unittest.TestCase): + + @ddt.data( + (NONE, False, [], ['<\/error><\/testcase>', '<\/failure><\/testcase>'], 7), + (NO_ERROR, False, [], ['<\/error><\/testcase>', '<\/failure><\/testcase>'], 7), + (ONE_NOTHING, False, [], ['<\/error><\/testcase>', '<\/failure><\/testcase>'], 7), + (ONE_ERROR, False, ['<\/error><\/testcase>'], ['<\/failure><\/testcase>'], 7), + (ONE_WARNING, False, ['<\/failure><\/testcase>'], ['<\/error><\/testcase>'], 7), + (ONE_WARNING, True, [], ['<\/error><\/testcase>', '<\/failure><\/testcase>'], 7), + (MIXED_ONE_FILE, False, ['<\/error><\/testcase>', '<\/failure><\/testcase>'], [], 8), + (MIXED_MULT_FILE, False, ['<\/error><\/testcase>', '<\/failure><\/testcase>'], [], 8), + ) + @ddt.unpack + def test_all_formaters(self, inp, no_warn, contain, not_contain, length): + res = JunitFormater(no_warn).show_problems_for_all_files(inp) + self.assertTrue(res.startswith( + '\n' \ + '\n' \ + ' \n' \ + '\n')) + + self.assertEqual(len(res.split('\n')), length) diff --git a/yamllint/format.py b/yamllint/format.py index 6875dd0..287501d 100644 --- a/yamllint/format.py +++ b/yamllint/format.py @@ -307,9 +307,7 @@ class JunitFormater(Formater): lines = [] for item in lst: - if item['level'] is None: - continue - elif item['level'] == 'warning': + if item['level'] == 'warning': warnings += 1 to_append = '<\/failure><\/testcase>' # noqa elif item['level'] == 'error': @@ -323,7 +321,7 @@ class JunitFormater(Formater): escape_xml(item['desc'])) ) - string += ' '*4 + '\n' % (errors, warnings, errors + warnings, datetime.datetime.now().isoformat(), platform.node()) # noqa + string += ' '*4 + '\n' % (errors, warnings, errors + warnings, datetime.datetime.now().isoformat(), platform.node()) # noqa string += '\n'.join(lines) + '\n' string += ' \n\n' return string