tests: use ddt to parametrize tests
This commit is contained in:
@@ -14,6 +14,7 @@ Pull Request Process
|
|||||||
.. code:: bash
|
.. code:: bash
|
||||||
|
|
||||||
pip install --user .
|
pip install --user .
|
||||||
|
pip install ddt
|
||||||
python -m unittest discover # all tests...
|
python -m unittest discover # all tests...
|
||||||
python -m unittest tests/rules/test_commas.py # or just some tests (faster)
|
python -m unittest tests/rules/test_commas.py # or just some tests (faster)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import unittest
|
import unittest
|
||||||
import string
|
import string
|
||||||
|
import ddt
|
||||||
|
|
||||||
from yamllint.format import (
|
from yamllint.format import (
|
||||||
escape_xml,
|
escape_xml,
|
||||||
@@ -90,15 +91,32 @@ class FormaterTestCase(unittest.TestCase):
|
|||||||
inst.show_problem(None, "a")
|
inst.show_problem(None, "a")
|
||||||
|
|
||||||
|
|
||||||
|
NONE = {}
|
||||||
|
NO_ERROR = {"file1.yml": []}
|
||||||
|
ONE_ERROR = {}
|
||||||
|
ONE_WARNING = {}
|
||||||
|
|
||||||
|
|
||||||
|
@ddt.ddt
|
||||||
class FormatersTestCase(unittest.TestCase):
|
class FormatersTestCase(unittest.TestCase):
|
||||||
|
|
||||||
args = [
|
@ddt.data(
|
||||||
(ParsableFormater(True), {"file1.yml": []}, ""),
|
(ParsableFormater(True), NONE, ""),
|
||||||
]
|
(GithubFormater(True), NONE, ""),
|
||||||
|
(ColoredFormater(True), NONE, ""),
|
||||||
def test_all_formaters(self):
|
(StandardFormater(True), NONE, ""),
|
||||||
for inst, inp, ret in self.args:
|
(JSONFormater(True), NONE, "[]\n"),
|
||||||
self.assertEqual(
|
(CodeclimateFormater(True), NONE, "[]\n"),
|
||||||
inst.show_problems_for_all_files(inp),
|
(ParsableFormater(True), NO_ERROR, ""),
|
||||||
ret
|
(GithubFormater(True), NO_ERROR, ""),
|
||||||
)
|
(ColoredFormater(True), NO_ERROR, ""),
|
||||||
|
(StandardFormater(True), NO_ERROR, ""),
|
||||||
|
(JSONFormater(True), NO_ERROR, "[]\n"),
|
||||||
|
(CodeclimateFormater(True), NO_ERROR, "[]\n"),
|
||||||
|
)
|
||||||
|
@ddt.unpack
|
||||||
|
def test_all_formaters(self, inst, inp, ret):
|
||||||
|
self.assertEqual(
|
||||||
|
inst.show_problems_for_all_files(inp),
|
||||||
|
ret
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user