Add function to get all of the test modules

This commit is contained in:
Erik Johnson 2018-08-13 14:43:55 -05:00
parent c5593bc843
commit c3dc8ec1d0
No known key found for this signature in database
GPG Key ID: 5E5583C437808F3F

View File

@ -14,11 +14,14 @@
# Import python libs
from __future__ import absolute_import
import os
import re
import sys
import stat
import logging
import tempfile
import salt.utils.path
log = logging.getLogger(__name__)
TESTS_DIR = os.path.dirname(os.path.dirname(os.path.normpath(os.path.abspath(__file__))))
@ -30,6 +33,7 @@ if sys.platform.startswith('win'):
CODE_DIR = os.path.dirname(TESTS_DIR)
if sys.platform.startswith('win'):
CODE_DIR = CODE_DIR.replace('\\', '\\\\')
UNIT_TEST_DIR = os.path.join(TESTS_DIR, 'unit')
INTEGRATION_TEST_DIR = os.path.join(TESTS_DIR, 'integration')
# Let's inject CODE_DIR so salt is importable if not there already
@ -99,6 +103,24 @@ SCRIPT_TEMPLATES = {
}
def test_mods():
'''
A generator which returns all of the test files
'''
test_re = re.compile(r'^test_.+\.py$')
for dirname in (UNIT_TEST_DIR, INTEGRATION_TEST_DIR):
test_type = os.path.basename(dirname)
for root, _, files in salt.utils.path.os_walk(dirname):
parent_mod = root[len(dirname):].lstrip(os.sep).replace(os.sep, '.')
for filename in files:
if test_re.match(filename):
mod_name = test_type
if parent_mod:
mod_name += '.' + parent_mod
mod_name += '.' + filename[:-3]
yield mod_name
class ScriptPathMixin(object):
def get_script_path(self, script_name):