1
0

test_doc.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # -*- coding: utf-8 -*-
  2. '''
  3. tests.unit.doc_test
  4. ~~~~~~~~~~~~~~~~~~~~
  5. '''
  6. # Import Python libs
  7. from __future__ import absolute_import
  8. import os
  9. import re
  10. # Import Salt Testing libs
  11. from tests.support.paths import CODE_DIR
  12. from tests.support.unit import TestCase
  13. # Import Salt libs
  14. import salt.modules.cmdmod
  15. import salt.utils.platform
  16. class DocTestCase(TestCase):
  17. '''
  18. Unit test case for testing doc files and strings.
  19. '''
  20. def test_check_for_doc_inline_markup(self):
  21. '''
  22. We should not be using the ``:doc:`` inline markup option when
  23. cross-referencing locations. Use ``:ref:`` or ``:mod:`` instead.
  24. This test checks for reference to ``:doc:`` usage.
  25. See Issue #12788 for more information.
  26. https://github.com/saltstack/salt/issues/12788
  27. '''
  28. salt_dir = CODE_DIR
  29. if salt.utils.platform.is_windows():
  30. # No grep in Windows, use findstr
  31. # findstr in windows doesn't prepend 'Binary` to binary files, so
  32. # use the '/P' switch to skip files with unprintable characters
  33. cmd = 'findstr /C:":doc:" /S /P {0}\\*'.format(salt_dir)
  34. else:
  35. salt_dir += '/'
  36. cmd = 'grep -r :doc: ' + salt_dir
  37. grep_call = salt.modules.cmdmod.run_stdout(cmd=cmd).split(os.linesep)
  38. test_ret = {}
  39. for line in grep_call:
  40. # Skip any .pyc files that may be present
  41. if line.startswith('Binary'):
  42. continue
  43. # Only split on colons not followed by a '\' as is the case with
  44. # Windows Drives
  45. regex = re.compile(r':(?!\\)')
  46. key, val = regex.split(line, 1)
  47. # Don't test man pages, this file, the tox or nox virtualenv files,
  48. # the page that documents to not use ":doc:", the doc/conf.py file
  49. # or the artifacts directory on nox CI test runs
  50. if 'man' in key \
  51. or '.tox/' in key \
  52. or '.nox/' in key \
  53. or 'artifacts/' in key \
  54. or key.endswith('test_doc.py') \
  55. or key.endswith(os.sep.join(['doc', 'conf.py'])) \
  56. or key.endswith(os.sep.join(['conventions', 'documentation.rst'])) \
  57. or key.endswith(os.sep.join(['doc', 'topics', 'releases', '2016.11.2.rst'])) \
  58. or key.endswith(os.sep.join(['doc', 'topics', 'releases', '2016.11.3.rst'])) \
  59. or key.endswith(os.sep.join(['doc', 'topics', 'releases', '2016.3.5.rst'])):
  60. continue
  61. # Set up test return dict
  62. if test_ret.get(key) is None:
  63. test_ret[key] = [val.strip()]
  64. else:
  65. test_ret[key].append(val.strip())
  66. # Allow test results to show files with :doc: ref, rather than truncating
  67. self.maxDiff = None
  68. # test_ret should be empty, otherwise there are :doc: references present
  69. self.assertEqual(test_ret, {})