2012-08-28 09:03:11 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2012-12-11 10:23:37 +00:00
|
|
|
'''
|
|
|
|
:codeauthor: :email:`Pedro Algarvio (pedro@algarvio.me)`
|
2013-09-16 16:24:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
tests.unit.utils.runtime_whitespace_regex_test
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2012-12-11 10:23:37 +00:00
|
|
|
'''
|
2012-08-28 09:03:11 +00:00
|
|
|
|
2012-12-11 10:23:37 +00:00
|
|
|
# Import python libs
|
2014-11-21 19:05:13 +00:00
|
|
|
from __future__ import absolute_import
|
2012-08-28 09:03:11 +00:00
|
|
|
import re
|
|
|
|
|
2013-06-24 22:53:59 +00:00
|
|
|
# Import Salt Testing libs
|
|
|
|
from salttesting import TestCase
|
2013-06-27 13:17:32 +00:00
|
|
|
from salttesting.helpers import ensure_in_syspath
|
|
|
|
ensure_in_syspath('../../')
|
|
|
|
|
|
|
|
# Import salt libs
|
|
|
|
from salt.utils import build_whitespace_split_regex
|
2012-12-11 10:23:37 +00:00
|
|
|
|
2013-06-24 22:53:59 +00:00
|
|
|
DOUBLE_TXT = '''\
|
2012-08-28 09:03:11 +00:00
|
|
|
# set variable identifying the chroot you work in (used in the prompt below)
|
|
|
|
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
|
|
|
|
debian_chroot=$(cat /etc/debian_chroot)
|
|
|
|
fi
|
2013-06-24 22:53:59 +00:00
|
|
|
'''
|
2012-08-28 09:03:11 +00:00
|
|
|
|
2013-06-24 22:53:59 +00:00
|
|
|
SINGLE_TXT = '''\
|
2012-08-28 09:03:11 +00:00
|
|
|
# set variable identifying the chroot you work in (used in the prompt below)
|
|
|
|
if [ -z '$debian_chroot' ] && [ -r /etc/debian_chroot ]; then
|
|
|
|
debian_chroot=$(cat /etc/debian_chroot)
|
|
|
|
fi
|
2013-06-24 22:53:59 +00:00
|
|
|
'''
|
2012-08-28 09:03:11 +00:00
|
|
|
|
2013-06-24 22:53:59 +00:00
|
|
|
SINGLE_DOUBLE_TXT = '''\
|
2012-08-28 09:03:11 +00:00
|
|
|
# set variable identifying the chroot you work in (used in the prompt below)
|
|
|
|
if [ -z '$debian_chroot' ] && [ -r /etc/debian_chroot ]; then
|
|
|
|
debian_chroot=$(cat /etc/debian_chroot)
|
|
|
|
fi
|
|
|
|
|
|
|
|
# set variable identifying the chroot you work in (used in the prompt below)
|
|
|
|
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
|
|
|
|
debian_chroot=$(cat /etc/debian_chroot)
|
|
|
|
fi
|
2013-06-24 22:53:59 +00:00
|
|
|
'''
|
2012-08-28 09:03:11 +00:00
|
|
|
|
2013-06-24 22:53:59 +00:00
|
|
|
SINGLE_DOUBLE_SAME_LINE_TXT = '''\
|
2012-10-12 10:45:27 +00:00
|
|
|
# set variable identifying the chroot you work in (used in the prompt below)
|
|
|
|
if [ -z '$debian_chroot' ] && [ -r "/etc/debian_chroot" ]; then
|
|
|
|
debian_chroot=$(cat /etc/debian_chroot)
|
|
|
|
fi
|
2013-06-24 22:53:59 +00:00
|
|
|
'''
|
2012-10-12 10:45:27 +00:00
|
|
|
|
2013-06-24 22:53:59 +00:00
|
|
|
MATCH = '''\
|
2012-08-28 09:03:11 +00:00
|
|
|
# set variable identifying the chroot you work in (used in the prompt below)
|
|
|
|
if [ -z '$debian_chroot' ] && [ -r /etc/debian_chroot ]; then
|
|
|
|
debian_chroot=$(cat /etc/debian_chroot)
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# set variable identifying the chroot you work in (used in the prompt below)
|
|
|
|
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
|
|
|
|
debian_chroot=$(cat /etc/debian_chroot)
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# set variable identifying the chroot you work in (used in the prompt below)
|
|
|
|
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
|
|
|
|
debian_chroot=$(cat /etc/debian_chroot)
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# set variable identifying the chroot you work in (used in the prompt below)
|
|
|
|
if [ -z '$debian_chroot' ] && [ -r /etc/debian_chroot ]; then
|
|
|
|
debian_chroot=$(cat /etc/debian_chroot)
|
|
|
|
fi
|
2012-10-12 10:45:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
# set variable identifying the chroot you work in (used in the prompt below)
|
|
|
|
if [ -z '$debian_chroot' ] && [ -r "/etc/debian_chroot" ]; then
|
|
|
|
debian_chroot=$(cat /etc/debian_chroot)
|
|
|
|
fi
|
2013-06-24 22:53:59 +00:00
|
|
|
'''
|
2012-08-28 09:03:11 +00:00
|
|
|
|
2012-10-12 10:45:27 +00:00
|
|
|
|
2012-08-28 09:03:11 +00:00
|
|
|
class TestRuntimeWhitespaceRegex(TestCase):
|
|
|
|
|
|
|
|
def test_single_quotes(self):
|
2013-05-15 10:48:08 +00:00
|
|
|
regex = build_whitespace_split_regex(SINGLE_TXT)
|
2012-08-28 09:03:11 +00:00
|
|
|
self.assertTrue(re.search(regex, MATCH))
|
|
|
|
|
|
|
|
def test_double_quotes(self):
|
2013-05-15 10:48:08 +00:00
|
|
|
regex = build_whitespace_split_regex(DOUBLE_TXT)
|
2012-08-28 09:03:11 +00:00
|
|
|
self.assertTrue(re.search(regex, MATCH))
|
|
|
|
|
|
|
|
def test_single_and_double_quotes(self):
|
2013-05-15 10:48:08 +00:00
|
|
|
regex = build_whitespace_split_regex(SINGLE_DOUBLE_TXT)
|
2012-08-28 09:03:11 +00:00
|
|
|
self.assertTrue(re.search(regex, MATCH))
|
|
|
|
|
2012-10-12 10:45:27 +00:00
|
|
|
def test_issue_2227(self):
|
2013-05-15 10:48:08 +00:00
|
|
|
regex = build_whitespace_split_regex(SINGLE_DOUBLE_SAME_LINE_TXT)
|
2012-10-12 10:45:27 +00:00
|
|
|
self.assertTrue(re.search(regex, MATCH))
|
|
|
|
|
|
|
|
|
2013-06-24 22:53:59 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
from integration import run_tests
|
|
|
|
run_tests(TestRuntimeWhitespaceRegex, needs_daemon=False)
|