test: Base class test

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

@ -1,12 +1,12 @@
<?xml version="1.0" ?>
<coverage version="6.3.1" timestamp="1644492016536" lines-valid="3584" lines-covered="3505" line-rate="0.978" branches-covered="0" branches-valid="0" branch-rate="0" complexity="0">
<coverage version="6.3.1" timestamp="1644493279412" lines-valid="3607" lines-covered="3532" line-rate="0.9792" branches-covered="0" branches-valid="0" branch-rate="0" complexity="0">
<!-- Generated by coverage.py: https://coverage.readthedocs.io -->
<!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd -->
<sources>
<source>/home/n42/git/yamllint</source>
</sources>
<packages>
<package name="tests" line-rate="0.9952" branch-rate="0" complexity="0">
<package name="tests" line-rate="0.9953" branch-rate="0" complexity="0">
<classes>
<class name="__init__.py" filename="tests/__init__.py" complexity="0" line-rate="1" branch-rate="0">
<methods/>
@ -598,19 +598,42 @@
<line number="2" hits="1"/>
<line number="3" hits="1"/>
<line number="5" hits="1"/>
<line number="8" hits="1"/>
<line number="10" hits="1"/>
<line number="18" hits="1"/>
<line number="19" hits="1"/>
<line number="20" hits="1"/>
<line number="22" hits="1"/>
<line number="23" hits="1"/>
<line number="24" hits="1"/>
<line number="27" hits="1"/>
<line number="29" hits="1"/>
<line number="32" hits="1"/>
<line number="33" hits="1"/>
<line number="34" hits="1"/>
<line number="36" hits="1"/>
<line number="37" hits="1"/>
<line number="38" hits="1"/>
<line number="39" hits="1"/>
<line number="40" hits="1"/>
<line number="41" hits="1"/>
<line number="43" hits="1"/>
<line number="52" hits="1"/>
<line number="53" hits="1"/>
<line number="54" hits="1"/>
<line number="57" hits="1"/>
<line number="59" hits="1"/>
<line number="69" hits="1"/>
<line number="70" hits="1"/>
<line number="75" hits="1"/>
<line number="76" hits="1"/>
<line number="77" hits="1"/>
<line number="78" hits="1"/>
<line number="79" hits="1"/>
<line number="80" hits="1"/>
<line number="82" hits="1"/>
<line number="83" hits="1"/>
<line number="84" hits="1"/>
<line number="86" hits="1"/>
<line number="87" hits="1"/>
<line number="88" hits="1"/>
<line number="89" hits="1"/>
<line number="90" hits="1"/>
<line number="91" hits="1"/>
<line number="92" hits="1"/>
<line number="93" hits="1"/>
<line number="96" hits="1"/>
</lines>
</class>
<class name="test_linter.py" filename="tests/test_linter.py" complexity="0" line-rate="1" branch-rate="0">
@ -2454,7 +2477,7 @@
</class>
</classes>
</package>
<package name="yamllint" line-rate="0.8955" branch-rate="0" complexity="0">
<package name="yamllint" line-rate="0.9017" branch-rate="0" complexity="0">
<classes>
<class name="__init__.py" filename="yamllint/__init__.py" complexity="0" line-rate="1" branch-rate="0">
<methods/>
@ -2675,7 +2698,7 @@
<line number="213" hits="1"/>
</lines>
</class>
<class name="format.py" filename="yamllint/format.py" complexity="0" line-rate="0.7783" branch-rate="0">
<class name="format.py" filename="yamllint/format.py" complexity="0" line-rate="0.7972" branch-rate="0">
<methods/>
<lines>
<line number="2" hits="1"/>
@ -2718,15 +2741,15 @@
<line number="72" hits="1"/>
<line number="73" hits="1"/>
<line number="74" hits="1"/>
<line number="75" hits="0"/>
<line number="75" hits="1"/>
<line number="77" hits="1"/>
<line number="79" hits="1"/>
<line number="81" hits="1"/>
<line number="83" hits="0"/>
<line number="83" hits="1"/>
<line number="85" hits="1"/>
<line number="87" hits="0"/>
<line number="87" hits="1"/>
<line number="89" hits="1"/>
<line number="91" hits="0"/>
<line number="91" hits="1"/>
<line number="94" hits="1"/>
<line number="96" hits="1"/>
<line number="98" hits="1"/>

@ -2,7 +2,21 @@
import unittest
import string
from yamllint.format import escape_xml, severity_from_level
from yamllint.format import (
escape_xml,
severity_from_level,
Formater,
ParsableFormater,
GithubFormater,
ColoredFormater,
StandardFormater,
JSONFormater,
JunitFormater,
CodeclimateFormater
)
INPUT = []
class TextToXMLTestCase(unittest.TestCase):
@ -38,3 +52,42 @@ class CodeClimateSeverityTestCase(unittest.TestCase):
def test_specials_chars(self):
for inp, out in self.expected.items():
self.assertEqual(severity_from_level(inp), out)
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())
)
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)
def test_unknown_formater(self):
with self.assertRaises(ValueError):
Formater.get_formater("unknown", False)
def test_abstract_class(self):
inst = Formater(False)
with self.assertRaises(NotImplementedError):
inst.show_problems_for_all_files([])
with self.assertRaises(NotImplementedError):
inst.show_problems_for_file([], "a")
with self.assertRaises(NotImplementedError):
inst.show_problem(None, "a")

Loading…
Cancel
Save