Commit Graph

40 Commits (18feeb51a88e221bbfaaaaf4d466d5b3330e429d)

Author SHA1 Message Date
Matt Martz 728fce0c44 Perf improvement for Templar.is_template (#57489)
* Faster is_template
7 years ago
Martin Krizek 34e9d6781b Templar: encapsulate _available_variables (#55435)
Ensure variables are reset between iterations
7 years ago
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
7 years ago
Martin Krizek 50d7483632
Native Jinja2: raise undefined error immediately (#52237)
Fixes #52158
7 years ago
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 }}"
7 years ago
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.
7 years ago
James Cassell 211aeebd0d remove unused templar._clean_data() (#42739) 7 years ago
Matt Martz 88509e75ad
Remove bare_deprecated functionality (#44517)
* Remove bare_deprecated functionality

* Change tests due to bare_deprecated removal
7 years ago
Victor Bocharsky a30befa609 Remove duplicated "instead" word (#38800)
* Remove duplicated "instead" word

* Actually fix the message
8 years ago
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
8 years ago
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
8 years ago
Matt Clay e45c763b64 Fix invalid string escape sequences. 8 years ago
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
8 years ago
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
9 years ago
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.
9 years ago
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
9 years ago
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.
9 years ago
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
9 years ago
Matt Clay 10d9318de7 PEP 8 indent cleanup. (#20800)
* PEP 8 E121 cleanup.

* PEP 8 E126 cleanup.

* PEP 8 E122 cleanup.
9 years ago
Matt Clay 95789f3949 PEP 8 whitespace cleanup. (#20783)
* PEP 8 E271 whitespace cleanup.
* PEP 8 W293 whitespace cleanup.
* Fix whitespace issue from recent PR.
9 years ago
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).
9 years ago
James Cammarata 1b54d3b6dc Merge branch 'threaded_receiver' into devel 9 years ago
James Cammarata dfb1c0647e Revert "Move queuing tasks to a background thread"
This reverts commit b71957d6e6.
9 years ago
Matt Clay 16baef1f72 Do not use bare vars in integration tests. (#17599) 9 years ago
James Cammarata b71957d6e6 Move queuing tasks to a background thread 9 years ago
James Cammarata 86de1429e5 Cleaning up FIXMEs 10 years ago
Brian Coca b6d6c2e4db corrected all missing paths changes 10 years ago
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.
10 years ago
Toshio Kuratomi e218bf8da9 Do not escape backslashes when processing a template file.
Fixes #12198
Fixes #12241
10 years ago
Toshio Kuratomi 1b64702b9a Fix templar unittests for change in preserve_trailing_newline parameter's default value 10 years ago
James Cammarata 45aac6a739 Adding unit tests for safe_eval 10 years ago
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.
10 years ago
Toshio Kuratomi 417bf1c805 Unittest the _count_trailing_newlines function 10 years ago
Toshio Kuratomi 7f5080f64a Fix backslash escaping inside of jinja2 expressions
Fixes #11891
10 years ago
Brian Coca 43bf9c86d8 fixed typo 10 years ago
Brian Coca d38bb4152d fixed test to match new exception class used 10 years ago
Brian Coca e9cf67004b updated fail_on_undefined test to new function signatures 11 years ago
James Cammarata 398b1d3e60 Cleaning up template test syntax a bit 11 years ago
James Cammarata 9aa8676bdd More template unit tests for v2 11 years ago
James Cammarata 23cd3294d0 Starting to add v2 tests for template 11 years ago