mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 17:50:20 +00:00
Fix test_doc on windows by using grep yay!
This commit is contained in:
parent
0ce086d13d
commit
759bccc202
1 changed files with 20 additions and 7 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue