mirror of
https://github.com/adrienverge/yamllint.git
synced 2025-02-25 18:55:20 -06:00
tests: Increase test coverage
- Add a `temp_workspace` context manager to simplify writing new tests. - Add `# pragma: no cover` to unit test code paths used for skipping tests. These code paths are only covered when tests are skipped. That makes it impractical to reach full code coverage on the unit test code. Having full coverage of unit tests is helpful for identifying unused tests. - Test the `octal-values` rule with a custom tag. - Test the cli `-d` option with the `default` config. - Test support for the `XDG_CONFIG_HOME` env var. - Test warning message output. - Test support for `.yamllint.yml` config files. - Test support for `.yamllint.yaml` config files. - Test error handling of a rule with a non-enable|disable|dict value. - Test error handling of `ignore` with a non-pattern value. - Test error handling of a rule `ignore` with a non-pattern value. - Test error handling of `locale` with a non-string value. - Test error handling of `yaml-files` with a non-list value. - Test extending config containing `ignore`. - Test `LintProblem.__repr__` without a rule. - Test `LintProblem.__repr__` with a rule.
This commit is contained in:
@@ -13,7 +13,9 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import contextlib
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
@@ -68,3 +70,17 @@ def build_temp_workspace(files):
|
||||
f.write(content)
|
||||
|
||||
return tempdir
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def temp_workspace(files):
|
||||
"""Provide a temporary workspace that is automatically cleaned up."""
|
||||
backup_wd = os.getcwd()
|
||||
wd = build_temp_workspace(files)
|
||||
|
||||
try:
|
||||
os.chdir(wd)
|
||||
yield
|
||||
finally:
|
||||
os.chdir(backup_wd)
|
||||
shutil.rmtree(wd)
|
||||
|
||||
Reference in New Issue
Block a user