Skip to content

Commit

Permalink
Ensure old API still works
Browse files Browse the repository at this point in the history
Since user code might already exist we keep make sure the old API still
works as well.
  • Loading branch information
kain88-de committed Jul 8, 2016
1 parent c4b2f09 commit 3c5f09b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
17 changes: 11 additions & 6 deletions package/MDAnalysis/analysis/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,8 @@ def __init__(self, trajectory, start=None,
quiet : bool, optional
Turn of verbosity
"""
self._setup_frames(trajectory, start, stop, step)
interval = int(self.n_frames // 100)
if interval == 0:
interval = 1
self._pm = ProgressMeter(self.nframes if self.nframes else 1,
interval=interval, quiet=quiet)
self._quiet = quiet
self._setup_frames(trajectory, start, stop, step)

def _setup_frames(self, trajectory, start=None,
stop=None, step=None):
Expand All @@ -97,6 +92,16 @@ def _setup_frames(self, trajectory, start=None,
self.stop = stop
self.step = step
self.n_frames = len(range(start, stop, step))
interval = int(self.n_frames // 100)
if interval == 0:
interval = 1

# if _quiet doesn't exists because __init__ wasn't called set it to
# true
if not hasattr(self, '_quiet'):
self._quiet = True
self._pm = ProgressMeter(self.n_frames if self.n_frames else 1,
interval=interval, quiet=self._quiet)

def _single_frame(self):
"""Calculate data from a single frame of trajectory
Expand Down
11 changes: 11 additions & 0 deletions testsuite/MDAnalysisTests/analysis/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ def __init__(self, reader, **kwargs):
super(IncompleteAnalysis, self).__init__(reader, **kwargs)


class OldAPIAnalysis(AnalysisBase):
def __init__(self, reader, **kwargs):
self._setup_frames(reader, **kwargs)

def _single_frame(self):
pass


class TestAnalysisBase(object):
@dec.skipif(parser_not_found('DCD'),
'DCD parser not available. Are you using python 3?')
Expand Down Expand Up @@ -89,3 +97,6 @@ def test_quiet(self):
@raises(NotImplementedError)
def test_incomplete_defined_analysis(self):
IncompleteAnalysis(self.u.trajectory).run()

def test_old_api(self):
OldAPIAnalysis(self.u.trajectory).run()

0 comments on commit 3c5f09b

Please sign in to comment.