1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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:
|