From 05f02371cedd449b6d1d95a4f4a7f99085830549 Mon Sep 17 00:00:00 2001 From: jctanner Date: Thu, 10 Nov 2016 17:06:14 -0500 Subject: [PATCH] Add a check for type() instead of isinstance() (#18439) --- test/sanity/validate-modules/README.rst | 1 + .../test_validate_modules_regex.py | 65 +++++++++++++++++++ test/sanity/validate-modules/validate-modules | 10 +++ 3 files changed, 76 insertions(+) create mode 100644 test/sanity/validate-modules/test_validate_modules_regex.py diff --git a/test/sanity/validate-modules/README.rst b/test/sanity/validate-modules/README.rst index 5da1d298320..1c39c5b9cc5 100644 --- a/test/sanity/validate-modules/README.rst +++ b/test/sanity/validate-modules/README.rst @@ -55,6 +55,7 @@ Errors #. New arguments have the correct ``version_added`` #. Modules should not import requests, instead use ``ansible.module_utils.urls`` #. Missing ``RETURN`` for new modules +#. Use of ``type()`` for type comparison instead of ``isinstance()`` Warnings ^^^^^^^^ diff --git a/test/sanity/validate-modules/test_validate_modules_regex.py b/test/sanity/validate-modules/test_validate_modules_regex.py new file mode 100644 index 00000000000..95b502e048b --- /dev/null +++ b/test/sanity/validate-modules/test_validate_modules_regex.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python + +# This is a standalone test for the regex inside validate-modules +# It is not suitable to add to the make tests target because the +# file under test is outside the test's sys.path AND has a hyphen +# in the name making it unimportable. +# +# To execute this by hand: +# 1) cd +# 2) source hacking/env-setup +# 3) PYTHONPATH=./lib nosetests -d -w test -v --nocapture sanity/validate-modules + +import os +import re +from ansible.compat.tests import unittest + +#TYPE_REGEX = re.compile(r'.*\stype\(.*') +#TYPE_REGEX = re.compile(r'.*(if|or)\stype\(.*') +#TYPE_REGEX = re.compile(r'.*(if|or)(\s+.*|\s+)type\(.*') +#TYPE_REGEX = re.compile(r'.*(if|or)(\s+.*|\s+)type\(.*') +#TYPE_REGEX = re.compile(r'.*(if|\sor)(\s+.*|\s+)type\(.*') +#TYPE_REGEX = re.compile(r'.*(if|\sor)(\s+.*|\s+)(?