Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON & XML formaters #442

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
81951b3
chore: ignore venv
QuentinN42 Feb 3, 2022
b858cbb
refactor: moved formater inside another file
QuentinN42 Feb 3, 2022
3601817
refactor: moved output at the end of the tests
QuentinN42 Feb 3, 2022
46a12a8
fix: missed return statement
QuentinN42 Feb 3, 2022
c4463c7
feat: max_level as separate function
QuentinN42 Feb 3, 2022
6217241
refactor: use object inheritance for the formaters
QuentinN42 Feb 3, 2022
fbf8108
feat: json formater
QuentinN42 Feb 3, 2022
805b9a9
feat: junitxml formater
QuentinN42 Feb 3, 2022
6a06e8d
feat: changed json output file name to path
QuentinN42 Feb 5, 2022
2839489
typo
QuentinN42 Feb 5, 2022
d24519c
feat: add codeclimate output
QuentinN42 Feb 5, 2022
4baaf12
feat: add message to the json format
QuentinN42 Feb 5, 2022
e04f03a
feat: auto infer formats
QuentinN42 Feb 5, 2022
4057451
feat: changed json format according to @adrienverge comment
QuentinN42 Feb 8, 2022
dab7a80
fix: test_run_with_user_global_config_file patched
QuentinN42 Feb 10, 2022
b1ce2f2
test: escape_xml
QuentinN42 Feb 10, 2022
32de447
test: severity_from_level
QuentinN42 Feb 10, 2022
eb48e1d
test: Base class test
QuentinN42 Feb 10, 2022
1f6adf6
test: Class to test all fmt
QuentinN42 Feb 10, 2022
b42ac81
chore: rm coverage
QuentinN42 Feb 10, 2022
d666308
tests: use ddt to parametrize tests
QuentinN42 Feb 10, 2022
4ae5487
feat: add the possibility to pass the level as argument
QuentinN42 Feb 10, 2022
418952c
refactor: match flake requirements
QuentinN42 Feb 10, 2022
48b5e2b
tests: tested formats with errors
QuentinN42 Feb 10, 2022
e018da1
feat: fixed some isues
QuentinN42 Feb 10, 2022
0354c33
ci: add ddt to the tests requirements and update the contributing fil…
QuentinN42 Feb 11, 2022
3561a77
tests: testing skipping warn with None level
QuentinN42 Feb 11, 2022
64e19e8
fix: filter None to exclude them
QuentinN42 Feb 11, 2022
f0000a1
test: test with mixed errors / files
QuentinN42 Feb 11, 2022
fba5b70
tests: use ddt to others classes
QuentinN42 Feb 11, 2022
d7f59fe
test: escape real text
QuentinN42 Feb 11, 2022
ad46f33
test: remaining tests done
QuentinN42 Feb 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
test: remaining tests done
  • Loading branch information
QuentinN42 committed Feb 11, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit ad46f33b1d09ffada9bd259d5cc1fa8a612f1c12
52 changes: 50 additions & 2 deletions tests/test_format.py
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
from yamllint.format import (
escape_xml,
severity_from_level,
max_level,
Formater,
ParsableFormater,
GithubFormater,
@@ -218,5 +219,52 @@ def test_all_formaters(self, inst, inp, ret):
)


# 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(
'<?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)
6 changes: 2 additions & 4 deletions yamllint/format.py
Original file line number Diff line number Diff line change
@@ -307,9 +307,7 @@ def show_problems_for_all_files(self, all_problems):

lines = []
for item in lst:
if item['level'] is None:
continue
elif item['level'] == 'warning':
if item['level'] == 'warning':
warnings += 1
to_append = '<testcase classname="%s:%d:%d" name="%s" time="0.0"><failure message="%s"><\/failure><\/testcase>' # noqa
elif item['level'] == 'error':
@@ -323,7 +321,7 @@ def show_problems_for_all_files(self, all_problems):
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 += ' </testsuite>\n</testsuites>\n'
return string