-
Notifications
You must be signed in to change notification settings - Fork 23.7k
/
test_tests_as_filters_warning.py
35 lines (28 loc) · 1.27 KB
/
test_tests_as_filters_warning.py
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
from ansible.template import Templar, display
from units.mock.loader import DictDataLoader
from jinja2.filters import FILTERS
from os.path import isabs
def test_tests_as_filters_warning(mocker):
fake_loader = DictDataLoader({
"/path/to/my_file.txt": "foo\n",
})
templar = Templar(loader=fake_loader, variables={})
filters = templar._get_filters(templar.environment.filters)
mocker.patch.object(display, 'deprecated')
# Call successful test, ensure the message is correct
filters['successful']({})
display.deprecated.assert_called_once_with(
'Using tests as filters is deprecated. Instead of using `result|successful` instead use `result is successful`', version='2.9'
)
# Call success test, ensure the message is correct
display.deprecated.reset_mock()
filters['success']({})
display.deprecated.assert_called_once_with(
'Using tests as filters is deprecated. Instead of using `result|success` instead use `result is success`', version='2.9'
)
# Call bool filter, ensure no deprecation message was displayed
display.deprecated.reset_mock()
filters['bool'](True)
assert display.deprecated.call_count == 0
# Ensure custom test does not override builtin filter
assert filters.get('abs') != isabs