Skip to content

Commit

Permalink
API: Added deprecation warning wrapper to pims imports
Browse files Browse the repository at this point in the history
  • Loading branch information
nkeim committed Mar 3, 2015
1 parent dcad1c1 commit 50696a8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
25 changes: 22 additions & 3 deletions trackpy/api.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import six
import warnings

# pims import is deprecated. We include it here for backwards
# compatibility, but there will be warnings.
import pims as _pims


def _deprecate_pims(call):
"""Wrap a pims callable with a warning that it is deprecated."""
def deprecated_pims_import(*args, **kw):
"""Class imported from pims package. Its presence in trackpy is deprecated."""
warnings.warn(('trackpy.{0} is being called, but "{0}" is really part of the '
'pims package. It will not be in future versions of trackpy. '
'Consider importing pims and calling pims.{0} instead.'
).format(call.__name__), UserWarning)
return call(*args, **kw)
return deprecated_pims_import


ImageSequence = _deprecate_pims(_pims.ImageSequence)
Video = _deprecate_pims(_pims.Video)
TiffStack = _deprecate_pims(_pims.TiffStack)

# Import all of pims top-level for convenience. But do it first so
# that trackpy names take precedence.
from pims import *

from .motion import *
from .plots import *
Expand Down
12 changes: 12 additions & 0 deletions trackpy/tests/test_misc.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import six
import os
import unittest
import warnings

import trackpy
import trackpy.diag

path, _ = os.path.split(os.path.abspath(__file__))

class DiagTests(unittest.TestCase):
def test_performance_report(self):
trackpy.diag.performance_report()

def test_dependencies(self):
trackpy.diag.dependencies()


class APITests(unittest.TestCase):
def test_pims_deprecation(self):
with warnings.catch_warnings(True) as w:
warnings.simplefilter('always')
_ = trackpy.ImageSequence(os.path.join(path, 'video/image_sequence/*.png'))
assert len(w) == 1

0 comments on commit 50696a8

Please sign in to comment.