PageRenderTime 53ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/xsphinx/run.py

https://gitlab.com/mbukatov/pylatest
Python | 109 lines | 44 code | 12 blank | 53 comment | 11 complexity | 423e7eac889960bccc265df1e9d451da MD5 | raw file
  1. # -*- coding: utf-8 -*-
  2. """
  3. Sphinx unit test driver module, copied without modifications (with exception of
  4. this docstring and copying notice) from ``tests/run.py`` file of Sphinx
  5. project, commit 139e09d12023a255b206c1158487d215217be920.
  6. Done as a workaround for: https://github.com/sphinx-doc/sphinx/issues/3458
  7. """
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. # This file incorporates work covered by the following copyright and
  22. # permission notice:
  23. #
  24. # Copyright (c) 2007-2017 by the Sphinx team (see AUTHORS file).
  25. # All rights reserved.
  26. #
  27. # Redistribution and use in source and binary forms, with or without
  28. # modification, are permitted provided that the following conditions are
  29. # met:
  30. #
  31. # * Redistributions of source code must retain the above copyright
  32. # notice, this list of conditions and the following disclaimer.
  33. #
  34. # * Redistributions in binary form must reproduce the above copyright
  35. # notice, this list of conditions and the following disclaimer in the
  36. # documentation and/or other materials provided with the distribution.
  37. #
  38. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  39. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  40. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  41. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  42. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  43. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  44. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  45. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  46. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  47. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  48. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  49. from __future__ import print_function
  50. import os
  51. import sys
  52. import warnings
  53. import traceback
  54. from path import path
  55. testroot = os.path.dirname(__file__) or '.'
  56. sys.path.insert(0, os.path.abspath(os.path.join(testroot, os.path.pardir)))
  57. # filter warnings of test dependencies
  58. warnings.filterwarnings('ignore', category=DeprecationWarning, module='site') # virtualenv
  59. warnings.filterwarnings('ignore', category=ImportWarning, module='backports')
  60. warnings.filterwarnings('ignore', category=ImportWarning, module='pkgutil')
  61. warnings.filterwarnings('ignore', category=ImportWarning, module='pytest_cov')
  62. warnings.filterwarnings('ignore', category=PendingDeprecationWarning, module=r'_pytest\..*')
  63. # check dependencies before testing
  64. print('Checking dependencies...')
  65. for modname in ('pytest', 'mock', 'six', 'docutils', 'jinja2', 'pygments',
  66. 'snowballstemmer', 'babel', 'html5lib'):
  67. try:
  68. __import__(modname)
  69. except ImportError as err:
  70. if modname == 'mock' and sys.version_info[0] == 3:
  71. continue
  72. traceback.print_exc()
  73. print('The %r package is needed to run the Sphinx test suite.' % modname)
  74. sys.exit(1)
  75. # find a temp dir for testing and clean it up now
  76. os.environ['SPHINX_TEST_TEMPDIR'] = \
  77. os.path.abspath(os.path.join(testroot, 'build')) \
  78. if 'SPHINX_TEST_TEMPDIR' not in os.environ \
  79. else os.path.abspath(os.environ['SPHINX_TEST_TEMPDIR'])
  80. tempdir = path(os.environ['SPHINX_TEST_TEMPDIR'])
  81. print('Temporary files will be placed in %s.' % tempdir)
  82. if tempdir.exists():
  83. tempdir.rmtree()
  84. tempdir.makedirs()
  85. print('Running Sphinx test suite (with Python %s)...' % sys.version.split()[0])
  86. sys.stdout.flush()
  87. # exclude 'root' and 'roots' dirs for pytest test collector
  88. ignore_paths = [
  89. os.path.relpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), sub))
  90. for sub in ('root', 'roots')
  91. ]
  92. args = sys.argv[1:]
  93. for ignore_path in ignore_paths:
  94. args.extend(['--ignore', ignore_path])
  95. import pytest # NOQA
  96. sys.exit(pytest.main(args))