Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
skoudoro committed Feb 21, 2019
1 parent 9050b8e commit 3e4db82
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 25 deletions.
55 changes: 33 additions & 22 deletions docs/source/ext/apigen.py
@@ -1,5 +1,5 @@
"""
Attempt to generate templates for module reference with Sphinx
Attempt to generate templates for module reference with Sphinx.
To include extension modules, first identify them as valid in the
``_uri2path`` method, then handle them in the ``_parse_module_with_import``
Expand All @@ -15,6 +15,7 @@
This is a modified version of a script originally shipped with the PyMVPA
project, then adapted for use first in NIPY and then in skimage. PyMVPA
is an MIT-licensed project.
"""

# Stdlib imports
Expand All @@ -31,8 +32,8 @@


class ApiDocWriter(object):
''' Class for automatic detection and parsing of API docs
to Sphinx-parsable reST format'''
"""Class for automatic detection and parsing of API docs
to Sphinx-parsable reST format."""

# only separating first two levels
rst_section_levels = ['*', '=', '-', '~', '^']
Expand All @@ -45,7 +46,7 @@ def __init__(self,
object_skip_patterns=None,
other_defines=True
):
''' Initialize package for parsing
r"""Initialize package for parsing.
Parameters
----------
Expand Down Expand Up @@ -75,7 +76,8 @@ def __init__(self,
other_defines : {True, False}, optional
Whether to include classes and functions that are imported in a
particular module but not defined there.
'''
"""
if package_skip_patterns is None:
package_skip_patterns = ['\\.tests$']
if module_skip_patterns is None:
Expand All @@ -95,7 +97,7 @@ def get_package_name(self):
return self._package_name

def set_package_name(self, package_name):
''' Set package_name
"""Set package_name.
>>> docwriter = ApiDocWriter('sphinx')
>>> import sphinx
Expand All @@ -105,7 +107,8 @@ def set_package_name(self, package_name):
>>> import docutils
>>> docwriter.root_path == docutils.__path__[0]
True
'''
"""
# It's also possible to imagine caching the module parsing here
self._package_name = package_name
root_module = self._import(package_name)
Expand All @@ -117,7 +120,7 @@ def set_package_name(self, package_name):

@staticmethod
def _import(name):
''' Import namespace package '''
"""Import namespace package."""
mod = __import__(name)
components = name.split('.')
for comp in components[1:]:
Expand All @@ -126,22 +129,24 @@ def _import(name):

@staticmethod
def _get_object_name(line):
''' Get second token in line
"""Get second token in line.
>>> docwriter = ApiDocWriter('sphinx')
>>> docwriter._get_object_name(" def func(): ")
'func'
>>> docwriter._get_object_name(" class Klass(object): ")
'Klass'
>>> docwriter._get_object_name(" class Klass: ")
'Klass'
'''
"""
name = line.split()[1].split('(')[0].strip()
# in case we have classes which are not derived from object
# ie. old style classes
return name.rstrip(':')

def _uri2path(self, uri):
''' Convert uri to absolute filepath
"""Convert uri to absolute filepath.
Parameters
----------
Expand All @@ -167,7 +172,7 @@ def _uri2path(self, uri):
True
>>> docwriter._uri2path('sphinx.does_not_exist')
'''
"""
if uri == self.package_name:
return os.path.join(self.root_path, '__init__.py')
path = uri.replace(self.package_name + '.', '')
Expand All @@ -183,15 +188,15 @@ def _uri2path(self, uri):
return path

def _path2uri(self, dirpath):
''' Convert directory path to uri '''
"""Convert directory path to uri."""
package_dir = self.package_name.replace('.', os.path.sep)
relpath = dirpath.replace(self.root_path, package_dir)
if relpath.startswith(os.path.sep):
relpath = relpath[1:]
return relpath.replace(os.path.sep, '.')

def _parse_module(self, uri):
''' Parse module defined in *uri* '''
"""Parse module defined in *uri*."""
filename = self._uri2path(uri)
if filename is None:
print(filename, 'erk')
Expand All @@ -218,6 +223,7 @@ def _parse_module_with_import(self, uri):
A list of (public) function names in the module.
classes : list of str
A list of (public) class names in the module.
"""
mod = import_module(uri)
patterns = "(?:{0})".format("|".join(self.object_skip_patterns))
Expand Down Expand Up @@ -251,7 +257,7 @@ def _parse_module_with_import(self, uri):
return functions, classes

def _parse_lines(self, linesource):
''' Parse lines of text for functions and classes '''
"""Parse lines of text for functions and classes."""
functions = []
classes = []
for line in linesource:
Expand All @@ -272,7 +278,7 @@ def _parse_lines(self, linesource):
return functions, classes

def generate_api_doc(self, uri):
'''Make autodoc documentation template string for a module
"""Make autodoc documentation template string for a module.
Parameters
----------
Expand All @@ -285,7 +291,8 @@ def generate_api_doc(self, uri):
Module name, table of contents.
body : string
Function and class docstrings.
'''
"""
# get the names of all classes and functions
functions, classes = self._parse_module_with_import(uri)
if not len(functions) and not len(classes) and DEBUG:
Expand Down Expand Up @@ -335,7 +342,7 @@ def generate_api_doc(self, uri):
return head, body

def _survives_exclude(self, matchstr, match_type):
''' Returns True if *matchstr* does not match patterns
r"""Return True if *matchstr* does not match patterns.
``self.package_name`` removed from front of string if present
Expand All @@ -354,7 +361,8 @@ def _survives_exclude(self, matchstr, match_type):
>>> dw.module_skip_patterns.append('^\\.badmod$')
>>> dw._survives_exclude('sphinx.badmod', 'module')
False
'''
"""
if match_type == 'module':
patterns = self.module_skip_patterns
elif match_type == 'package':
Expand All @@ -377,7 +385,7 @@ def _survives_exclude(self, matchstr, match_type):
return True

def discover_modules(self):
''' Return module sequence discovered from ``self.package_name``
r"""Return module sequence discovered from ``self.package_name``.
Parameters
Expand All @@ -399,7 +407,8 @@ def discover_modules(self):
>>> 'sphinx.util' in dw.discover_modules()
False
>>>
'''
"""
modules = [self.package_name]
# raw directory parsing
for dirpath, dirnames, filenames in os.walk(self.root_path):
Expand Down Expand Up @@ -476,6 +485,7 @@ def write_api_docs(self, outdir):
Notes
-----
Sets self.written_modules to list of written modules
"""
if not os.path.exists(outdir):
os.mkdir(outdir)
Expand All @@ -484,7 +494,7 @@ def write_api_docs(self, outdir):
self.write_modules_api(modules, outdir)

def write_index(self, outdir, froot='gen', relative_to=None):
"""Make a reST API index file from written files
"""Make a reST API index file from written files.
Parameters
----------
Expand All @@ -500,6 +510,7 @@ def write_index(self, outdir, froot='gen', relative_to=None):
component of the written file path will be removed from
outdir, in the generated index. Default is None, meaning,
leave path as it is.
"""
if self.written_modules is None:
raise ValueError('No modules written')
Expand Down
15 changes: 14 additions & 1 deletion fury/tests/test_ui.py
Expand Up @@ -93,6 +93,15 @@ def _setup(self):
def _set_position(self, coords):
self.actor.SetPosition(*coords)

def _get_size(self):
return

def _get_actors(self):
return self.actor

def _add_to_scene(self, _scene):
return

# Can be instantiated.
SimplestUI()

Expand Down Expand Up @@ -178,7 +187,8 @@ def test_ui_disk_2d():
arr = window.snapshot(show_manager.scene, size=window_size, offscreen=True)
report = window.analyze_snapshot(arr, colors=colors)
npt.assert_equal(report.objects, 1)
npt.assert_equal(report.colors_found, True)
# Should be False because of the offscreen
npt.assert_equal(report.colors_found, [False])

# Test visibility off.
disk.set_visibility(False)
Expand Down Expand Up @@ -1086,3 +1096,6 @@ def timer_callback(_obj, _event):

if len(sys.argv) <= 1 or sys.argv[1] == "test_grid_ui":
test_grid_ui(interactive=False)

if len(sys.argv) <= 1 or sys.argv[1] == "test_ui_disk_2d":
test_ui_disk_2d()
5 changes: 3 additions & 2 deletions fury/ui.py
Expand Up @@ -188,6 +188,7 @@ def _set_position(self, _coords):
def size(self):
return np.asarray(self._get_size(), dtype=int)

@abc.abstractmethod
def _get_size(self):
msg = "Subclasses of UI must implement property `size`."
raise NotImplementedError(msg)
Expand Down Expand Up @@ -1968,7 +1969,7 @@ def track_click_callback(self, i_ren, _vtkactor, _slider):
i_ren.force_render()
i_ren.event.abort() # Stop propagating the event.

def handle_move_callback(self, i_ren, vtkactor, slider):
def handle_move_callback(self, i_ren, _vtkactor, _slider):
""" Actual handle movement.
Parameters
Expand All @@ -1984,7 +1985,7 @@ def handle_move_callback(self, i_ren, vtkactor, slider):
i_ren.force_render()
i_ren.event.abort() # Stop propagating the event.

def handle_release_callback(self, i_ren, vtkactor, slider):
def handle_release_callback(self, i_ren, _vtkactor, _slider):
""" Change color when handle is released.
Parameters
Expand Down

0 comments on commit 3e4db82

Please sign in to comment.