Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pystache_custom
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
pystache_custom
Commits
67d77628
Commit
67d77628
authored
Apr 20, 2012
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved code from load_tests() to new doctesting module.
parent
bd207abf
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
82 additions
and
60 deletions
+82
-60
pystache/tests/common.py
+1
-0
pystache/tests/doctesting.py
+78
-0
pystache/tests/test_doctests.py
+3
-60
No files found.
pystache/tests/common.py
View file @
67d77628
...
...
@@ -17,6 +17,7 @@ _TESTS_DIR = os.path.dirname(pystache.tests.__file__)
DATA_DIR
=
os
.
path
.
join
(
_TESTS_DIR
,
'data'
)
# i.e. 'pystache/tests/data'.
EXAMPLES_DIR
=
os
.
path
.
dirname
(
examples
.
__file__
)
# TODO: change SOURCE_DIR to PACKAGE_DIR.
SOURCE_DIR
=
os
.
path
.
dirname
(
pystache
.
__file__
)
PROJECT_DIR
=
os
.
path
.
join
(
SOURCE_DIR
,
'..'
)
SPEC_TEST_DIR
=
os
.
path
.
join
(
PROJECT_DIR
,
'ext'
,
'spec'
,
'specs'
)
...
...
pystache/tests/doctesting.py
0 → 100644
View file @
67d77628
# coding: utf-8
"""
Exposes a get_doctests() function for the project's test harness.
"""
import
os
import
pkgutil
import
doctest
import
traceback
from
pystache.tests.common
import
PROJECT_DIR
,
SOURCE_DIR
# The paths to text files (i.e. non-module files) containing doctests.
# Paths should be OS-specific and relative to the project directory.
TEXT_DOCTEST_PATHS
=
[
'README.rst'
]
def
get_module_doctests
():
"""
Return a list of TestSuite instances for all doctests in the pacakqge.
"""
suites
=
[]
# Since module_relative is False in our calls to DocFileSuite below,
# paths should be OS-specific. Moreover, we choose absolute paths
# so that the current working directory does not come into play.
# See the following for more info--
#
# http://docs.python.org/library/doctest.html#doctest.DocFileSuite
#
paths
=
[
os
.
path
.
join
(
PROJECT_DIR
,
path
)
for
path
in
TEXT_DOCTEST_PATHS
]
for
path
in
paths
:
suite
=
doctest
.
DocFileSuite
(
path
,
module_relative
=
False
)
suites
.
append
(
suite
)
modules
=
_get_module_doctests
(
SOURCE_DIR
)
for
module
in
modules
:
suite
=
doctest
.
DocTestSuite
(
module
)
suites
.
append
(
suite
)
return
suites
def
_get_module_doctests
(
package_dir
):
modules
=
[]
for
pkg
in
pkgutil
.
walk_packages
([
package_dir
]):
# The importer is a pkgutil.ImpImporter instance:
#
# http://docs.python.org/library/pkgutil.html#pkgutil.ImpImporter
#
importer
,
module_name
,
is_package
=
pkg
if
is_package
:
# Otherwise, we will get the following error when adding tests:
#
# ValueError: (<module 'tests' from '.../pystache/tests/__init__.pyc'>, 'has no tests')
#
continue
# The loader is a pkgutil.ImpLoader instance.
loader
=
importer
.
find_module
(
module_name
)
try
:
module
=
loader
.
load_module
(
module_name
)
except
ImportError
,
e
:
# In some situations, the test harness was swallowing and/or
# suppressing the display of the stack trace when errors
# occurred here. The following code makes errors occurring here
# easier to troubleshoot.
details
=
""
.
join
(
traceback
.
format_exception
(
*
sys
.
exc_info
()))
raise
ImportError
(
details
)
modules
.
append
(
module
)
return
modules
pystache/tests/test_doctests.py
View file @
67d77628
...
...
@@ -10,19 +10,7 @@ Creates unittest.TestSuite instances for the doctests in the project.
# http://docs.python.org/library/doctest.html#unittest-api
#
import
os
import
doctest
import
pkgutil
import
traceback
import
unittest
import
pystache
from
pystache.tests.common
import
PROJECT_DIR
,
SOURCE_DIR
# The paths to text files (i.e. non-module files) containing doctests.
# Paths should be OS-specific and relative to the project directory.
text_file_paths
=
[
'README.rst'
]
from
pystache.tests.doctesting
import
get_module_doctests
# The following load_tests() function implements unittests's load_tests
...
...
@@ -46,52 +34,7 @@ text_file_paths = ['README.rst']
# before version 2.7.
#
def
load_tests
(
loader
,
tests
,
ignore
):
# Since module_relative is False in our calls to DocFileSuite below,
# paths should be OS-specific. Moreover, we choose absolute paths
# so that the current working directory does not come into play.
# See the following for more info--
#
# http://docs.python.org/library/doctest.html#doctest.DocFileSuite
#
paths
=
[
os
.
path
.
join
(
PROJECT_DIR
,
path
)
for
path
in
text_file_paths
]
for
path
in
paths
:
suite
=
doctest
.
DocFileSuite
(
path
,
module_relative
=
False
)
tests
.
addTests
(
suite
)
modules
=
_get_module_doctests
()
for
module
in
modules
:
suite
=
doctest
.
DocTestSuite
(
module
)
tests
.
addTests
(
suite
)
suites
=
get_module_doctests
()
tests
.
addTests
(
suites
)
return
tests
def
_get_module_doctests
():
modules
=
[]
for
pkg
in
pkgutil
.
walk_packages
([
SOURCE_DIR
]):
# The importer is a pkgutil.ImpImporter instance:
#
# http://docs.python.org/library/pkgutil.html#pkgutil.ImpImporter
#
importer
,
module_name
,
is_package
=
pkg
if
is_package
:
# Otherwise, we will get the following error when adding tests:
#
# ValueError: (<module 'tests' from '.../pystache/tests/__init__.pyc'>, 'has no tests')
#
continue
# The loader is a pkgutil.ImpLoader instance.
loader
=
importer
.
find_module
(
module_name
)
try
:
module
=
loader
.
load_module
(
module_name
)
except
ImportError
,
e
:
# In some situations, the test harness was swallowing and/or
# suppressing the display of the stack trace when errors
# occurred here. The following code makes errors occurring here
# easier to troubleshoot.
details
=
""
.
join
(
traceback
.
format_exception
(
*
sys
.
exc_info
()))
raise
ImportError
(
details
)
modules
.
append
(
module
)
return
modules
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment