ansible/test/units
Matt Clay 9e67953b2e
Fix collection loader and add unit tests. (#58701)
* Use `compile` before `eval` in collection loader.

This fixes two issues:

1. File names are available when tracing execution, such as with code coverage.
2. Future statements are not inherited from the collection loader.

* Add unit tests for collection loading.

These tests verify several things:

1. That unit tests can import code from collections when the collection loader is installed.
2. That tracing reports the correct file and line numbers (to support code coverage).
3. That collection code does not inherit __future__ statements from the collection loader.

* Update unit test handling of the collection loader.

Since the collection loader is installed simply by importing ansible.plugins.loader,
we may already have a collection loader installed when the test runs. This occurs if
any other tests are collected which use that import during collection. Until that code
is moved into an initialization function to avoid loading during import, the unit tests
will need to replace any existing collection loaders so that they reflect the desired
configuration.

* Insert into sys.modules before calling exec.

This is a requirement of PEP 302.

It will prevent recursion errors when importing the current module or using a relative import.

* Use the correct value for __package__ in modules.

This allows using relative imports in collections.

* Add warning about modifying code for trace test.

* Add test for relative import in collection.

* Add __init__.py to collection to satisfy pylint.

The relative-beyond-top-level rule in pylint may not be appropriate for collections.
However, until that rule is disabled for collections this will keep tests passing.
2019-07-09 17:31:33 -07:00
..
cli ansible-galaxy: add collection sub command (#57106) 2019-07-10 05:47:25 +10:00
compat Move unit test compat code out of lib/ansible/. (#46996) 2018-10-12 20:01:14 -07:00
config Fix encoding issues with file paths. (#50830) 2019-01-14 13:06:47 -08:00
contrib Fix vmware_inventory unit tests so they run. 2018-10-09 22:52:04 -07:00
errors Add better error when k=v syntax is used with YAML in tasks (#41754) 2018-12-04 12:32:02 -05:00
executor Support using importlib on py>=3 to avoid imp deprecation (#54883) 2019-04-25 10:28:18 -05:00
galaxy ansible-galaxy: add collection sub command (#57106) 2019-07-10 05:47:25 +10:00
inventory_test_data/group_vars Merge branch 'v2_final' into devel_switch_v2 2015-05-28 15:26:03 -05:00
mock Move unit test compat code out of lib/ansible/. (#46996) 2018-10-12 20:01:14 -07:00
module_utils Add unit tests for lenient_lowercase function (#58586) 2019-07-08 18:33:15 -04:00
modules New Fortinet's module for fortios_user_device (using new httpapi plugin) (#58291) 2019-07-09 15:53:36 +05:30
parsing Handle vaulted non-ascii characters for Python2 (#58503) 2019-06-28 13:23:15 -04:00
playbook role: Fix role's hash_params (#55263) 2019-07-08 09:25:59 -04:00
plugins Skip tests with unsatisfied deps (#55853) 2019-06-28 13:09:36 -07:00
regex Add toggle to control invalid character substitution in group names (#52748) 2019-03-06 11:49:40 -05:00
template Add back _contains_vars method as maybe_template (#58290) 2019-06-25 10:54:37 -05:00
utils Fix collection loader and add unit tests. (#58701) 2019-07-09 17:31:33 -07:00
vars Fix inventory cache interface (#50446) 2019-03-06 12:12:35 -06:00
__init__.py Add empty-init code-smell script. (#18406) 2016-11-07 15:02:13 -08:00
ansible.cfg Fix ansible-test config management. 2017-10-04 12:52:36 -07:00
conftest.py Update handling of the non_local test alias. 2019-03-22 16:05:24 -07:00
test_constants.py 1st part of ansible config, adds ansible-config to view/manage configs (#12797) 2017-06-14 11:08:34 -04:00
test_context.py Save the command line arguments into a global context 2019-01-03 18:12:23 -08:00