Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds doctesting to the VCS test suite. #2151

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions testing/vcs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,95 @@ cdat_add_test(test_vcs_textextents
${BASELINE_DIR}/test_textextents.png
)

cdat_add_test(test_vcs_docstrings_boxfill
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/test_vcs_docstrings_boxfill.py
)

cdat_add_test(test_vcs_docstrings_Canvas
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/test_vcs_docstrings_Canvas.py
)

cdat_add_test(test_vcs_docstrings_colormap
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/test_vcs_docstrings_colormap.py
)

cdat_add_test(test_vcs_docstrings_displayplot
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/test_vcs_docstrings_Canvas.py
)

cdat_add_test(test_vcs_docstrings_fillarea
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/test_vcs_docstrings_fillarea.py
)

cdat_add_test(test_vcs_docstrings_isofill
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/test_vcs_docstrings_isofill.py
)

cdat_add_test(test_vcs_docstrings_isoline
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/test_vcs_docstrings_isoline.py
)

cdat_add_test(test_vcs_docstrings_line
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/test_vcs_docstrings_line.py
)

cdat_add_test(test_vcs_docstrings_manageElements
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/test_vcs_docstrings_manageElements.py
)

cdat_add_test(test_vcs_docstrings_marker
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/test_vcs_docstrings_marker.py
)

cdat_add_test(test_vcs_docstrings_meshfill
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/test_vcs_docstrings_meshfill.py
)

cdat_add_test(test_vcs_docstrings_projection
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/test_vcs_docstrings_projection.py
)

cdat_add_test(test_vcs_docstrings_queries
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/test_vcs_docstrings_queries.py
)

cdat_add_test(test_vcs_docstrings_taylordiagram
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/test_vcs_docstrings_taylordiagram.py
)

cdat_add_test(test_vcs_docstrings_template
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/test_vcs_docstrings_template.py
)

cdat_add_test(test_vcs_docstrings_textcombined
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/test_vcs_docstrings_textcombined.py
)

cdat_add_test(test_vcs_docstrings_textorientation
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/test_vcs_docstrings_textorientation.py
)

cdat_add_test(test_vcs_docstrings_texttable
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/test_vcs_docstrings_texttable.py
)

add_subdirectory(vtk_ui)
add_subdirectory(editors)
Expand Down
74 changes: 74 additions & 0 deletions testing/vcs/test_vcs_docstrings_Canvas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
from vcs.Canvas import Canvas
import vcs.utils
import glob
import os
import doctest


# for testing. remove when done
def find_obj(olist, name):
for obj in olist:
if obj.name == name:
return obj
print ("No object named " + name)


def cleanup():
"""Cleanup for the doctests. If some files aren't being deleted after testing, add their glob signature to the
patterns list.
"""
gb = glob.glob
patterns = ["example.*", "*.svg", "ex_*", "my*", "filename.*", "*.png", "deft_box.py", "*.mpeg"]
for pattern in patterns:
fnames = gb(pattern)
for name in fnames:
try:
os.remove(name)
except:
continue

f = doctest.DocTestFinder(exclude_empty=False)
runner = doctest.DocTestRunner(optionflags=doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE)
objs = f.find(Canvas) # list of objects with non-empty docstrings
failed = False
doctest_failed, no_doctest, no_docstring = [], [], []
if not os.path.isdir(vcs.sample_data):
vcs.download_sample_data_files() # we need to have these for any example that uses slabs made from sample data
for obj in objs:
if obj.name.split('.')[-1][0] == '_' or obj.docstring.find('.. pragma: skip-doctest') >= 0:
continue # this is private or has been explicitly ignored; skip it.
elif obj.lineno is None:
continue # this is not actually something that can be documented; most likely came from __slots__.
if obj.docstring is '':
no_docstring.append(obj.name) # store for empty docstring warning
continue
examples = obj.examples
if len(examples) > 0:
# There are examples. Do they run?
results = runner.run(obj)
if results.failed > 0:
failed = True
doctest_failed.append(obj.name)
else:
# All docstrings not specifically skipped and non-empty require a doctest
failed = True
no_doctest.append(obj.name)
cleanup() # testing done

# Report summary for cdash
if len(doctest_failed):
print "FAILING DOCTESTS:"
for name in doctest_failed:
print "\t" + name
if len(no_doctest):
print "MISSING DOCTESTS:"
for name in no_doctest:
print "\t" + name
if len(no_docstring):
print "NO DOCUMENTATION:"
for name in no_docstring:
print "\t" + name

assert failed is False
print ("All doctests passed for vcs.Canvas")

66 changes: 66 additions & 0 deletions testing/vcs/test_vcs_docstrings_boxfill.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from vcs.boxfill import Gfb
import vcs.utils
import glob
import os
import doctest


def cleanup():
"""Cleanup for the doctests. If some files aren't being deleted after testing, add their glob signature to the
patterns list.
"""
gb = glob.glob
patterns = ["example.*", "*.svg", "ex_*", "my*", "filename.*", "*.png", "deft_box.py", "*.mpeg", "new_box.json"]
for pattern in patterns:
fnames = gb(pattern)
for name in fnames:
try:
os.remove(name)
except:
continue

f = doctest.DocTestFinder(exclude_empty=False)
runner = doctest.DocTestRunner(optionflags=doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE)
objs = f.find(Gfb) # list of objects with non-empty docstrings
failed = False
doctest_failed, no_doctest, no_docstring = [], [], []
if not os.path.isdir(vcs.sample_data):
vcs.download_sample_data_files() # we need to have these for any example that uses slabs made from sample data
for obj in objs:
if obj.name.split('.')[-1][0] == '_' or obj.docstring.find('.. pragma: skip-doctest') >= 0:
continue # this is private or has been explicitly ignored; skip it.
if obj.lineno is None:
continue # this is not actually something that can be documented; most likely came from __slots__.
if obj.docstring is '':
no_docstring.append(obj.name) # store for empty docstring warning
continue
examples = obj.examples
if len(examples) > 0:
# There are examples. Do they run?
results = runner.run(obj)
if results.failed > 0:
failed = True
doctest_failed.append(obj.name)
else:
# All docstrings not specifically skipped and non-empty require a doctest
failed = True
no_doctest.append(obj.name)
cleanup() # testing done

# Report summary for cdash
if len(doctest_failed):
print "FAILING DOCTESTS:"
for name in doctest_failed:
print "\t" + name
if len(no_doctest):
print "MISSING DOCTESTS:"
for name in no_doctest:
print "\t" + name
if len(no_docstring):
print "NO DOCUMENTATION:"
for name in no_docstring:
print "\t" + name

assert failed is False
print ("All doctests passed for vcs.boxfill")

66 changes: 66 additions & 0 deletions testing/vcs/test_vcs_docstrings_colormap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from vcs.colormap import Cp
import vcs.utils
import glob
import os
import doctest


def cleanup():
"""Cleanup for the doctests. If some files aren't being deleted after testing, add their glob signature to the
patterns list.
"""
gb = glob.glob
patterns = ["example.*", "*.svg", "ex_*", "my*", "filename.*", "*.png", "deft_box.py", "*.mpeg"]
for pattern in patterns:
fnames = gb(pattern)
for name in fnames:
try:
os.remove(name)
except:
continue

f = doctest.DocTestFinder(exclude_empty=False)
runner = doctest.DocTestRunner(optionflags=doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE)
objs = f.find(Cp) # list of objects with non-empty docstrings
failed = False
doctest_failed, no_doctest, no_docstring = [], [], []
if not os.path.isdir(vcs.sample_data):
vcs.download_sample_data_files() # we need to have these for any example that uses slabs made from sample data
for obj in objs:
if obj.name.split('.')[-1][0] == '_' or obj.docstring.find('.. pragma: skip-doctest') >= 0:
continue # this is private or has been explicitly ignored; skip it.
if obj.lineno is None:
continue # this is not actually something that can be documented; most likely came from __slots__.
if obj.docstring is '':
no_docstring.append(obj.name) # store for empty docstring warning
continue
examples = obj.examples
if len(examples) > 0:
# There are examples. Do they run?
results = runner.run(obj)
if results.failed > 0:
failed = True
doctest_failed.append(obj.name)
else:
# All docstrings not specifically skipped and non-empty require a doctest
failed = True
no_doctest.append(obj.name)
cleanup() # testing done

# Report summary for cdash
if len(doctest_failed):
print "FAILING DOCTESTS:"
for name in doctest_failed:
print "\t" + name
if len(no_doctest):
print "MISSING DOCTESTS:"
for name in no_doctest:
print "\t" + name
if len(no_docstring):
print "NO DOCUMENTATION:"
for name in no_docstring:
print "\t" + name

assert failed is False
print ("All doctests passed for vcs.colormap")

66 changes: 66 additions & 0 deletions testing/vcs/test_vcs_docstrings_displayplot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from vcs.displayplot import Dp
import vcs.utils
import glob
import os
import doctest


def cleanup():
"""Cleanup for the doctests. If some files aren't being deleted after testing, add their glob signature to the
patterns list.
"""
gb = glob.glob
patterns = ["example.*", "*.svg", "ex_*", "my*", "filename.*", "*.png", "deft_box.py", "*.mpeg"]
for pattern in patterns:
fnames = gb(pattern)
for name in fnames:
try:
os.remove(name)
except:
continue

f = doctest.DocTestFinder(exclude_empty=False)
runner = doctest.DocTestRunner(optionflags=doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE)
objs = f.find(Dp) # list of objects with non-empty docstrings
failed = False
doctest_failed, no_doctest, no_docstring = [], [], []
if not os.path.isdir(vcs.sample_data):
vcs.download_sample_data_files() # we need to have these for any example that uses slabs made from sample data
for obj in objs:
if obj.name.split('.')[-1][0] == '_' or obj.docstring.find('.. pragma: skip-doctest') >= 0:
continue # this is private or has been explicitly ignored; skip it.
if obj.lineno is None:
continue # this is not actually something that can be documented; most likely came from __slots__.
if obj.docstring is '':
no_docstring.append(obj.name) # store for empty docstring warning
continue
examples = obj.examples
if len(examples) > 0:
# There are examples. Do they run?
results = runner.run(obj)
if results.failed > 0:
failed = True
doctest_failed.append(obj.name)
else:
# All docstrings not specifically skipped and non-empty require a doctest
failed = True
no_doctest.append(obj.name)
cleanup() # testing done

# Report summary for cdash
if len(doctest_failed):
print "FAILING DOCTESTS:"
for name in doctest_failed:
print "\t" + name
if len(no_doctest):
print "MISSING DOCTESTS:"
for name in no_doctest:
print "\t" + name
if len(no_docstring):
print "NO DOCUMENTATION:"
for name in no_docstring:
print "\t" + name

assert failed is False
print ("All doctests passed for vcs.displayplot")

Loading