Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pycgtool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
James Graham
pycgtool
Commits
6d520fef
Commit
6d520fef
authored
Jul 6, 2016
by
James Graham
Browse files
Options
Downloads
Patches
Plain Diff
Skip test_map_only if MDTraj is not present
Remove unimplemented prewhile condition in Progress
parent
8964d1d0
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
pycgtool/interface.py
+6
-13
6 additions, 13 deletions
pycgtool/interface.py
pycgtool/pycgtool.py
+2
-2
2 additions, 2 deletions
pycgtool/pycgtool.py
test/test_interface.py
+1
-8
1 addition, 8 deletions
test/test_interface.py
test/test_pycgtool.py
+7
-0
7 additions, 0 deletions
test/test_pycgtool.py
with
16 additions
and
23 deletions
pycgtool/interface.py
+
6
−
13
View file @
6d520fef
...
...
@@ -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
,
post
while
=
None
,
quiet
=
False
):
def
__init__
(
self
,
maxits
,
length
=
20
,
do
while
=
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 post
while condition
s
.
Allow iteration over Progress while testing
do
while condition.
Will catch Ctrl-C and return control as if the iterator has been fully consumed.
:return: Iteration number
"""
try
:
if
self
.
_
post
while
is
not
None
and
self
.
_its
>
0
and
not
self
.
_
post
while
():
if
self
.
_
do
while
is
not
None
and
self
.
_its
>
0
and
not
self
.
_
do
while
():
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
...
...
This diff is collapsed.
Click to expand it.
pycgtool/pycgtool.py
+
2
−
2
View file @
6d520fef
...
...
@@ -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
,
post
while
=
main_loop
,
quiet
=
args
.
quiet
).
run
()
Progress
(
numframes
,
do
while
=
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
,
post
while
=
main_loop
,
quiet
=
args
.
quiet
).
run
()
Progress
(
numframes
,
do
while
=
main_loop
,
quiet
=
args
.
quiet
).
run
()
This diff is collapsed.
Click to expand it.
test/test_interface.py
+
1
−
8
View file @
6d520fef
...
...
@@ -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
,
post
while
=
lambda
:
sum
<
20
,
quiet
=
True
):
for
i
in
Progress
(
20
,
do
while
=
lambda
:
sum
<
20
,
quiet
=
True
):
sum
+=
i
self
.
assertEqual
(
21
,
sum
)
...
...
This diff is collapsed.
Click to expand it.
test/test_pycgtool.py
+
7
−
0
View file @
6d520fef
...
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment