/tests/unit/utils/runtime_whitespace_regex_test.py

https://gitlab.com/ricardo.hernandez/salt · Python · 108 lines · 81 code · 16 blank · 11 comment · 1 complexity · ab3ae2fa8e24a9495ac70a32cdeb3201 MD5 · raw file

  1. # -*- coding: utf-8 -*-
  2. '''
  3. :codeauthor: :email:`Pedro Algarvio (pedro@algarvio.me)`
  4. tests.unit.utils.runtime_whitespace_regex_test
  5. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6. '''
  7. # Import python libs
  8. from __future__ import absolute_import
  9. import re
  10. # Import Salt Testing libs
  11. from salttesting import TestCase
  12. from salttesting.helpers import ensure_in_syspath
  13. ensure_in_syspath('../../')
  14. # Import salt libs
  15. from salt.utils import build_whitespace_split_regex
  16. DOUBLE_TXT = '''\
  17. # set variable identifying the chroot you work in (used in the prompt below)
  18. if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
  19. debian_chroot=$(cat /etc/debian_chroot)
  20. fi
  21. '''
  22. SINGLE_TXT = '''\
  23. # set variable identifying the chroot you work in (used in the prompt below)
  24. if [ -z '$debian_chroot' ] && [ -r /etc/debian_chroot ]; then
  25. debian_chroot=$(cat /etc/debian_chroot)
  26. fi
  27. '''
  28. SINGLE_DOUBLE_TXT = '''\
  29. # set variable identifying the chroot you work in (used in the prompt below)
  30. if [ -z '$debian_chroot' ] && [ -r /etc/debian_chroot ]; then
  31. debian_chroot=$(cat /etc/debian_chroot)
  32. fi
  33. # set variable identifying the chroot you work in (used in the prompt below)
  34. if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
  35. debian_chroot=$(cat /etc/debian_chroot)
  36. fi
  37. '''
  38. SINGLE_DOUBLE_SAME_LINE_TXT = '''\
  39. # set variable identifying the chroot you work in (used in the prompt below)
  40. if [ -z '$debian_chroot' ] && [ -r "/etc/debian_chroot" ]; then
  41. debian_chroot=$(cat /etc/debian_chroot)
  42. fi
  43. '''
  44. MATCH = '''\
  45. # set variable identifying the chroot you work in (used in the prompt below)
  46. if [ -z '$debian_chroot' ] && [ -r /etc/debian_chroot ]; then
  47. debian_chroot=$(cat /etc/debian_chroot)
  48. fi
  49. # set variable identifying the chroot you work in (used in the prompt below)
  50. if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
  51. debian_chroot=$(cat /etc/debian_chroot)
  52. fi
  53. # set variable identifying the chroot you work in (used in the prompt below)
  54. if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
  55. debian_chroot=$(cat /etc/debian_chroot)
  56. fi
  57. # set variable identifying the chroot you work in (used in the prompt below)
  58. if [ -z '$debian_chroot' ] && [ -r /etc/debian_chroot ]; then
  59. debian_chroot=$(cat /etc/debian_chroot)
  60. fi
  61. # set variable identifying the chroot you work in (used in the prompt below)
  62. if [ -z '$debian_chroot' ] && [ -r "/etc/debian_chroot" ]; then
  63. debian_chroot=$(cat /etc/debian_chroot)
  64. fi
  65. '''
  66. class TestRuntimeWhitespaceRegex(TestCase):
  67. def test_single_quotes(self):
  68. regex = build_whitespace_split_regex(SINGLE_TXT)
  69. self.assertTrue(re.search(regex, MATCH))
  70. def test_double_quotes(self):
  71. regex = build_whitespace_split_regex(DOUBLE_TXT)
  72. self.assertTrue(re.search(regex, MATCH))
  73. def test_single_and_double_quotes(self):
  74. regex = build_whitespace_split_regex(SINGLE_DOUBLE_TXT)
  75. self.assertTrue(re.search(regex, MATCH))
  76. def test_issue_2227(self):
  77. regex = build_whitespace_split_regex(SINGLE_DOUBLE_SAME_LINE_TXT)
  78. self.assertTrue(re.search(regex, MATCH))
  79. if __name__ == '__main__':
  80. from integration import run_tests
  81. run_tests(TestRuntimeWhitespaceRegex, needs_daemon=False)