Skip to content
Snippets Groups Projects
Commit 6d520fef authored by James Graham's avatar James Graham
Browse files

Skip test_map_only if MDTraj is not present

Remove unimplemented prewhile condition in Progress
parent 8964d1d0
Branches
No related tags found
No related merge requests found
......@@ -210,23 +210,18 @@ class Progress:
Display a progress bar during the main loop of a program.
"""
def __init__(self, maxits, length=20, prewhile=None, postwhile=None, quiet=False):
def __init__(self, maxits, length=20, dowhile=None, quiet=False):
"""
Return progress bar instance to handle printing of a progress bar within loops.
:param maxits: Expected number of iterations
:param length: Length of progress bar in characters
:param prewhile: Function to check before each iteration, stops if False
:param postwhile: Function to check after each iteration, stops if False
:param dowhile: Function to call after each iteration, stops if False
:param quiet: Skip printing of progress bar - for testing
"""
if prewhile is not None:
raise NotImplementedError("Prewhile conditions are not yet implemented")
self._maxits = maxits
self._length = length
self._prewhile = prewhile
self._postwhile = postwhile
self._dowhile = dowhile
self._quiet = quiet
self._its = 0
self._start_time = time.clock()
......@@ -236,14 +231,14 @@ class Progress:
def __next__(self):
"""
Allow iteration over Progress while testing prewhile and postwhile conditions.
Allow iteration over Progress while testing dowhile condition.
Will catch Ctrl-C and return control as if the iterator has been fully consumed.
:return: Iteration number
"""
try:
if self._postwhile is not None and self._its > 0 and not self._postwhile():
if self._dowhile is not None and self._its > 0 and not self._dowhile():
self._stop()
except KeyboardInterrupt:
......@@ -263,9 +258,7 @@ class Progress:
"""
Iterate through self until stopped by maximum iterations or False condition.
"""
# collections.deque(self, maxlen=0)
for _ in self:
pass
collections.deque(self, maxlen=0)
return self._its
@property
......
......@@ -51,7 +51,7 @@ def main(args, config):
numframes = frame.numframes - args.begin if args.end == -1 else args.end - args.begin
logger.info("Beginning analysis of {0} frames".format(numframes))
Progress(numframes, postwhile=main_loop, quiet=args.quiet).run()
Progress(numframes, dowhile=main_loop, quiet=args.quiet).run()
if args.bnd:
if args.map:
......@@ -94,5 +94,5 @@ def map_only(args, config):
numframes = frame.numframes - args.begin if args.end == -1 else args.end - args.begin
logger.info("Beginning analysis of {0} frames".format(numframes))
Progress(numframes, postwhile=main_loop, quiet=args.quiet).run()
Progress(numframes, dowhile=main_loop, quiet=args.quiet).run()
......@@ -10,16 +10,9 @@ class UtilTest(unittest.TestCase):
sum += i
self.assertEqual(45, sum)
@unittest.expectedFailure
def test_progress_prewhile(self):
sum = 0
for i in Progress(20, prewhile=lambda: sum < 20, quiet=True):
sum += i
self.assertEqual(15, sum)
def test_progress_postwhile(self):
sum = 0
for i in Progress(20, postwhile=lambda: sum < 20, quiet=True):
for i in Progress(20, dowhile=lambda: sum < 20, quiet=True):
sum += i
self.assertEqual(21, sum)
......
......@@ -6,6 +6,12 @@ import numpy as np
from simpletraj.trajectory import XtcTrajectory
try:
import mdtraj
mdtraj_present = True
except ImportError:
mdtraj_present = False
from pycgtool.interface import Options
from pycgtool.pycgtool import main, map_only
......@@ -40,6 +46,7 @@ class PycgtoolTest(unittest.TestCase):
path = os.path.dirname(os.path.dirname(__file__))
self.assertEqual(0, subprocess.check_call([os.path.join(path, "pycgtool.py"), "-h"], stdout=subprocess.PIPE))
@unittest.skipIf(not mdtraj_present, "MDTRAJ not present")
def test_map_only(self):
map_only(Args("sugar"), self.config)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment