summaryrefslogtreecommitdiffstats
path: root/test/TestBaseFormatter.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-14 20:04:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-14 20:04:50 +0000
commit782f8df6e41f29dce2db4970a3ad84aaeb7d8c5f (patch)
tree3a88a542cd8074743d251881131510157cfc510b /test/TestBaseFormatter.py
parentInitial commit. (diff)
downloadansible-lint-782f8df6e41f29dce2db4970a3ad84aaeb7d8c5f.tar.xz
ansible-lint-782f8df6e41f29dce2db4970a3ad84aaeb7d8c5f.zip
Adding upstream version 4.3.7.upstream/4.3.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/TestBaseFormatter.py')
-rw-r--r--test/TestBaseFormatter.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/test/TestBaseFormatter.py b/test/TestBaseFormatter.py
new file mode 100644
index 0000000..c6ba7fb
--- /dev/null
+++ b/test/TestBaseFormatter.py
@@ -0,0 +1,46 @@
+# -*- coding: utf-8; -*-
+from pathlib import Path
+
+import pytest
+
+from ansiblelint.formatters import BaseFormatter
+
+
+@pytest.mark.parametrize(('base_dir', 'relative_path'), (
+ (None, True),
+ ('/whatever', False),
+ (Path('/whatever'), False),
+))
+@pytest.mark.parametrize('path', ('/whatever/string', Path('/whatever/string')))
+def test_base_formatter_when_base_dir(base_dir, relative_path, path):
+ # Given
+ base_formatter = BaseFormatter(base_dir, relative_path)
+
+ # When
+ output_path = base_formatter._format_path(path)
+
+ # Then
+ assert isinstance(output_path, str)
+ assert base_formatter._base_dir is None or isinstance(base_formatter._base_dir, str)
+ assert output_path == str(path)
+
+
+@pytest.mark.parametrize('base_dir', (
+ Path('/whatever'),
+ '/whatever',
+))
+@pytest.mark.parametrize('path', ('/whatever/string', Path('/whatever/string')))
+def test_base_formatter_when_base_dir_is_given_and_relative_is_true(path, base_dir):
+ # Given
+ base_formatter = BaseFormatter(base_dir, True)
+
+ # When
+ output_path = base_formatter._format_path(path)
+
+ # Then
+ assert isinstance(output_path, str)
+ assert isinstance(base_formatter._base_dir, str)
+ assert output_path == Path(path).name
+
+
+# vim: et:sw=4:syntax=python:ts=4: