test: remaining tests done
This commit is contained in:
@@ -8,6 +8,7 @@ from yamllint.linter import LintProblem
|
|||||||
from yamllint.format import (
|
from yamllint.format import (
|
||||||
escape_xml,
|
escape_xml,
|
||||||
severity_from_level,
|
severity_from_level,
|
||||||
|
max_level,
|
||||||
Formater,
|
Formater,
|
||||||
ParsableFormater,
|
ParsableFormater,
|
||||||
GithubFormater,
|
GithubFormater,
|
||||||
@@ -218,5 +219,52 @@ class FormatersTestCase(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# TODO : test max level
|
@ddt.ddt
|
||||||
# TODO : test junit
|
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(
|
||||||
|
'<?xml version="1.0" encoding="utf-8"?>\n' \
|
||||||
|
'<testsuites>\n' \
|
||||||
|
' <testsuite name="yamllint" '
|
||||||
|
))
|
||||||
|
|
||||||
|
for e in contain:
|
||||||
|
self.assertTrue(e in res)
|
||||||
|
for e in not_contain:
|
||||||
|
self.assertFalse(e in res)
|
||||||
|
|
||||||
|
self.assertTrue(res.endswith(
|
||||||
|
'\n' \
|
||||||
|
' </testsuite>\n' \
|
||||||
|
'</testsuites>\n'))
|
||||||
|
|
||||||
|
self.assertEqual(len(res.split('\n')), length)
|
||||||
|
|||||||
@@ -307,9 +307,7 @@ class JunitFormater(Formater):
|
|||||||
|
|
||||||
lines = []
|
lines = []
|
||||||
for item in lst:
|
for item in lst:
|
||||||
if item['level'] is None:
|
if item['level'] == 'warning':
|
||||||
continue
|
|
||||||
elif item['level'] == 'warning':
|
|
||||||
warnings += 1
|
warnings += 1
|
||||||
to_append = '<testcase classname="%s:%d:%d" name="%s" time="0.0"><failure message="%s"><\/failure><\/testcase>' # noqa
|
to_append = '<testcase classname="%s:%d:%d" name="%s" time="0.0"><failure message="%s"><\/failure><\/testcase>' # noqa
|
||||||
elif item['level'] == 'error':
|
elif item['level'] == 'error':
|
||||||
@@ -323,7 +321,7 @@ class JunitFormater(Formater):
|
|||||||
escape_xml(item['desc']))
|
escape_xml(item['desc']))
|
||||||
)
|
)
|
||||||
|
|
||||||
string += ' '*4 + '<testsuite name="pytest" errors="%d" failures="%d" skipped="0" tests="%d" time="0" timestamp="%s" hostname="%s">\n' % (errors, warnings, errors + warnings, datetime.datetime.now().isoformat(), platform.node()) # noqa
|
string += ' '*4 + '<testsuite name="yamllint" errors="%d" failures="%d" skipped="0" tests="%d" time="0" timestamp="%s" hostname="%s">\n' % (errors, warnings, errors + warnings, datetime.datetime.now().isoformat(), platform.node()) # noqa
|
||||||
string += '\n'.join(lines) + '\n'
|
string += '\n'.join(lines) + '\n'
|
||||||
string += ' </testsuite>\n</testsuites>\n'
|
string += ' </testsuite>\n</testsuites>\n'
|
||||||
return string
|
return string
|
||||||
|
|||||||
Reference in New Issue
Block a user