Fix test_doc on windows by using grep yay!

This commit is contained in:
Daniel A. Wozniak 2019-04-28 23:00:23 +00:00 committed by Pedro Algarvio
parent 0ce086d13d
commit 759bccc202
No known key found for this signature in database
GPG key ID: BB36BF6584A298FF

View file

@ -8,6 +8,7 @@
from __future__ import absolute_import
import os
import re
import logging
# Import Salt Testing libs
from tests.support.paths import CODE_DIR
@ -18,6 +19,9 @@ import salt.modules.cmdmod
import salt.utils.platform
log = logging.getLogger(__name__)
class DocTestCase(TestCase):
'''
Unit test case for testing doc files and strings.
@ -37,15 +41,20 @@ class DocTestCase(TestCase):
salt_dir = CODE_DIR
if salt.utils.platform.is_windows():
# No grep in Windows, use findstr
# findstr in windows doesn't prepend 'Binary` to binary files, so
# use the '/P' switch to skip files with unprintable characters
cmd = 'findstr /C:":doc:" /S /P {0}\\*'.format(salt_dir)
if salt.utils.path.which('bash'):
# Use grep from git-bash when it exists.
cmd = 'bash -c \'grep -r :doc: ./salt/'.format(salt_dir)
grep_call = salt.modules.cmdmod.run_stdout(cmd=cmd, cwd=salt_dir).split(os.linesep)
else:
# No grep in Windows, use findstr
# findstr in windows doesn't prepend 'Binary` to binary files, so
# use the '/P' switch to skip files with unprintable characters
cmd = 'findstr /C:":doc:" /S /P {0}\\*'.format(salt_dir)
grep_call = salt.modules.cmdmod.run_stdout(cmd=cmd).split(os.linesep)
else:
salt_dir += '/'
cmd = 'grep -r :doc: ' + salt_dir
grep_call = salt.modules.cmdmod.run_stdout(cmd=cmd).split(os.linesep)
grep_call = salt.modules.cmdmod.run_stdout(cmd=cmd).split(os.linesep)
test_ret = {}
for line in grep_call:
@ -56,7 +65,11 @@ class DocTestCase(TestCase):
# Only split on colons not followed by a '\' as is the case with
# Windows Drives
regex = re.compile(r':(?!\\)')
key, val = regex.split(line, 1)
try:
key, val = regex.split(line, 1)
except ValueError:
log.error("Could not split line: %s", line)
continue
# Don't test man pages, this file, the tox or nox virtualenv files,
# the page that documents to not use ":doc:", the doc/conf.py file