2008-06-05 03:58:43 -05:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
Sphinx unit test driver
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
This script runs the Sphinx unit test suite.
|
|
|
|
|
2016-01-14 15:54:04 -06:00
|
|
|
:copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
|
2009-01-03 04:57:07 -06:00
|
|
|
:license: BSD, see LICENSE for details.
|
2008-06-05 03:58:43 -05:00
|
|
|
"""
|
2014-01-19 04:17:10 -06:00
|
|
|
from __future__ import print_function
|
2008-06-05 03:58:43 -05:00
|
|
|
|
2014-09-21 10:17:02 -05:00
|
|
|
import os
|
2008-06-05 03:58:43 -05:00
|
|
|
import sys
|
2016-12-14 22:12:13 -06:00
|
|
|
import warnings
|
2014-09-21 10:17:02 -05:00
|
|
|
import traceback
|
|
|
|
|
|
|
|
from path import path
|
2017-01-03 07:24:00 -06:00
|
|
|
import pytest
|
2014-09-21 10:17:02 -05:00
|
|
|
|
|
|
|
testroot = os.path.dirname(__file__) or '.'
|
|
|
|
sys.path.insert(0, os.path.abspath(os.path.join(testroot, os.path.pardir)))
|
|
|
|
|
|
|
|
# check dependencies before testing
|
|
|
|
print('Checking dependencies...')
|
2017-01-03 07:24:00 -06:00
|
|
|
for modname in ('pytest', 'mock', 'six', 'docutils', 'jinja2', 'pygments',
|
2016-05-28 01:51:21 -05:00
|
|
|
'snowballstemmer', 'babel', 'html5lib'):
|
2014-09-21 10:17:02 -05:00
|
|
|
try:
|
|
|
|
__import__(modname)
|
|
|
|
except ImportError as err:
|
2014-09-21 10:32:52 -05:00
|
|
|
if modname == 'mock' and sys.version_info[0] == 3:
|
|
|
|
continue
|
2014-09-21 10:17:02 -05:00
|
|
|
traceback.print_exc()
|
|
|
|
print('The %r package is needed to run the Sphinx test suite.' % modname)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
# find a temp dir for testing and clean it up now
|
|
|
|
os.environ['SPHINX_TEST_TEMPDIR'] = \
|
|
|
|
os.path.abspath(os.path.join(testroot, 'build')) \
|
|
|
|
if 'SPHINX_TEST_TEMPDIR' not in os.environ \
|
|
|
|
else os.path.abspath(os.environ['SPHINX_TEST_TEMPDIR'])
|
|
|
|
tempdir = path(os.environ['SPHINX_TEST_TEMPDIR'])
|
|
|
|
print('Temporary files will be placed in %s.' % tempdir)
|
|
|
|
if tempdir.exists():
|
|
|
|
tempdir.rmtree()
|
|
|
|
tempdir.makedirs()
|
2011-04-12 17:54:14 -05:00
|
|
|
|
2014-11-06 02:12:51 -06:00
|
|
|
print('Running Sphinx test suite (with Python %s)...' % sys.version.split()[0])
|
2014-09-21 12:01:03 -05:00
|
|
|
sys.stdout.flush()
|
|
|
|
|
2016-12-14 22:12:13 -06:00
|
|
|
# filter warnings of test dependencies
|
|
|
|
warnings.filterwarnings('ignore', category=DeprecationWarning, module='site') # virtualenv
|
|
|
|
|
2017-01-03 07:24:00 -06:00
|
|
|
# exclude 'root' and 'roots' dirs for pytest test collector
|
|
|
|
ignore_paths = [
|
|
|
|
os.path.relpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), sub))
|
|
|
|
for sub in ('root', 'roots')
|
|
|
|
]
|
|
|
|
args = sys.argv[1:]
|
|
|
|
for path in ignore_paths:
|
|
|
|
args.extend(['--ignore', path])
|
|
|
|
|
|
|
|
sys.exit(pytest.main(args))
|