Skip to content

Commit

Permalink
Merge pull request #732 from MDAnalysis/issue-669-test-offsets-cleanup
Browse files Browse the repository at this point in the history
New cleanup plugin that deletes offset files after tests (closes #669)
  • Loading branch information
kain88-de committed Feb 22, 2016
2 parents 693b478 + 8750c72 commit c81ece3
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 4 deletions.
2 changes: 2 additions & 0 deletions testsuite/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ and https://github.com/MDAnalysis/mdanalysis/wiki/UnitTests

* 0.14.0

- Added the cleanup plugin (--with-mda_cleanup) to delete offset files
after tests have run (Issue 669)
- Made memleak testing python 3 compliant (Issue 662). It may be a moot
point since python 3.4 now cleverly deals with leaks.

Expand Down
4 changes: 2 additions & 2 deletions testsuite/MDAnalysisTests/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
# code won't be run again under coverage's watch.

# Don't forget to also add your plugin to the import further ahead
__all__ = ['memleak', 'capture_err', 'knownfailure']
__all__ = ['memleak', 'capture_err', 'knownfailure', 'cleanup']

import distutils.version
try:
Expand Down Expand Up @@ -103,7 +103,7 @@ def _check_plugins_loaded():
loaded_plugins = dict()

# ADD HERE your plugin import
from . import memleak, capture_err, knownfailure
from . import memleak, capture_err, knownfailure, cleanup

plugin_classes = []
for plugin in __all__:
Expand Down
4 changes: 2 additions & 2 deletions testsuite/MDAnalysisTests/plugins/capture_err.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ def __init__(self):
self._buf = None

def options(self, parser, env):
"""Register commandline options
"""Registers the commandline option, defaulting to enabled.
"""
parser.add_option(
"--no-errorcapture", action="store_false",
default=not env.get(self.env_opt), dest="capture_error",
help="Don't capture stderr (any stderr output "
"will be printed immediately) [NOSE_NO_ERRORCAPTURE]")
"will be printed immediately) [{}]".format(self.env_opt))

def configure(self, options, conf):
"""Configure plugin. Plugin is enabled by default.
Expand Down
74 changes: 74 additions & 0 deletions testsuite/MDAnalysisTests/plugins/cleanup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# -*- Mode: python; tab-width: 4; indent-tabs-mode:nil; coding:utf-8 -*-
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 fileencoding=utf-8
#
# MDAnalysis --- http://www.MDAnalysis.org
# Copyright (c) 2006-2015 Naveen Michaud-Agrawal, Elizabeth J. Denning, Oliver Beckstein
# and contributors (see AUTHORS for the full list)
#
# Released under the GNU Public Licence, v2 or any higher version
#
# Please cite your use of MDAnalysis in published work:
#
# N. Michaud-Agrawal, E. J. Denning, T. B. Woolf, and O. Beckstein.
# MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations.
# J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787
#

"""Plugin that cleans up all .npz created during testing.
"""
# We may want to make the glob pattern an option, for extensibility.

import nose
from nose.plugins.base import Plugin
from os import walk, unlink, path
from pkg_resources import resource_filename
import warnings

class Cleanup(Plugin):
"""Removes XDR offset files after all testing is done."""
enabled = True
name = "mda_cleanup"
env_opt = 'NOSE_NO_MDA_CLEANUP'
score = 2000

def options(self, parser, env):
"""Registers the commandline option, defaulting to enabled.
"""
parser.add_option("--no-%s" % self.name,
action="store_false",
dest="do_mda_cleanup",
default=not env.get(self.env_opt),
help="Disables the cleanup of MDAnalysis offset "
"(*.npz) files. [{}]".format(self.env_opt))

def configure(self, options, conf):
super(Cleanup, self).configure(options, conf)
self.config = conf # This will let other tests know about config settings.
try:
self.enabled = options.do_mda_cleanup
except AttributeError:
self.enabled = False
self.verbosity = options.verbosity

def report(self, stream):
from .. import __name__ as mdatestsname
dirname = resource_filename(mdatestsname, 'data')
if self.verbosity > 0:
stream.write("Cleanup: deleting offset files in "
"{}\n".format(dirname))
for root, dirs, fnames in walk(dirname):
for fname in fnames:
if fname.endswith('_offsets.npz'):
fullname = path.join(root, fname)
if self.verbosity > 1:
stream.write("Cleanup: deleting offset file "
"{}\n".format(fullname))
try:
unlink(fullname)
except OSError:
warnings.warn("Cleanup couldn't delete offset file "
"{}".format(fullname))


plugin_class = Cleanup

0 comments on commit c81ece3

Please sign in to comment.