-
Notifications
You must be signed in to change notification settings - Fork 23.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix tests as filters #4 #33930
Fix tests as filters #4 #33930
Conversation
I forgot, I'll need to add docs for the code smell test |
dd95835
to
5ff8d00
Compare
shipit |
|
||
Jinja tests are used for comparisons, whereas filters are used for data manipulation, and have different applications in jinja. This change is to help differentiate the concepts for a better understanding of jinja, and where each can be appropriately used. | ||
|
||
As of Ansible 2.5 using an Ansible provided jinja test with filter syntax, will display a deprecation error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary comma.
Sanity Tests » no-tests-as-filters | ||
================================== | ||
|
||
Using Ansible provided jinja tests as filters will be removed in Ansible 2.9. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Jinja2
instead of jinja
here and in following sentences.
|
||
FILTER_RE = re.compile(r'((.+?)\s*([\w \.\'"]+)(\s*)\|(\s*)(\w+))') | ||
|
||
all_matches = defaultdict(list) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put the test body in a main
function called with the standard if __name__ == '__main__'
conditional.
It's not really an issue now, but if we start running import tests on code smell tests we'll want that.
|
||
if all_matches: | ||
print('Use of Ansible provided Jinja tests as filters is deprecated.') | ||
print('Please update to use `is` syntax such as `result is failed`') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should probably be at the end of the sentence.
all_matches[path].append(match[0]) | ||
|
||
if all_matches: | ||
print('Use of Ansible provided Jinja tests as filters is deprecated.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Jinja2
instead of Jinja
.
@mattclay feedback addressed |
|
||
Prior to Ansible 2.5, Jinja2 tests included within Ansible were most often used as filters. The large difference in use is that filters are referenced as ``variable | filter_name`` where as Jinja2 tests are refereced as ``variable is test_name``. | ||
|
||
Jinja tests are used for comparisons, whereas filters are used for data manipulation, and have different applications in Jinja2. This change is to help differentiate the concepts for a better understanding of Jinja2, and where each can be appropriately used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more Jinja
to Jinja2
fix here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gah. Thanks.
5e65ce3
to
0b8b1ca
Compare
@mattclay addressed |
SUMMARY
Address recent changes to tests to fix jinja tests as filters
Following on #32361 this PR fixes tests as filters syntax to use proper is test syntax in newly modified files.
Additionally, the PR adds a code smell test to check for tests as filters syntax.
ISSUE TYPE
COMPONENT NAME
tests
ANSIBLE VERSION
ADDITIONAL INFORMATION