From 18867847f43190df1b12f692f410d0f9e17cda82 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Tue, 6 Aug 2019 17:17:57 -0700 Subject: [PATCH] Split up "code smell" sanity tests. (#60174) * Relocate ansible-only sanity tests. * Get "code smell" sanity tests from multiple dirs. - `test/lib/ansible_test/_data/sanity/code-smell/` - General purpose tests used for both Ansible and Ansible Collections. - `test/sanity/code-smell/` - Tests specific to Ansible, will not be used for Ansible Collections. --- MANIFEST.in | 2 +- .../testing/sanity/update-bundled.rst | 2 +- .../_data/sanity/code-smell/ansible-only.txt | 9 -------- .../ansible_test/_internal/sanity/__init__.py | 22 ++++++++----------- .../sanity/code-smell/azure-requirements.json | 0 .../sanity/code-smell/azure-requirements.py | 0 .../_data => }/sanity/code-smell/botmeta.json | 0 .../_data => }/sanity/code-smell/botmeta.py | 0 .../sanity/code-smell/changelog.json | 0 .../_data => }/sanity/code-smell/changelog.py | 0 .../code-smell/configure-remoting-ps1.json | 0 .../code-smell/configure-remoting-ps1.py | 0 .../sanity/code-smell/deprecated-config.json | 0 .../sanity/code-smell/deprecated-config.py | 0 .../sanity/code-smell/docs-build.json | 0 .../sanity/code-smell/docs-build.py | 0 .../sanity/code-smell/package-data.json | 0 .../sanity/code-smell/package-data.py | 0 .../_data => }/sanity/code-smell/skip.txt | 0 .../sanity/code-smell/test-constraints.json | 0 .../sanity/code-smell/test-constraints.py | 0 .../sanity/code-smell/update-bundled.json | 0 .../sanity/code-smell/update-bundled.py | 2 +- 23 files changed, 12 insertions(+), 25 deletions(-) delete mode 100644 test/lib/ansible_test/_data/sanity/code-smell/ansible-only.txt rename test/{lib/ansible_test/_data => }/sanity/code-smell/azure-requirements.json (100%) rename test/{lib/ansible_test/_data => }/sanity/code-smell/azure-requirements.py (100%) rename test/{lib/ansible_test/_data => }/sanity/code-smell/botmeta.json (100%) rename test/{lib/ansible_test/_data => }/sanity/code-smell/botmeta.py (100%) rename test/{lib/ansible_test/_data => }/sanity/code-smell/changelog.json (100%) rename test/{lib/ansible_test/_data => }/sanity/code-smell/changelog.py (100%) rename test/{lib/ansible_test/_data => }/sanity/code-smell/configure-remoting-ps1.json (100%) rename test/{lib/ansible_test/_data => }/sanity/code-smell/configure-remoting-ps1.py (100%) rename test/{lib/ansible_test/_data => }/sanity/code-smell/deprecated-config.json (100%) rename test/{lib/ansible_test/_data => }/sanity/code-smell/deprecated-config.py (100%) rename test/{lib/ansible_test/_data => }/sanity/code-smell/docs-build.json (100%) rename test/{lib/ansible_test/_data => }/sanity/code-smell/docs-build.py (100%) rename test/{lib/ansible_test/_data => }/sanity/code-smell/package-data.json (100%) rename test/{lib/ansible_test/_data => }/sanity/code-smell/package-data.py (100%) rename test/{lib/ansible_test/_data => }/sanity/code-smell/skip.txt (100%) rename test/{lib/ansible_test/_data => }/sanity/code-smell/test-constraints.json (100%) rename test/{lib/ansible_test/_data => }/sanity/code-smell/test-constraints.py (100%) rename test/{lib/ansible_test/_data => }/sanity/code-smell/update-bundled.json (100%) rename test/{lib/ansible_test/_data => }/sanity/code-smell/update-bundled.py (98%) diff --git a/MANIFEST.in b/MANIFEST.in index b255249608e..137483fa0e1 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -23,6 +23,6 @@ include MANIFEST.in include changelogs/CHANGELOG*.rst include contrib/README.md recursive-include contrib/inventory * -exclude test/lib/ansible_test/_data/sanity/code-smell/botmeta.* +exclude test/sanity/code-smell/botmeta.* recursive-include hacking/build_library *.py include hacking/build-ansible.py diff --git a/docs/docsite/rst/dev_guide/testing/sanity/update-bundled.rst b/docs/docsite/rst/dev_guide/testing/sanity/update-bundled.rst index de255a01423..d8f19385b35 100644 --- a/docs/docsite/rst/dev_guide/testing/sanity/update-bundled.rst +++ b/docs/docsite/rst/dev_guide/testing/sanity/update-bundled.rst @@ -15,7 +15,7 @@ This test can error in the following ways: added, this error should go away. * A file has a _BUNDLED_METADATA variable but the file isn't specified in - :file:`test/lib/ansible_test/_data/sanity/code-smell/update-bundled.py`. This typically happens when a new bundled + :file:`test/sanity/code-smell/update-bundled.py`. This typically happens when a new bundled library is added. Add the file to the `get_bundled_libs()` function in the `update-bundled.py` test script to solve this error. diff --git a/test/lib/ansible_test/_data/sanity/code-smell/ansible-only.txt b/test/lib/ansible_test/_data/sanity/code-smell/ansible-only.txt deleted file mode 100644 index 14c45f07994..00000000000 --- a/test/lib/ansible_test/_data/sanity/code-smell/ansible-only.txt +++ /dev/null @@ -1,9 +0,0 @@ -azure-requirements.py -botmeta.py -changelog.py -configure-remoting-ps1.py -deprecated-config.py -docs-build.py -test-constraints.py -update-bundled.py -package-data.py diff --git a/test/lib/ansible_test/_internal/sanity/__init__.py b/test/lib/ansible_test/_internal/sanity/__init__.py index 310208e969b..4dcde04f07d 100644 --- a/test/lib/ansible_test/_internal/sanity/__init__.py +++ b/test/lib/ansible_test/_internal/sanity/__init__.py @@ -209,21 +209,17 @@ def command_sanity(args): raise ApplicationError(message) -def collect_code_smell_tests(): - """ - :rtype: tuple[SanityFunc] - """ - skip_file = os.path.join(SANITY_ROOT, 'code-smell', 'skip.txt') - ansible_only_file = os.path.join(SANITY_ROOT, 'code-smell', 'ansible-only.txt') - - skip_tests = read_lines_without_comments(skip_file, remove_blank_lines=True, optional=True) - - if not data_context().content.is_ansible: - skip_tests += read_lines_without_comments(ansible_only_file, remove_blank_lines=True) - +def collect_code_smell_tests(): # type: () -> t.Tuple[SanityFunc, ...] + """Return a tuple of available code smell sanity tests.""" paths = glob.glob(os.path.join(SANITY_ROOT, 'code-smell', '*.py')) - paths = sorted(p for p in paths if os.access(p, os.X_OK) and os.path.isfile(p) and os.path.basename(p) not in skip_tests) + if data_context().content.is_ansible: + # include Ansible specific code-smell tests which are not configured to be skipped + ansible_code_smell_root = os.path.join(data_context().content.root, 'test', 'sanity', 'code-smell') + skip_tests = read_lines_without_comments(os.path.join(ansible_code_smell_root, 'skip.txt'), remove_blank_lines=True, optional=True) + paths.extend(path for path in glob.glob(os.path.join(ansible_code_smell_root, '*.py')) if os.path.basename(path) not in skip_tests) + + paths = sorted(p for p in paths if os.access(p, os.X_OK) and os.path.isfile(p)) tests = tuple(SanityCodeSmellTest(p) for p in paths) return tests diff --git a/test/lib/ansible_test/_data/sanity/code-smell/azure-requirements.json b/test/sanity/code-smell/azure-requirements.json similarity index 100% rename from test/lib/ansible_test/_data/sanity/code-smell/azure-requirements.json rename to test/sanity/code-smell/azure-requirements.json diff --git a/test/lib/ansible_test/_data/sanity/code-smell/azure-requirements.py b/test/sanity/code-smell/azure-requirements.py similarity index 100% rename from test/lib/ansible_test/_data/sanity/code-smell/azure-requirements.py rename to test/sanity/code-smell/azure-requirements.py diff --git a/test/lib/ansible_test/_data/sanity/code-smell/botmeta.json b/test/sanity/code-smell/botmeta.json similarity index 100% rename from test/lib/ansible_test/_data/sanity/code-smell/botmeta.json rename to test/sanity/code-smell/botmeta.json diff --git a/test/lib/ansible_test/_data/sanity/code-smell/botmeta.py b/test/sanity/code-smell/botmeta.py similarity index 100% rename from test/lib/ansible_test/_data/sanity/code-smell/botmeta.py rename to test/sanity/code-smell/botmeta.py diff --git a/test/lib/ansible_test/_data/sanity/code-smell/changelog.json b/test/sanity/code-smell/changelog.json similarity index 100% rename from test/lib/ansible_test/_data/sanity/code-smell/changelog.json rename to test/sanity/code-smell/changelog.json diff --git a/test/lib/ansible_test/_data/sanity/code-smell/changelog.py b/test/sanity/code-smell/changelog.py similarity index 100% rename from test/lib/ansible_test/_data/sanity/code-smell/changelog.py rename to test/sanity/code-smell/changelog.py diff --git a/test/lib/ansible_test/_data/sanity/code-smell/configure-remoting-ps1.json b/test/sanity/code-smell/configure-remoting-ps1.json similarity index 100% rename from test/lib/ansible_test/_data/sanity/code-smell/configure-remoting-ps1.json rename to test/sanity/code-smell/configure-remoting-ps1.json diff --git a/test/lib/ansible_test/_data/sanity/code-smell/configure-remoting-ps1.py b/test/sanity/code-smell/configure-remoting-ps1.py similarity index 100% rename from test/lib/ansible_test/_data/sanity/code-smell/configure-remoting-ps1.py rename to test/sanity/code-smell/configure-remoting-ps1.py diff --git a/test/lib/ansible_test/_data/sanity/code-smell/deprecated-config.json b/test/sanity/code-smell/deprecated-config.json similarity index 100% rename from test/lib/ansible_test/_data/sanity/code-smell/deprecated-config.json rename to test/sanity/code-smell/deprecated-config.json diff --git a/test/lib/ansible_test/_data/sanity/code-smell/deprecated-config.py b/test/sanity/code-smell/deprecated-config.py similarity index 100% rename from test/lib/ansible_test/_data/sanity/code-smell/deprecated-config.py rename to test/sanity/code-smell/deprecated-config.py diff --git a/test/lib/ansible_test/_data/sanity/code-smell/docs-build.json b/test/sanity/code-smell/docs-build.json similarity index 100% rename from test/lib/ansible_test/_data/sanity/code-smell/docs-build.json rename to test/sanity/code-smell/docs-build.json diff --git a/test/lib/ansible_test/_data/sanity/code-smell/docs-build.py b/test/sanity/code-smell/docs-build.py similarity index 100% rename from test/lib/ansible_test/_data/sanity/code-smell/docs-build.py rename to test/sanity/code-smell/docs-build.py diff --git a/test/lib/ansible_test/_data/sanity/code-smell/package-data.json b/test/sanity/code-smell/package-data.json similarity index 100% rename from test/lib/ansible_test/_data/sanity/code-smell/package-data.json rename to test/sanity/code-smell/package-data.json diff --git a/test/lib/ansible_test/_data/sanity/code-smell/package-data.py b/test/sanity/code-smell/package-data.py similarity index 100% rename from test/lib/ansible_test/_data/sanity/code-smell/package-data.py rename to test/sanity/code-smell/package-data.py diff --git a/test/lib/ansible_test/_data/sanity/code-smell/skip.txt b/test/sanity/code-smell/skip.txt similarity index 100% rename from test/lib/ansible_test/_data/sanity/code-smell/skip.txt rename to test/sanity/code-smell/skip.txt diff --git a/test/lib/ansible_test/_data/sanity/code-smell/test-constraints.json b/test/sanity/code-smell/test-constraints.json similarity index 100% rename from test/lib/ansible_test/_data/sanity/code-smell/test-constraints.json rename to test/sanity/code-smell/test-constraints.json diff --git a/test/lib/ansible_test/_data/sanity/code-smell/test-constraints.py b/test/sanity/code-smell/test-constraints.py similarity index 100% rename from test/lib/ansible_test/_data/sanity/code-smell/test-constraints.py rename to test/sanity/code-smell/test-constraints.py diff --git a/test/lib/ansible_test/_data/sanity/code-smell/update-bundled.json b/test/sanity/code-smell/update-bundled.json similarity index 100% rename from test/lib/ansible_test/_data/sanity/code-smell/update-bundled.json rename to test/sanity/code-smell/update-bundled.json diff --git a/test/lib/ansible_test/_data/sanity/code-smell/update-bundled.py b/test/sanity/code-smell/update-bundled.py similarity index 98% rename from test/lib/ansible_test/_data/sanity/code-smell/update-bundled.py rename to test/sanity/code-smell/update-bundled.py index 3720e2f08bd..121e225f396 100755 --- a/test/lib/ansible_test/_data/sanity/code-smell/update-bundled.py +++ b/test/sanity/code-smell/update-bundled.py @@ -132,7 +132,7 @@ def main(): for filename in files_with_bundled_metadata.difference(bundled_libs): print('{0}: ERROR: File contains _BUNDLED_METADATA but needs to be added to' - ' test/lib/ansible_test/_data/sanity/code-smell/update-bundled.py'.format(filename)) + ' test/sanity/code-smell/update-bundled.py'.format(filename)) for filename in bundled_libs: try: