|
|
|
@ -19,65 +19,79 @@ from yamllint.format import (
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ddt.ddt
|
|
|
|
|
class TextToXMLTestCase(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
specials = {
|
|
|
|
|
'&': '&',
|
|
|
|
|
'<': '<',
|
|
|
|
|
'>': '>',
|
|
|
|
|
'"': '"',
|
|
|
|
|
"'": '''
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def test_letters_chars(self):
|
|
|
|
|
txt = string.ascii_letters
|
|
|
|
|
self.assertEqual(escape_xml(txt), txt)
|
|
|
|
|
|
|
|
|
|
def test_specials_chars(self):
|
|
|
|
|
for inp, out in self.specials.items():
|
|
|
|
|
self.assertEqual(escape_xml(inp), out)
|
|
|
|
|
@ddt.data(
|
|
|
|
|
('&', '&'),
|
|
|
|
|
('<', '<'),
|
|
|
|
|
('>', '>'),
|
|
|
|
|
('"', '"'),
|
|
|
|
|
("'", '''),
|
|
|
|
|
)
|
|
|
|
|
@ddt.unpack
|
|
|
|
|
def test_specials_chars(self, inp, out):
|
|
|
|
|
self.assertEqual(escape_xml(inp), out)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ddt.ddt
|
|
|
|
|
class CodeClimateSeverityTestCase(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
expected = {
|
|
|
|
|
None: "info",
|
|
|
|
|
'warning': "minor",
|
|
|
|
|
'error': "major",
|
|
|
|
|
0: "info",
|
|
|
|
|
1: "minor",
|
|
|
|
|
2: "major",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def test_specials_chars(self):
|
|
|
|
|
for inp, out in self.expected.items():
|
|
|
|
|
self.assertEqual(severity_from_level(inp), out)
|
|
|
|
|
@ddt.data(
|
|
|
|
|
(None, "info"),
|
|
|
|
|
('warning', "minor"),
|
|
|
|
|
('error', "major"),
|
|
|
|
|
(0, "info"),
|
|
|
|
|
(1, "minor"),
|
|
|
|
|
(2, "major"),
|
|
|
|
|
)
|
|
|
|
|
@ddt.unpack
|
|
|
|
|
def test_specials_chars(self, inp, out):
|
|
|
|
|
self.assertEqual(severity_from_level(inp), out)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ddt.ddt
|
|
|
|
|
class FormaterTestCase(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
sublcasses = {
|
|
|
|
|
"parsable": ParsableFormater,
|
|
|
|
|
"github": GithubFormater,
|
|
|
|
|
"colored": ColoredFormater,
|
|
|
|
|
"standard": StandardFormater,
|
|
|
|
|
"json": JSONFormater,
|
|
|
|
|
"junitxml": JunitFormater,
|
|
|
|
|
"codeclimate": CodeclimateFormater
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def test_get_formaters_names(self):
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
set(Formater.get_formaters_names()),
|
|
|
|
|
set(self.sublcasses.keys())
|
|
|
|
|
{
|
|
|
|
|
"parsable",
|
|
|
|
|
"github",
|
|
|
|
|
"colored",
|
|
|
|
|
"standard",
|
|
|
|
|
"json",
|
|
|
|
|
"junitxml",
|
|
|
|
|
"codeclimate"
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def test_get_formater(self):
|
|
|
|
|
for no_warn in [True, False]:
|
|
|
|
|
for name, cls in self.sublcasses.items():
|
|
|
|
|
res = Formater.get_formater(name, no_warn)
|
|
|
|
|
self.assertTrue(isinstance(res, cls))
|
|
|
|
|
self.assertEqual(res.no_warn, no_warn)
|
|
|
|
|
@ddt.data(
|
|
|
|
|
("parsable", ParsableFormater, True),
|
|
|
|
|
("github", GithubFormater, True),
|
|
|
|
|
("colored", ColoredFormater, True),
|
|
|
|
|
("standard", StandardFormater, True),
|
|
|
|
|
("json", JSONFormater, True),
|
|
|
|
|
("junitxml", JunitFormater, True),
|
|
|
|
|
("codeclimate", CodeclimateFormater, True),
|
|
|
|
|
("parsable", ParsableFormater, False),
|
|
|
|
|
("github", GithubFormater, False),
|
|
|
|
|
("colored", ColoredFormater, False),
|
|
|
|
|
("standard", StandardFormater, False),
|
|
|
|
|
("json", JSONFormater, False),
|
|
|
|
|
("junitxml", JunitFormater, False),
|
|
|
|
|
("codeclimate", CodeclimateFormater, False),
|
|
|
|
|
)
|
|
|
|
|
@ddt.unpack
|
|
|
|
|
def test_get_formater(self, name, cls, no_warn):
|
|
|
|
|
res = Formater.get_formater(name, no_warn)
|
|
|
|
|
self.assertTrue(isinstance(res, cls))
|
|
|
|
|
self.assertEqual(res.no_warn, no_warn)
|
|
|
|
|
|
|
|
|
|
def test_unknown_formater(self):
|
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
@ -200,3 +214,7 @@ class FormatersTestCase(unittest.TestCase):
|
|
|
|
|
inst.show_problems_for_all_files(inp),
|
|
|
|
|
ret
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# TODO : test max level
|
|
|
|
|
# TODO : test junit
|
|
|
|
|