Skip to content

Commit

Permalink
finalized fix of #556 (test failure due os.chdir/tempdir)
Browse files Browse the repository at this point in the history
- use tempdir.in_tempdir() in test_hole.py
- added Hai Nguyen to AUTHORS and sphinx/source/conf.py
  (for #558)
  • Loading branch information
orbeckst committed Dec 3, 2015
1 parent d424ccf commit f1345fa
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 41 deletions.
1 change: 1 addition & 0 deletions package/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Chronological list of authors
- Max Linke
- Gorman Stock
- Jonathan Barnoud
- Hai Nguyen

External code
-------------
Expand Down
9 changes: 5 additions & 4 deletions package/doc/sphinx/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ def __getattr__(cls, name):
Xavier Deupi, Jan Domański, David L. Dotson, Lennard van der
Feltz, Philip Fowler, Joseph Goose, Richard J. Gowers, Lukas
Grossar, Benjamin Hall, Joe Jordan, Max Linke, Jinju Lu, Robert
McGibbon, Alex Nesterenko, Manuel Nuno Melo, Caio S. Souza, Danny
Parton, Joshua L. Phillips, Tyler Reddy, Paul Rigor, Sean
L. Seyler, Andy Somogyi, Lukas Stelzl, Gorman Stock, Isaac
Virshup, Zhuyi Xue, Carlos Yáñez S., and Oliver Beckstein"""
McGibbon, Alex Nesterenko, Manuel Nuno Melo, Hai Nguyen,
Caio S. Souza, Danny Parton, Joshua L. Phillips, Tyler Reddy,
Paul Rigor, Sean L. Seyler, Andy Somogyi, Lukas Stelzl,
Gorman Stock, Isaac Virshup, Zhuyi Xue, Carlos Yáñez S.,
and Oliver Beckstein"""
project = u'MDAnalysis'
copyright = u'2005-2015, ' + authors

Expand Down
67 changes: 30 additions & 37 deletions testsuite/MDAnalysisTests/analysis/test_hole.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@

import MDAnalysis
import MDAnalysis.analysis.hole
from MDAnalysis.analysis.hole import HOLEtraj

from numpy.testing import TestCase, dec
import numpy as np
import nose
from nose.plugins.attrib import attr

import os
import errno
import tempfile
import shutil
import tempdir

from MDAnalysisTests.datafiles import PDB_HOLE, XTC_HOLE
from MDAnalysisTests import executable_not_found
Expand All @@ -45,11 +44,9 @@ def rlimits_missing():
class TestHoleModule(TestCase):
def setUp(self):
self.universe = MDAnalysis.Universe(PDB_HOLE, XTC_HOLE)
self.dir_name = tempfile.mkdtemp()
try:
# on Unix we can manipulate our limits: http://docs.python.org/2/library/resource.html
import resource

self.soft_max_open_files, self.hard_max_open_files = resource.getrlimit(resource.RLIMIT_NOFILE)
except ImportError:
pass
Expand All @@ -67,41 +64,38 @@ def test_hole_module_fd_closure(self):
try:
# Hasten failure by setting "ulimit -n 64" (can't go too low because of open modules etc...)
import resource

resource.setrlimit(resource.RLIMIT_NOFILE, (64, self.hard_max_open_files))
except ImportError:
raise NotImplementedError("Test cannot be run without the resource module.")
import errno
from MDAnalysis.analysis.hole import HOLEtraj

os.chdir(self.dir_name)
try:
# will need to have the 'hole' command available in the path
H = HOLEtraj(self.universe, cvect=[0, 1, 0], sample=20.0)
except OSError as err:
if err.errno == errno.ENOENT:
raise OSError(errno.ENOENT, "HOLE binary not found")
raise
finally:
self._restore_rlimits()

# pretty unlikely that the code will get through 2 rounds if the MDA
# issue 129 isn't fixed, although this depends on the file descriptor
# open limit for the machine in question
try:
for i in xrange(2):
# will typically get an OSError for too many files being open after
# about 2 seconds if issue 129 isn't resolved
H.run()
except OSError as err:
if err.errno == errno.EMFILE:
raise AssertionError("HOLEtraj does not close file descriptors (Issue 129)")
elif err.errno == errno.ENOENT:
raise OSError(errno.ENOENT, "HOLE binary not found")
raise
finally:
# make sure to restore open file limit !!
self._restore_rlimits()
with tempdir.in_tempdir():
try:
# will need to have the 'hole' command available in the path
H = HOLEtraj(self.universe, cvect=[0, 1, 0], sample=20.0)
except OSError as err:
if err.errno == errno.ENOENT:
raise OSError(errno.ENOENT, "HOLE binary not found")
raise
finally:
self._restore_rlimits()

# pretty unlikely that the code will get through 2 rounds if the MDA
# issue 129 isn't fixed, although this depends on the file descriptor
# open limit for the machine in question
try:
for i in xrange(2):
# will typically get an OSError for too many files being open after
# about 2 seconds if issue 129 isn't resolved
H.run()
except OSError as err:
if err.errno == errno.EMFILE:
raise AssertionError("HOLEtraj does not close file descriptors (Issue 129)")
elif err.errno == errno.ENOENT:
raise OSError(errno.ENOENT, "HOLE binary not found")
raise
finally:
# make sure to restore open file limit !!
self._restore_rlimits()

def _restore_rlimits(self):
try:
Expand All @@ -114,6 +108,5 @@ def _restore_rlimits(self):
def tearDown(self):
self._restore_rlimits()
del self.universe
shutil.rmtree(self.dir_name, ignore_errors=True)


0 comments on commit f1345fa

Please sign in to comment.