Commit graph

47 commits

Author SHA1 Message Date
Matt Martz
b08e7daf46 Do not treat AnsibleUndefined as being unsafe (#65202)
* Do not treat AnsibleUndefined as being unsafe. Fixes #65198

* fix yaml formatting
2019-11-25 15:06:29 +01:00
Mads Jensen
0f491c0289 Replace TestCase.assertEquals with TestCase.assertEqual. 2019-11-11 10:24:21 -08:00
Mads Jensen
ecc8e51044 Remove empty overridden unittest.setUp and unittest.tearDown methods. 2019-11-05 09:12:11 -08:00
Christian Clauss
23c7bf6481 Fix access to exception using Python 3 scoping rules (#62268) 2019-09-17 13:28:37 -04:00
Andrey Klychkov
21863d48f3 unit tests: remove unused imports (#60462) 2019-08-13 19:21:43 +02:00
Andrey Klychkov
64e3cb0fa8 Unit tests: remove unused imports (#59812)
* Unit tests: remove unused imports

* Unit tests: remove unused imports, fix
2019-08-02 17:18:14 +02:00
Matt Martz
e32d60bbcd
Add back _contains_vars method as maybe_template (#58290)
* Add back _contains_vars method as maybe_template. Fixes #58282

* Remove template guard in a few places

* maybe_template sounds like it might template something, rename to is_possibly_template

* Add tests for is_possibly_template
2019-06-25 10:54:37 -05:00
Matt Martz
728fce0c44 Perf improvement for Templar.is_template (#57489)
* Faster is_template
2019-06-06 15:49:26 -04:00
Martin Krizek
34e9d6781b Templar: encapsulate _available_variables (#55435)
Ensure variables are reset between iterations
2019-05-20 11:49:54 -04:00
Matt Martz
9f83139dcb
Don't register tests as filters (#55332)
* Don't register tests as filters. Fixes #55319

* Remove tests for deprecated functionality

* Remove no-tests-as-filters sanity tests

* Remove docs too

* Revert "Remove docs too"

This reverts commit 7daf457a74.

* Make no-tests-as-filters doc an orphan
2019-04-16 14:10:14 -05:00
Martin Krizek
50d7483632
Native Jinja2: raise undefined error immediately (#52237)
Fixes #52158
2019-02-15 19:36:12 +01:00
Pilou
62c05033d6 templar: ensure that exceptions are handled, fix 'AttributeError' (#48792)
* templar: ensure that exceptions are handled

* Fix AttributeError: object has no attribute 'message'

'message' attribute is deprecated since Python 2.6 and not available
with Python 3.

Simple reproducer:

    - hosts: localhost
      vars:
        not_json: "{{ 'test str' | from_json }}"
      tasks:
        - command: "echo {{ not_json }}"
2018-11-29 09:56:23 -05:00
Matt Clay
3033fd96b0
Move unit test compat code out of lib/ansible/. (#46996)
* Move ansible.compat.tests to test/units/compat/.
* Fix unit test references to ansible.compat.tests.
* Move builtins compat to separate file.
* Fix classification of test/units/compat/ dir.
2018-10-12 20:01:14 -07:00
James Cassell
211aeebd0d remove unused templar._clean_data() (#42739) 2018-09-11 09:11:03 +02:00
Matt Martz
88509e75ad
Remove bare_deprecated functionality (#44517)
* Remove bare_deprecated functionality

* Change tests due to bare_deprecated removal
2018-08-23 11:31:16 -05:00
Victor Bocharsky
a30befa609 Remove duplicated "instead" word (#38800)
* Remove duplicated "instead" word

* Actually fix the message
2018-04-16 09:23:43 -04:00
Matt Martz
1f824bd620 Don't overwrite builtin jinja2 filters with tests (#37881)
* Don't overwrite builtin jinja2 filters with tests. Fixes #37856

* Fix tests and other callers of _get_filters
2018-03-26 12:06:00 -05:00
Matt Martz
4fe08441be Deprecate tests used as filters (#32361)
* Warn on tests used as filters

* Update docs, add aliases for tests that fit more gramatically with test syntax

* Fix rst formatting

* Add successful filter, alias of success

* Remove renamed_deprecation, it was overkill

* Make directory alias for is_dir

* Update tests to use proper jinja test syntax

* Update additional documentation, living outside of YAML files, to reflect proper jinja test syntax

* Add conversion script, porting guide updates, and changelog updates

* Update newly added uses of tests as filters

* No underscore variable

* Convert recent tests as filter changes to win_stat

* Fix some changes related to rebasing a few integration tests

* Make tests_as_filters_warning explicitly accept the name of the test, instead of inferring the name

* Add test for tests_as_filters_warning

* Update tests as filters in newly added/modified tests

* Address recent changes to several integration tests

* Address recent changes in cs_vpc
2017-11-27 17:58:08 -05:00
Matt Clay
e45c763b64 Fix invalid string escape sequences. 2017-11-21 10:03:34 -08:00
Zac Medico
501fc7a248 template: fix KeyError: 'undefined variable: 0 (#27972)
* template: fix KeyError: 'undefined variable: 0

For compatibility with the Context.get_all() implementation
in jinja 2.9, make AnsibleJ2Vars implement collections.Mapping.
Also, make AnsibleJ2Template.newcontext() handle dict type
for the 'vars' parameter.

See: d67f0fd4cc
Fixes: https://github.com/ansible/ansible/issues/20494

* add units/template/test_vars

* intg tests for jinja-2.9 issues like 20494

test cases here are based on
https://github.com/ansible/ansible/issues/20494#issue-202108318
2017-08-09 18:50:53 -04:00
Dag Wieers
4efec414e7 test/: PEP8 compliancy (#24803)
* test/: PEP8 compliancy

- Make PEP8 compliant

* Python3 chokes on casting int to bytes (#24952)

But if we tell the formatter that the var is a number, it works
2017-05-30 18:05:19 +01:00
Toshio Kuratomi
1c05ed7951 Fix circular import with unsafe_proxy, template, and vars
template/__init__.py imported unsafe_proxy from vars which caused
vars/__init__.py to load.  vars/__init__.py needed template/__init__.py
which caused issues.  Loading unsafe_proxy from another location fixes
that.
2017-04-28 15:35:30 -07:00
Brian Coca
4594bee65a keep unsafe .. unsafe (#23742)
* keep unsafe .. unsafe

fixes #23734, which was broken in previous fix that allowed non string types to be templated
use new 'is_template' function vs bastardizing others
refactored clean_data to allow for arbitrary data structures to clean
fixed/removed some tests

* deal with complex data for is_template

* typos
2017-04-21 16:07:38 -04:00
Toshio Kuratomi
2fff690caa Update module_utils.six to latest (#22855)
* Update module_utils.six to latest

We've been held back on the version of six we could use on the module
side to 1.4.x because of python-2.4 compatibility.  Now that our minimum
is Python-2.6, we can update to the latest version of six in
module_utils and get rid of the second copy in lib/ansible/compat.
2017-03-23 13:35:05 -07:00
Adrian Likins
df3e4cd7f4 Don't check for var._obj in template._clean_data (#20868)
* Don't check for var._obj in template._clean_data

AnsibleUnsafe or other unsafe vars used to have a
'_obj' slot but no longer do. This was causing attribute
errors if a object was 'unsafe' but not a string.

Add tests for AnsibleUnsafe, lookups, and AnsibleContext
2017-02-08 16:09:34 -05:00
Matt Clay
10d9318de7 PEP 8 indent cleanup. (#20800)
* PEP 8 E121 cleanup.

* PEP 8 E126 cleanup.

* PEP 8 E122 cleanup.
2017-01-29 07:28:53 +00:00
Matt Clay
95789f3949 PEP 8 whitespace cleanup. (#20783)
* PEP 8 E271 whitespace cleanup.
* PEP 8 W293 whitespace cleanup.
* Fix whitespace issue from recent PR.
2017-01-27 15:45:23 -08:00
Matt Clay
8c270ac75f Add empty-init code-smell script. (#18406)
Also removed boilerplate from otherwise empty __init__.py files
which should not contain any code (checked by empty-init script).
2016-11-07 15:02:13 -08:00
James Cammarata
1b54d3b6dc Merge branch 'threaded_receiver' into devel 2016-09-20 09:18:26 -05:00
James Cammarata
dfb1c0647e Revert "Move queuing tasks to a background thread"
This reverts commit b71957d6e6.
2016-09-15 17:00:06 -05:00
Matt Clay
16baef1f72 Do not use bare vars in integration tests. (#17599) 2016-09-15 17:41:54 -04:00
James Cammarata
b71957d6e6 Move queuing tasks to a background thread 2016-08-31 13:33:01 -05:00
James Cammarata
86de1429e5 Cleaning up FIXMEs 2015-10-22 16:03:50 -04:00
Brian Coca
b6d6c2e4db corrected all missing paths changes 2015-09-15 11:57:54 -04:00
Marius Gedminas
f91b28ef23 Fix safe_eval() of set literals
There was code to support set literals (on Python 2.7 and newer), but it
was buggy: SAFE_NODES.union() doesn't modify SAFE_NODES in place,
instead it returns a new set object that is then silently discarded.

I added a unit test and fixed the code.  I also changed the version
check to use sys.version_tuple instead of a string comparison, for
consistency with the subsequent Python 3.4 version check that I added in
the previous commit.
2015-09-11 09:41:05 +03:00
Toshio Kuratomi
e218bf8da9 Do not escape backslashes when processing a template file.
Fixes #12198
Fixes #12241
2015-09-03 17:45:17 -07:00
Toshio Kuratomi
1b64702b9a Fix templar unittests for change in preserve_trailing_newline parameter's default value 2015-09-02 11:58:01 -07:00
James Cammarata
45aac6a739 Adding unit tests for safe_eval 2015-09-02 14:12:06 -04:00
Toshio Kuratomi
9ecfc30f9a * Mark all strings as unicode -- shouldn't matter for this dataset but
ansible is passing unicode arond internally so we should test the same
  data.
* Add a zero length test for _count_newlines and fix the zero newlines
  test to have no newlines.
2015-09-02 09:43:42 -07:00
Toshio Kuratomi
417bf1c805 Unittest the _count_trailing_newlines function 2015-09-02 08:59:31 -07:00
Toshio Kuratomi
7f5080f64a Fix backslash escaping inside of jinja2 expressions
Fixes #11891
2015-08-31 13:17:26 -07:00
Brian Coca
43bf9c86d8 fixed typo 2015-08-16 13:15:23 -04:00
Brian Coca
d38bb4152d fixed test to match new exception class used 2015-08-16 10:35:09 -04:00
Brian Coca
e9cf67004b updated fail_on_undefined test to new function signatures 2015-06-11 13:45:04 -04:00
James Cammarata
398b1d3e60 Cleaning up template test syntax a bit 2015-05-17 01:13:22 -05:00
James Cammarata
9aa8676bdd More template unit tests for v2 2015-05-17 01:06:02 -05:00
James Cammarata
23cd3294d0 Starting to add v2 tests for template 2015-05-16 15:45:01 -05:00