From e9e47c3853bb769b03eb9cebbb28bffc1e9e57b2 Mon Sep 17 00:00:00 2001 From: Irfan Alibay Date: Tue, 16 Jun 2020 06:52:48 +0100 Subject: [PATCH] Remove py2 things from aux, vis, transform, and others (#2762) * Remove py2 things from aux * rm py2 for selections, tests, transformations * Remove py2 from visualization * Remove misc py2 things * errsmg typo --- benchmarks/benchmarks/GRO.py | 2 - benchmarks/benchmarks/ag_methods.py | 2 - benchmarks/benchmarks/analysis/distances.py | 2 - benchmarks/benchmarks/analysis/leaflet.py | 2 - benchmarks/benchmarks/analysis/psa.py | 2 - benchmarks/benchmarks/analysis/rdf.py | 2 - benchmarks/benchmarks/analysis/rms.py | 2 - benchmarks/benchmarks/selections.py | 2 - benchmarks/benchmarks/traj_reader.py | 1 - maintainer/adapt_sitemap.py | 2 - package/MDAnalysis/__init__.py | 1 - package/MDAnalysis/auxiliary/XVG.py | 14 ++----- package/MDAnalysis/auxiliary/__init__.py | 2 - package/MDAnalysis/auxiliary/base.py | 6 +-- package/MDAnalysis/auxiliary/core.py | 20 +++------- package/MDAnalysis/due.py | 1 - package/MDAnalysis/selections/__init__.py | 10 ++--- package/MDAnalysis/selections/base.py | 8 +--- package/MDAnalysis/selections/charmm.py | 3 +- package/MDAnalysis/selections/gromacs.py | 3 +- package/MDAnalysis/selections/jmol.py | 3 +- package/MDAnalysis/selections/pymol.py | 3 +- package/MDAnalysis/selections/vmd.py | 3 +- package/MDAnalysis/tests/datafiles.py | 4 +- .../MDAnalysis/transformations/__init__.py | 2 - package/MDAnalysis/transformations/fit.py | 21 +++++----- .../transformations/positionaveraging.py | 3 -- package/MDAnalysis/transformations/rotate.py | 16 +++----- .../MDAnalysis/transformations/translate.py | 10 ++--- package/MDAnalysis/transformations/wrap.py | 3 +- package/MDAnalysis/units.py | 21 +++------- package/MDAnalysis/visualization/__init__.py | 1 - .../MDAnalysis/visualization/streamlines.py | 10 +---- .../visualization/streamlines_3D.py | 8 +--- testsuite/MDAnalysisTests/__init__.py | 1 - testsuite/MDAnalysisTests/auxiliary/base.py | 3 -- .../MDAnalysisTests/auxiliary/test_core.py | 2 - .../MDAnalysisTests/auxiliary/test_xvg.py | 3 -- .../data/coordinates/create_data.py | 1 - testsuite/MDAnalysisTests/datafiles.py | 1 - testsuite/MDAnalysisTests/dummy.py | 3 -- .../MDAnalysisTests/formats/test_libdcd.py | 4 +- .../MDAnalysisTests/formats/test_libmdaxdr.py | 3 +- .../MDAnalysisTests/import/fork_called.py | 1 - .../MDAnalysisTests/import/test_import.py | 1 - testsuite/MDAnalysisTests/test_api.py | 2 - .../transformations/test_fit.py | 2 - .../transformations/test_positionaveraging.py | 2 - .../transformations/test_rotate.py | 2 - .../transformations/test_translate.py | 2 - .../transformations/test_wrap.py | 2 - testsuite/MDAnalysisTests/util.py | 2 +- .../MDAnalysisTests/utils/test_altloc.py | 2 - .../MDAnalysisTests/utils/test_authors.py | 1 - .../MDAnalysisTests/utils/test_datafiles.py | 2 - .../MDAnalysisTests/utils/test_duecredit.py | 1 - .../MDAnalysisTests/utils/test_failure.py | 2 - .../MDAnalysisTests/utils/test_imports.py | 2 - testsuite/MDAnalysisTests/utils/test_log.py | 4 +- testsuite/MDAnalysisTests/utils/test_meta.py | 2 - .../MDAnalysisTests/utils/test_modelling.py | 2 - .../MDAnalysisTests/utils/test_persistence.py | 40 +++++++++---------- .../MDAnalysisTests/utils/test_qcprot.py | 2 - .../MDAnalysisTests/utils/test_selections.py | 3 +- .../MDAnalysisTests/utils/test_streamio.py | 39 +++++------------- .../utils/test_transformations.py | 3 -- testsuite/MDAnalysisTests/utils/test_units.py | 2 - .../visualization/test_streamlines.py | 1 - 68 files changed, 85 insertions(+), 255 deletions(-) diff --git a/benchmarks/benchmarks/GRO.py b/benchmarks/benchmarks/GRO.py index 0b4c31bf7ca..ad34b41915e 100644 --- a/benchmarks/benchmarks/GRO.py +++ b/benchmarks/benchmarks/GRO.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import numpy as np from MDAnalysis.coordinates.GRO import GROReader from MDAnalysis.topology.GROParser import GROParser diff --git a/benchmarks/benchmarks/ag_methods.py b/benchmarks/benchmarks/ag_methods.py index 2cc446268ef..be6cd7ba322 100644 --- a/benchmarks/benchmarks/ag_methods.py +++ b/benchmarks/benchmarks/ag_methods.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import MDAnalysis import numpy as np diff --git a/benchmarks/benchmarks/analysis/distances.py b/benchmarks/benchmarks/analysis/distances.py index f138f101f94..303168425f0 100644 --- a/benchmarks/benchmarks/analysis/distances.py +++ b/benchmarks/benchmarks/analysis/distances.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import MDAnalysis import numpy as np diff --git a/benchmarks/benchmarks/analysis/leaflet.py b/benchmarks/benchmarks/analysis/leaflet.py index dcfc3a98df6..791ca7c8e68 100644 --- a/benchmarks/benchmarks/analysis/leaflet.py +++ b/benchmarks/benchmarks/analysis/leaflet.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import MDAnalysis # use a lipid bilayer system for leaflet testing diff --git a/benchmarks/benchmarks/analysis/psa.py b/benchmarks/benchmarks/analysis/psa.py index 95f1a78a453..bc7b73ac835 100644 --- a/benchmarks/benchmarks/analysis/psa.py +++ b/benchmarks/benchmarks/analysis/psa.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import MDAnalysis import numpy as np diff --git a/benchmarks/benchmarks/analysis/rdf.py b/benchmarks/benchmarks/analysis/rdf.py index f9099fa3319..507b112df89 100644 --- a/benchmarks/benchmarks/analysis/rdf.py +++ b/benchmarks/benchmarks/analysis/rdf.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import MDAnalysis try: diff --git a/benchmarks/benchmarks/analysis/rms.py b/benchmarks/benchmarks/analysis/rms.py index c9811a5984d..3d34f386c5a 100644 --- a/benchmarks/benchmarks/analysis/rms.py +++ b/benchmarks/benchmarks/analysis/rms.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import MDAnalysis try: diff --git a/benchmarks/benchmarks/selections.py b/benchmarks/benchmarks/selections.py index 36e580d8c2e..b07fc7348f6 100644 --- a/benchmarks/benchmarks/selections.py +++ b/benchmarks/benchmarks/selections.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import MDAnalysis try: diff --git a/benchmarks/benchmarks/traj_reader.py b/benchmarks/benchmarks/traj_reader.py index cf66f767292..b2fce682c60 100644 --- a/benchmarks/benchmarks/traj_reader.py +++ b/benchmarks/benchmarks/traj_reader.py @@ -1,4 +1,3 @@ -from __future__ import division, absolute_import, print_function try: from MDAnalysis.coordinates.DCD import DCDReader diff --git a/maintainer/adapt_sitemap.py b/maintainer/adapt_sitemap.py index 593b4c4cf4b..a731bf20872 100755 --- a/maintainer/adapt_sitemap.py +++ b/maintainer/adapt_sitemap.py @@ -3,8 +3,6 @@ # # Adjust path in sitemap.xml -from __future__ import print_function - from xml.etree import ElementTree import argparse diff --git a/package/MDAnalysis/__init__.py b/package/MDAnalysis/__init__.py index ad5fb648c42..4eab18bb6bb 100644 --- a/package/MDAnalysis/__init__.py +++ b/package/MDAnalysis/__init__.py @@ -149,7 +149,6 @@ doi:10.1016/j.jmb.2009.09.009 """ -from __future__ import absolute_import __all__ = ['Universe', 'as_Universe', 'Writer', 'fetch_mmtf', 'AtomGroup', 'ResidueGroup', 'SegmentGroup'] diff --git a/package/MDAnalysis/auxiliary/XVG.py b/package/MDAnalysis/auxiliary/XVG.py index 4bf2c083c21..2dbeb705cf9 100644 --- a/package/MDAnalysis/auxiliary/XVG.py +++ b/package/MDAnalysis/auxiliary/XVG.py @@ -66,10 +66,6 @@ .. autofunction:: uncomment """ -from __future__ import absolute_import - -from six import raise_from - import numbers import os import numpy as np @@ -150,13 +146,9 @@ def _select_data(self, key): try: return self._data[key] except IndexError: - raise_from( - ValueError( - '{} not a valid index for data with {} ' - 'columns'.format(key, len(self._data)) - ), - None - ) + errmsg = (f'{key} not a valid index for data with ' + f'{len(self._data)} columns') + raise ValueError(errmsg) from None else: return np.array([self._select_data(i) for i in key]) diff --git a/package/MDAnalysis/auxiliary/__init__.py b/package/MDAnalysis/auxiliary/__init__.py index 4e2667e8d2b..b10e543065f 100644 --- a/package/MDAnalysis/auxiliary/__init__.py +++ b/package/MDAnalysis/auxiliary/__init__.py @@ -517,8 +517,6 @@ """ -from __future__ import absolute_import - # registry of auxiliary readers _AUXREADERS = {} diff --git a/package/MDAnalysis/auxiliary/base.py b/package/MDAnalysis/auxiliary/base.py index b17c1d7d0d2..8bea4573133 100644 --- a/package/MDAnalysis/auxiliary/base.py +++ b/package/MDAnalysis/auxiliary/base.py @@ -39,10 +39,6 @@ """ -from __future__ import division, absolute_import -import six -from six.moves import range - import os import numbers import math @@ -235,7 +231,7 @@ def _empty_data(self): return np.full_like(self.data, np.nan) -class AuxReader(six.with_metaclass(_AuxReaderMeta)): +class AuxReader(metaclass=_AuxReaderMeta): """ Base class for auxiliary readers. Allows iteration over a set of data from a trajectory, additional diff --git a/package/MDAnalysis/auxiliary/core.py b/package/MDAnalysis/auxiliary/core.py index 2f05a8c1d59..6dc3124d57a 100644 --- a/package/MDAnalysis/auxiliary/core.py +++ b/package/MDAnalysis/auxiliary/core.py @@ -28,13 +28,10 @@ .. autofunction:: get_auxreader_for .. autofunction:: auxreader """ -from __future__ import absolute_import - -from six import raise_from, string_types - from . import _AUXREADERS from ..lib import util + def get_auxreader_for(auxdata=None, format=None): """Return the appropriate auxiliary reader class for *auxdata*/*format*. @@ -65,7 +62,7 @@ def get_auxreader_for(auxdata=None, format=None): raise ValueError('Must provide either auxdata or format') if format is None: - if isinstance(auxdata, string_types): + if isinstance(auxdata, str): ## assume it's a filename? format = util.guess_format(auxdata) else: @@ -75,19 +72,14 @@ def get_auxreader_for(auxdata=None, format=None): try: return _AUXREADERS[format] except KeyError: - raise_from( - ValueError( - "Unknown auxiliary data format for auxdata: " - "{0}".format(auxdata)), - None - ) + errmsg = f"Unknown auxiliary data format for auxdata: {auxdata}" + raise ValueError(errmsg) from None else: try: return _AUXREADERS[format] except KeyError: - raise_from( - ValueError("Unknown auxiliary data format {0}".format(format)), - None) + errmsg = f"Unknown auxiliary data format {format}" + raise ValueError(errmsg) from None def auxreader(auxdata, format=None, **kwargs): """ Return an auxiliary reader instance for *auxdata*. diff --git a/package/MDAnalysis/due.py b/package/MDAnalysis/due.py index 41724c0d886..b8f10b37dce 100644 --- a/package/MDAnalysis/due.py +++ b/package/MDAnalysis/due.py @@ -26,7 +26,6 @@ """ -from __future__ import absolute_import __version__ = '0.0.5' diff --git a/package/MDAnalysis/selections/__init__.py b/package/MDAnalysis/selections/__init__.py index 146252a9963..4ff08dc116d 100644 --- a/package/MDAnalysis/selections/__init__.py +++ b/package/MDAnalysis/selections/__init__.py @@ -44,9 +44,6 @@ .. autofunction:: get_writer """ -from __future__ import absolute_import -from six import raise_from - import os.path from .. import _SELECTION_WRITERS @@ -86,7 +83,6 @@ def get_writer(filename, defaultformat): try: return _SELECTION_WRITERS[format] except KeyError: - raise_from(NotImplementedError( - "Writing as {0!r} is not implemented;" - " only {1!r} will work.".format(format, _SELECTION_WRITERS.keys())), - None) + errmsg = (f"Writing as {format} is not implemented; only " + f"{ _SELECTION_WRITERS.keys()} will work.") + raise NotImplementedError(errmsg) from None diff --git a/package/MDAnalysis/selections/base.py b/package/MDAnalysis/selections/base.py index 277e8f4b810..fccc0b7e2b7 100644 --- a/package/MDAnalysis/selections/base.py +++ b/package/MDAnalysis/selections/base.py @@ -37,16 +37,12 @@ .. autofunction:: join """ -from __future__ import absolute_import - -import six -from six.moves import range - import os.path from ..lib import util from . import _SELECTION_WRITERS + def join(seq, string="", func=None): """Create a list from sequence. @@ -75,7 +71,7 @@ def __init__(cls, name, bases, classdict): _SELECTION_WRITERS[f] = cls -class SelectionWriterBase(six.with_metaclass(_Selectionmeta)): +class SelectionWriterBase(metaclass=_Selectionmeta): """Export a selection in MDAnalysis to a format usable in an external package. The :class:`SelectionWriterBase` writes a selection string to a file diff --git a/package/MDAnalysis/selections/charmm.py b/package/MDAnalysis/selections/charmm.py index 66aae74b8b6..1ede0a646bc 100644 --- a/package/MDAnalysis/selections/charmm.py +++ b/package/MDAnalysis/selections/charmm.py @@ -39,10 +39,9 @@ .. _CHARMM: http://www.charmm.org .. _CHARMM selection: http://www.charmm.org/documentation/c34b1/select.html """ -from __future__ import absolute_import - from . import base + class SelectionWriter(base.SelectionWriterBase): format = ["CHARMM", "str"] ext = "str" diff --git a/package/MDAnalysis/selections/gromacs.py b/package/MDAnalysis/selections/gromacs.py index 7ef721caa44..1129388d409 100644 --- a/package/MDAnalysis/selections/gromacs.py +++ b/package/MDAnalysis/selections/gromacs.py @@ -39,10 +39,9 @@ .. autoclass:: SelectionWriter :inherited-members: """ -from __future__ import absolute_import - from . import base + class SelectionWriter(base.SelectionWriterBase): format = ["Gromacs", "ndx"] ext = "ndx" diff --git a/package/MDAnalysis/selections/jmol.py b/package/MDAnalysis/selections/jmol.py index 462df90d3b3..a090b5bfe54 100644 --- a/package/MDAnalysis/selections/jmol.py +++ b/package/MDAnalysis/selections/jmol.py @@ -39,10 +39,9 @@ .. _Jmol: http://wiki.jmol.org/index.php/Main_Page .. _Jmol selection: http://chemapps.stolaf.edu/jmol/docs/#define """ -from __future__ import absolute_import - from . import base + class SelectionWriter(base.SelectionWriterBase): format = ["Jmol", "spt"] ext = "spt" diff --git a/package/MDAnalysis/selections/pymol.py b/package/MDAnalysis/selections/pymol.py index 1873524cb93..0a86d23e918 100644 --- a/package/MDAnalysis/selections/pymol.py +++ b/package/MDAnalysis/selections/pymol.py @@ -40,10 +40,9 @@ .. autoclass:: SelectionWriter :inherited-members: """ -from __future__ import absolute_import - from . import base + class SelectionWriter(base.SelectionWriterBase): format = ["PyMol", "pml"] ext = "pml" diff --git a/package/MDAnalysis/selections/vmd.py b/package/MDAnalysis/selections/vmd.py index 879b8d7a0fc..d9f3043ed90 100644 --- a/package/MDAnalysis/selections/vmd.py +++ b/package/MDAnalysis/selections/vmd.py @@ -47,10 +47,9 @@ :inherited-members: """ -from __future__ import absolute_import - from . import base + class SelectionWriter(base.SelectionWriterBase): format = "VMD" ext = "vmd" diff --git a/package/MDAnalysis/tests/datafiles.py b/package/MDAnalysis/tests/datafiles.py index 68f2af8000e..8f879873b12 100644 --- a/package/MDAnalysis/tests/datafiles.py +++ b/package/MDAnalysis/tests/datafiles.py @@ -36,8 +36,6 @@ :mod:`MDAnalysisTests` package which must be downloaded from http://pypi.python.org/pypi/MDAnalysisTests and installed. """ -from __future__ import print_function, absolute_import -from six import raise_from try: from MDAnalysisTests.datafiles import * @@ -51,4 +49,4 @@ print() print("and download and install the `MDAnalysisTests-x.y.z.tar.gz'") print("that matches your MDAnalysis release.") - raise_from(ImportError("MDAnalysisTests package not installed."), None) + raise ImportError("MDAnalysisTests package not installed.") from None diff --git a/package/MDAnalysis/transformations/__init__.py b/package/MDAnalysis/transformations/__init__.py index f2dbbde94d9..13ce68dfbd4 100644 --- a/package/MDAnalysis/transformations/__init__.py +++ b/package/MDAnalysis/transformations/__init__.py @@ -56,8 +56,6 @@ def wrapped(ts): """ -from __future__ import absolute_import - from .translate import translate, center_in_box from .rotate import rotateby from .positionaveraging import PositionAverager diff --git a/package/MDAnalysis/transformations/fit.py b/package/MDAnalysis/transformations/fit.py index e742dca67f3..084868a0e55 100644 --- a/package/MDAnalysis/transformations/fit.py +++ b/package/MDAnalysis/transformations/fit.py @@ -32,9 +32,6 @@ .. autofunction:: fit_rot_trans """ -from __future__ import absolute_import -from six import raise_from - import numpy as np from functools import partial @@ -91,14 +88,14 @@ def fit_translation(ag, reference, plane=None, weights=None): try: plane = axes[plane] except (TypeError, KeyError): - raise_from(ValueError('{} is not a valid plane'.format(plane)), None) + raise ValueError(f'{plane} is not a valid plane') from None try: if ag.atoms.n_residues != reference.atoms.n_residues: - raise ValueError("{} and {} have mismatched number of residues".format(ag,reference)) + errmsg = f"{ag} and {reference} have mismatched number of residues" + raise ValueError(errmsg) except AttributeError: - raise_from( - AttributeError("{} or {} is not valid Universe/AtomGroup".format(ag,reference)), - None) + errmsg = f"{ag} or {reference} is not valid Universe/AtomGroup" + raise AttributeError(errmsg) from None ref, mobile = align.get_matching_atoms(reference.atoms, ag.atoms) weights = align.get_weights(ref.atoms, weights=weights) ref_com = ref.center(weights) @@ -168,12 +165,14 @@ def fit_rot_trans(ag, reference, plane=None, weights=None): try: plane = axes[plane] except (TypeError, KeyError): - raise_from(ValueError('{} is not a valid plane'.format(plane)), None) + raise ValueError(f'{plane} is not a valid plane') from None try: if ag.atoms.n_residues != reference.atoms.n_residues: - raise ValueError("{} and {} have mismatched number of residues".format(ag,reference)) + errmsg = f"{ag} and {reference} have mismatched number of residues" + raise ValueError(errmsg) except AttributeError: - raise_from(AttributeError("{} or {} is not valid Universe/AtomGroup".format(ag,reference)), None) + errmsg = f"{ag} or {reference} is not valid Universe/AtomGroup" + raise AttributeError(errmsg) from None ref, mobile = align.get_matching_atoms(reference.atoms, ag.atoms) weights = align.get_weights(ref.atoms, weights=weights) ref_com = ref.center(weights) diff --git a/package/MDAnalysis/transformations/positionaveraging.py b/package/MDAnalysis/transformations/positionaveraging.py index 00ee3ff9c85..179b98163f1 100644 --- a/package/MDAnalysis/transformations/positionaveraging.py +++ b/package/MDAnalysis/transformations/positionaveraging.py @@ -32,13 +32,10 @@ .. autoclass:: PositionAverager """ -from __future__ import absolute_import - import numpy as np import warnings - class PositionAverager(object): """ diff --git a/package/MDAnalysis/transformations/rotate.py b/package/MDAnalysis/transformations/rotate.py index 694aec606e2..4e27f81012d 100644 --- a/package/MDAnalysis/transformations/rotate.py +++ b/package/MDAnalysis/transformations/rotate.py @@ -31,9 +31,6 @@ .. autofunction:: rotateby """ -from __future__ import absolute_import -from six import raise_from - import math import numpy as np from functools import partial @@ -114,9 +111,7 @@ def rotateby(angle, direction, point=None, ag=None, weights=None, wrap=False): raise ValueError('{} is not a valid direction'.format(direction)) direction = direction.reshape(3, ) except ValueError: - raise_from( - ValueError('{} is not a valid direction'.format(direction)), - None) + raise ValueError(f'{direction} is not a valid direction') from None if point is not None: point = np.asarray(point, np.float32) if point.shape != (3, ) and point.shape != (1, 3): @@ -126,15 +121,14 @@ def rotateby(angle, direction, point=None, ag=None, weights=None, wrap=False): try: atoms = ag.atoms except AttributeError: - raise_from(ValueError('{} is not an AtomGroup object'.format(ag)), None) + raise ValueError(f'{ag} is not an AtomGroup object') from None else: try: weights = get_weights(atoms, weights=weights) except (ValueError, TypeError): - raise_from( - TypeError("weights must be {'mass', None} or an iterable of the " - "same size as the atomgroup."), - None) + errmsg = ("weights must be {'mass', None} or an iterable of " + "the same size as the atomgroup.") + raise TypeError(errmsg) from None center_method = partial(atoms.center, weights, pbc=wrap) else: raise ValueError('A point or an AtomGroup must be specified') diff --git a/package/MDAnalysis/transformations/translate.py b/package/MDAnalysis/transformations/translate.py index 77950d4bab3..6a4d28113be 100644 --- a/package/MDAnalysis/transformations/translate.py +++ b/package/MDAnalysis/transformations/translate.py @@ -36,9 +36,6 @@ """ -from __future__ import absolute_import, division -from six import raise_from - import numpy as np from functools import partial @@ -127,11 +124,10 @@ def center_in_box(ag, center='geometry', point=None, wrap=False): raise ValueError('{} is not a valid argument for center'.format(center)) except AttributeError: if center == 'mass': - raise_from( - AttributeError('{} is not an AtomGroup object with masses'.format(ag)), - None) + errmsg = f'{ag} is not an AtomGroup object with masses' + raise AttributeError(errmsg) from None else: - raise_from(ValueError('{} is not an AtomGroup object'.format(ag)), None) + raise ValueError(f'{ag} is not an AtomGroup object') from None def wrapped(ts): if point is None: diff --git a/package/MDAnalysis/transformations/wrap.py b/package/MDAnalysis/transformations/wrap.py index a88d852fd42..99b60f943a1 100644 --- a/package/MDAnalysis/transformations/wrap.py +++ b/package/MDAnalysis/transformations/wrap.py @@ -34,10 +34,9 @@ """ -from __future__ import absolute_import - from ..lib._cutil import make_whole + def wrap(ag, compound='atoms'): """ Shift the contents of a given AtomGroup back into the unit cell. :: diff --git a/package/MDAnalysis/units.py b/package/MDAnalysis/units.py index 670967d941d..9e77df6f486 100644 --- a/package/MDAnalysis/units.py +++ b/package/MDAnalysis/units.py @@ -165,9 +165,6 @@ """ -from __future__ import absolute_import, unicode_literals, division -from six import raise_from - # # NOTE: Whenever a constant is added to the constants dict, you also # MUST add an appropriate entry to @@ -354,22 +351,16 @@ def convert(x, u1, u2): try: ut1 = unit_types[u1] except KeyError: - raise_from( - ValueError( - ("unit '{0}' not recognized.\n" - "It must be one of {1}.").format(u1, ", ".join(unit_types)) - ), - None) + errmsg = (f"unit '{u1}' not recognized.\n" + f"It must be one of {', '.join(unit_types)}.") + raise ValueError(errmsg) from None try: ut2 = unit_types[u2] except KeyError: - raise_from( - ValueError( - ("unit '{0}' not recognized.\n" - "It must be one of {1}.").format(u2, ", ".join(unit_types)) - ), - None) + errmsg = (f"unit '{u2}' not recognized.\n" + f"It must be one of {', '.join(unit_types)}.") + raise ValueError(errmsg) from None if ut1 != ut2: raise ValueError("Cannot convert between unit types " "{0} --> {1}".format(u1, u2)) diff --git a/package/MDAnalysis/visualization/__init__.py b/package/MDAnalysis/visualization/__init__.py index 8e53b809d92..72e488329a2 100644 --- a/package/MDAnalysis/visualization/__init__.py +++ b/package/MDAnalysis/visualization/__init__.py @@ -21,7 +21,6 @@ # J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 # -from __future__ import absolute_import from . import streamlines from . import streamlines_3D diff --git a/package/MDAnalysis/visualization/streamlines.py b/package/MDAnalysis/visualization/streamlines.py index e50bb0df313..e5ae24018a1 100644 --- a/package/MDAnalysis/visualization/streamlines.py +++ b/package/MDAnalysis/visualization/streamlines.py @@ -42,10 +42,6 @@ .. autofunction:: generate_streamlines """ -from __future__ import absolute_import -from six.moves import zip -from six import raise_from - import multiprocessing import numpy as np @@ -55,14 +51,12 @@ import matplotlib import matplotlib.path except ImportError: - raise_from( - ImportError(( + raise ImportError( '2d streamplot module requires: matplotlib.path for its ' 'path.Path.contains_points method. The installation ' 'instructions for the matplotlib module can be found here: ' 'http://matplotlib.org/faq/installing_faq.html?highlight=install' - )), - None) + ) from None import MDAnalysis diff --git a/package/MDAnalysis/visualization/streamlines_3D.py b/package/MDAnalysis/visualization/streamlines_3D.py index cf749d5e387..07c00b447ab 100644 --- a/package/MDAnalysis/visualization/streamlines_3D.py +++ b/package/MDAnalysis/visualization/streamlines_3D.py @@ -43,10 +43,6 @@ .. autofunction:: generate_streamlines_3d """ -from __future__ import division, absolute_import -import six -from six.moves import range, zip - import multiprocessing import numpy as np @@ -267,7 +263,7 @@ def update_dictionary_point_in_cube_start_frame(array_simulation_particle_coordi corresponding to the indices of the relevant particles that fall within a given cube. Also, for a given cube, store a key/value pair for the centroid of the particles that fall within the cube.""" cube_counter = 0 - for key, cube in six.iteritems(dictionary_cube_data_this_core): + for key, cube in dictionary_cube_data_this_core.items(): index_list_in_cube = point_in_cube(array_simulation_particle_coordinates, cube['vertex_list'], cube['centroid']) cube['start_frame_index_list_in_cube'] = index_list_in_cube @@ -282,7 +278,7 @@ def update_dictionary_point_in_cube_start_frame(array_simulation_particle_coordi def update_dictionary_end_frame(array_simulation_particle_coordinates, dictionary_cube_data_this_core): """Update the cube dictionary objects again as appropriate for the second and final frame.""" cube_counter = 0 - for key, cube in six.iteritems(dictionary_cube_data_this_core): + for key, cube in dictionary_cube_data_this_core.items(): # if there were no particles in the cube in the first frame, then set dx,dy,dz each to 0 if cube['centroid_of_particles_first_frame'] == 'empty': cube['dx'] = 0 diff --git a/testsuite/MDAnalysisTests/__init__.py b/testsuite/MDAnalysisTests/__init__.py index 7a7fef347f4..60f12335323 100644 --- a/testsuite/MDAnalysisTests/__init__.py +++ b/testsuite/MDAnalysisTests/__init__.py @@ -90,7 +90,6 @@ .. _Gromacs: http://www.gromacs.org """ -from __future__ import absolute_import import logging import pytest diff --git a/testsuite/MDAnalysisTests/auxiliary/base.py b/testsuite/MDAnalysisTests/auxiliary/base.py index ea9fbc8c379..68561fd8f48 100644 --- a/testsuite/MDAnalysisTests/auxiliary/base.py +++ b/testsuite/MDAnalysisTests/auxiliary/base.py @@ -20,14 +20,11 @@ # MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations. # J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 # -from __future__ import absolute_import - import MDAnalysis as mda import numpy as np import pytest from MDAnalysisTests.datafiles import (COORDINATES_XTC, COORDINATES_TOPOLOGY) from numpy.testing import assert_almost_equal, assert_equal -from six.moves import range def test_get_bad_auxreader_format_raises_ValueError(): diff --git a/testsuite/MDAnalysisTests/auxiliary/test_core.py b/testsuite/MDAnalysisTests/auxiliary/test_core.py index 9a624be1c6f..f8a4bb81f5c 100644 --- a/testsuite/MDAnalysisTests/auxiliary/test_core.py +++ b/testsuite/MDAnalysisTests/auxiliary/test_core.py @@ -21,8 +21,6 @@ # J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 # -from __future__ import absolute_import - import MDAnalysis as mda import pytest diff --git a/testsuite/MDAnalysisTests/auxiliary/test_xvg.py b/testsuite/MDAnalysisTests/auxiliary/test_xvg.py index e9d837595bc..ec70383dbb5 100644 --- a/testsuite/MDAnalysisTests/auxiliary/test_xvg.py +++ b/testsuite/MDAnalysisTests/auxiliary/test_xvg.py @@ -20,9 +20,6 @@ # MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations. # J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 # -from __future__ import absolute_import - -from six.moves import range import pytest from numpy.testing import assert_array_equal import numpy as np diff --git a/testsuite/MDAnalysisTests/data/coordinates/create_data.py b/testsuite/MDAnalysisTests/data/coordinates/create_data.py index 9a2b3ede853..94919f6d77b 100644 --- a/testsuite/MDAnalysisTests/data/coordinates/create_data.py +++ b/testsuite/MDAnalysisTests/data/coordinates/create_data.py @@ -1,6 +1,5 @@ import MDAnalysis as mda import numpy as np -from six.moves import range def create_test_trj(uni, fname): diff --git a/testsuite/MDAnalysisTests/datafiles.py b/testsuite/MDAnalysisTests/datafiles.py index 79f13bc3377..cc12454aa35 100644 --- a/testsuite/MDAnalysisTests/datafiles.py +++ b/testsuite/MDAnalysisTests/datafiles.py @@ -35,7 +35,6 @@ from MDAnalysisTestData.datafiles import * """ -from __future__ import absolute_import __all__ = [ "PSF", "DCD", "CRD", # CHARMM (AdK example, DIMS trajectory from JMB 2009 paper) diff --git a/testsuite/MDAnalysisTests/dummy.py b/testsuite/MDAnalysisTests/dummy.py index f6e77ebf817..1da3799fbdf 100644 --- a/testsuite/MDAnalysisTests/dummy.py +++ b/testsuite/MDAnalysisTests/dummy.py @@ -23,9 +23,6 @@ """Mock Universe and Topology generated from scratch with default values """ -from __future__ import absolute_import, division - -from six.moves import range import numpy as np import string diff --git a/testsuite/MDAnalysisTests/formats/test_libdcd.py b/testsuite/MDAnalysisTests/formats/test_libdcd.py index 0028a80bd3b..452b47ad485 100644 --- a/testsuite/MDAnalysisTests/formats/test_libdcd.py +++ b/testsuite/MDAnalysisTests/formats/test_libdcd.py @@ -13,9 +13,7 @@ # MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations. # J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 # -from __future__ import absolute_import, print_function -from six.moves import zip -from six.moves import cPickle as pickle +import pickle from collections import namedtuple import os diff --git a/testsuite/MDAnalysisTests/formats/test_libmdaxdr.py b/testsuite/MDAnalysisTests/formats/test_libmdaxdr.py index d4ed6190d2a..aff0bddf1b5 100644 --- a/testsuite/MDAnalysisTests/formats/test_libmdaxdr.py +++ b/testsuite/MDAnalysisTests/formats/test_libmdaxdr.py @@ -20,8 +20,7 @@ # MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations. # J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 # -from __future__ import print_function, absolute_import -from six.moves import cPickle as pickle +import pickle import numpy as np diff --git a/testsuite/MDAnalysisTests/import/fork_called.py b/testsuite/MDAnalysisTests/import/fork_called.py index 5296d1065e2..3f2fe1bd56c 100644 --- a/testsuite/MDAnalysisTests/import/fork_called.py +++ b/testsuite/MDAnalysisTests/import/fork_called.py @@ -20,7 +20,6 @@ # MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations. # J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 # -from __future__ import absolute_import, print_function import os import mock diff --git a/testsuite/MDAnalysisTests/import/test_import.py b/testsuite/MDAnalysisTests/import/test_import.py index 329a39e3fb0..6afcb72a281 100644 --- a/testsuite/MDAnalysisTests/import/test_import.py +++ b/testsuite/MDAnalysisTests/import/test_import.py @@ -20,7 +20,6 @@ # MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations. # J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 # -from __future__ import absolute_import, print_function import sys import os import subprocess diff --git a/testsuite/MDAnalysisTests/test_api.py b/testsuite/MDAnalysisTests/test_api.py index a9f5798c194..752fb516953 100644 --- a/testsuite/MDAnalysisTests/test_api.py +++ b/testsuite/MDAnalysisTests/test_api.py @@ -24,8 +24,6 @@ Test the user facing API is as we expect... """ -from __future__ import absolute_import - import MDAnalysis as mda def test_Universe(): diff --git a/testsuite/MDAnalysisTests/transformations/test_fit.py b/testsuite/MDAnalysisTests/transformations/test_fit.py index 3d206ce96d6..36469ec6d7f 100644 --- a/testsuite/MDAnalysisTests/transformations/test_fit.py +++ b/testsuite/MDAnalysisTests/transformations/test_fit.py @@ -19,8 +19,6 @@ # MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations. # J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 # -from __future__ import division, print_function, absolute_import - import numpy as np import pytest from numpy.testing import assert_array_almost_equal diff --git a/testsuite/MDAnalysisTests/transformations/test_positionaveraging.py b/testsuite/MDAnalysisTests/transformations/test_positionaveraging.py index 5c746bf7786..3eec056a5bb 100644 --- a/testsuite/MDAnalysisTests/transformations/test_positionaveraging.py +++ b/testsuite/MDAnalysisTests/transformations/test_positionaveraging.py @@ -1,7 +1,5 @@ ### -from __future__ import absolute_import - import numpy as np import pytest from numpy.testing import assert_array_almost_equal diff --git a/testsuite/MDAnalysisTests/transformations/test_rotate.py b/testsuite/MDAnalysisTests/transformations/test_rotate.py index 817abecd4b6..cf7342fab8f 100644 --- a/testsuite/MDAnalysisTests/transformations/test_rotate.py +++ b/testsuite/MDAnalysisTests/transformations/test_rotate.py @@ -21,8 +21,6 @@ # J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 # -from __future__ import absolute_import - import numpy as np import pytest from numpy.testing import assert_array_almost_equal diff --git a/testsuite/MDAnalysisTests/transformations/test_translate.py b/testsuite/MDAnalysisTests/transformations/test_translate.py index 413c3338bce..daeb9583f11 100644 --- a/testsuite/MDAnalysisTests/transformations/test_translate.py +++ b/testsuite/MDAnalysisTests/transformations/test_translate.py @@ -21,8 +21,6 @@ # J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 # -from __future__ import absolute_import - import numpy as np import pytest from numpy.testing import assert_array_almost_equal diff --git a/testsuite/MDAnalysisTests/transformations/test_wrap.py b/testsuite/MDAnalysisTests/transformations/test_wrap.py index bb338fa72fb..8b9cfecf2d9 100644 --- a/testsuite/MDAnalysisTests/transformations/test_wrap.py +++ b/testsuite/MDAnalysisTests/transformations/test_wrap.py @@ -20,8 +20,6 @@ # J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 # -from __future__ import absolute_import - import numpy as np import pytest from numpy.testing import assert_array_almost_equal diff --git a/testsuite/MDAnalysisTests/util.py b/testsuite/MDAnalysisTests/util.py index d4d54b08d8e..648ff286a7a 100644 --- a/testsuite/MDAnalysisTests/util.py +++ b/testsuite/MDAnalysisTests/util.py @@ -24,7 +24,6 @@ Useful functions for running tests """ -from __future__ import absolute_import try: import __builtin__ @@ -45,6 +44,7 @@ from numpy.testing import assert_warns + def block_import(package): """Block import of a given package diff --git a/testsuite/MDAnalysisTests/utils/test_altloc.py b/testsuite/MDAnalysisTests/utils/test_altloc.py index 490a22519c5..00e09279332 100644 --- a/testsuite/MDAnalysisTests/utils/test_altloc.py +++ b/testsuite/MDAnalysisTests/utils/test_altloc.py @@ -20,8 +20,6 @@ # MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations. # J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 # -from __future__ import absolute_import - import pytest from MDAnalysis import Universe from numpy.testing import assert_equal diff --git a/testsuite/MDAnalysisTests/utils/test_authors.py b/testsuite/MDAnalysisTests/utils/test_authors.py index 7d76eb299ac..67131e5034e 100644 --- a/testsuite/MDAnalysisTests/utils/test_authors.py +++ b/testsuite/MDAnalysisTests/utils/test_authors.py @@ -20,7 +20,6 @@ # MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations. # J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 # -from __future__ import absolute_import from numpy.testing import assert_ import MDAnalysis diff --git a/testsuite/MDAnalysisTests/utils/test_datafiles.py b/testsuite/MDAnalysisTests/utils/test_datafiles.py index f24d4289666..4b382349ce5 100644 --- a/testsuite/MDAnalysisTests/utils/test_datafiles.py +++ b/testsuite/MDAnalysisTests/utils/test_datafiles.py @@ -20,8 +20,6 @@ # MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations. # J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 # -from __future__ import absolute_import - import pytest from numpy.testing import assert_equal diff --git a/testsuite/MDAnalysisTests/utils/test_duecredit.py b/testsuite/MDAnalysisTests/utils/test_duecredit.py index cec267f5cab..4a782e0f901 100644 --- a/testsuite/MDAnalysisTests/utils/test_duecredit.py +++ b/testsuite/MDAnalysisTests/utils/test_duecredit.py @@ -20,7 +20,6 @@ # MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations. # J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 # -from __future__ import absolute_import import os import pytest diff --git a/testsuite/MDAnalysisTests/utils/test_failure.py b/testsuite/MDAnalysisTests/utils/test_failure.py index bc6e30fc8ed..551e9c4e103 100644 --- a/testsuite/MDAnalysisTests/utils/test_failure.py +++ b/testsuite/MDAnalysisTests/utils/test_failure.py @@ -20,8 +20,6 @@ # MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations. # J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 # -from __future__ import absolute_import - import os diff --git a/testsuite/MDAnalysisTests/utils/test_imports.py b/testsuite/MDAnalysisTests/utils/test_imports.py index 8c456810345..6d52b162ae3 100644 --- a/testsuite/MDAnalysisTests/utils/test_imports.py +++ b/testsuite/MDAnalysisTests/utils/test_imports.py @@ -20,8 +20,6 @@ # MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations. # J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 # -from __future__ import absolute_import - import os import MDAnalysisTests diff --git a/testsuite/MDAnalysisTests/utils/test_log.py b/testsuite/MDAnalysisTests/utils/test_log.py index 60b42a8d474..dbe21c3de9d 100644 --- a/testsuite/MDAnalysisTests/utils/test_log.py +++ b/testsuite/MDAnalysisTests/utils/test_log.py @@ -20,9 +20,7 @@ # MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations. # J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 # -from __future__ import division, absolute_import - -from six.moves import StringIO, range +from io import StringIO import logging import sys diff --git a/testsuite/MDAnalysisTests/utils/test_meta.py b/testsuite/MDAnalysisTests/utils/test_meta.py index bef422f4466..3de7b828de9 100644 --- a/testsuite/MDAnalysisTests/utils/test_meta.py +++ b/testsuite/MDAnalysisTests/utils/test_meta.py @@ -20,8 +20,6 @@ # MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations. # J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 # -from __future__ import absolute_import - import re import MDAnalysisTests diff --git a/testsuite/MDAnalysisTests/utils/test_modelling.py b/testsuite/MDAnalysisTests/utils/test_modelling.py index bafc3422c22..88578d2aefc 100644 --- a/testsuite/MDAnalysisTests/utils/test_modelling.py +++ b/testsuite/MDAnalysisTests/utils/test_modelling.py @@ -20,8 +20,6 @@ # MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations. # J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 # -from __future__ import absolute_import, print_function - import os import MDAnalysis import pytest diff --git a/testsuite/MDAnalysisTests/utils/test_persistence.py b/testsuite/MDAnalysisTests/utils/test_persistence.py index b3fab89a04a..e5a3679d2da 100644 --- a/testsuite/MDAnalysisTests/utils/test_persistence.py +++ b/testsuite/MDAnalysisTests/utils/test_persistence.py @@ -20,10 +20,8 @@ # MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations. # J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 # -from __future__ import absolute_import - import pytest -from six.moves import cPickle +import pickle import MDAnalysis as mda from numpy.testing import ( @@ -64,23 +62,23 @@ def ag_n(universe_n): @staticmethod @pytest.fixture() def pickle_str(ag): - return cPickle.dumps(ag, protocol=cPickle.HIGHEST_PROTOCOL) + return pickle.dumps(ag, protocol=pickle.HIGHEST_PROTOCOL) @staticmethod @pytest.fixture() def pickle_str_n(ag_n): - return cPickle.dumps(ag_n, protocol=cPickle.HIGHEST_PROTOCOL) + return pickle.dumps(ag_n, protocol=pickle.HIGHEST_PROTOCOL) def test_unpickle(self, pickle_str, ag, universe): """Test that an AtomGroup can be unpickled (Issue 293)""" - newag = cPickle.loads(pickle_str) + newag = pickle.loads(pickle_str) # Can unpickle assert_equal(ag.indices, newag.indices) assert newag.universe is universe, "Unpickled AtomGroup on wrong Universe." def test_unpickle_named(self, pickle_str_n, ag_n, universe_n): """Test that an AtomGroup can be unpickled (Issue 293)""" - newag = cPickle.loads(pickle_str_n) + newag = pickle.loads(pickle_str_n) # Can unpickle assert_equal(ag_n.indices, newag.indices) assert newag.universe is universe_n, "Unpickled AtomGroup on wrong Universe." @@ -91,16 +89,16 @@ def test_unpickle_missing(self): anchor_name="test1") ag = universe.atoms[:20] # prototypical AtomGroup ag_n = universe_n.atoms[:10] - pickle_str_n = cPickle.dumps(ag_n, protocol=cPickle.HIGHEST_PROTOCOL) + pickle_str_n = pickle.dumps(ag_n, protocol=pickle.HIGHEST_PROTOCOL) # Kill AtomGroup and Universe del ag_n del universe_n # and make sure they're very dead gc.collect() # we shouldn't be able to unpickle - # assert_raises(RuntimeError, cPickle.loads, pickle_str_n) + # assert_raises(RuntimeError, pickle.loads, pickle_str_n) with pytest.raises(RuntimeError): - cPickle.loads(pickle_str_n) + pickle.loads(pickle_str_n) def test_unpickle_noanchor(self, universe, pickle_str): # Shouldn't unpickle if the universe is removed from the anchors @@ -108,9 +106,9 @@ def test_unpickle_noanchor(self, universe, pickle_str): # In the complex (parallel) testing environment there's the risk of # other compatible Universes being available for anchoring even after # this one is expressly removed. - # assert_raises(RuntimeError, cPickle.loads, pickle_str) + # assert_raises(RuntimeError, pickle.loads, pickle_str) with pytest.raises(RuntimeError): - cPickle.loads(pickle_str) + pickle.loads(pickle_str) # If this fails to raise an exception either: # 1-the anchoring Universe failed to remove_anchor or 2-another # Universe with the same characteristics was created for testing and is @@ -121,7 +119,7 @@ def test_unpickle_reanchor(self, universe, pickle_str, ag): universe.remove_anchor() # now it goes back into the anchor list again universe.make_anchor() - newag = cPickle.loads(pickle_str) + newag = pickle.loads(pickle_str) assert_equal(ag.indices, newag.indices) assert newag.universe is universe, "Unpickled AtomGroup on wrong Universe." @@ -131,22 +129,22 @@ def test_unpickle_wrongname(self, universe_n, pickle_str_n): # shouldn't unpickle if no name matches, even if there's a compatible # universe in the unnamed anchor list. with pytest.raises(RuntimeError): - cPickle.loads(pickle_str_n) + pickle.loads(pickle_str_n) def test_unpickle_rename(self, universe_n, universe, pickle_str_n, ag_n): # we change universe_n's anchor_name universe_n.anchor_name = "test2" # and make universe a named anchor universe.anchor_name = "test1" - newag = cPickle.loads(pickle_str_n) + newag = pickle.loads(pickle_str_n) assert_equal(ag_n.indices, newag.indices) assert newag.universe is universe, "Unpickled AtomGroup on wrong Universe." def test_pickle_unpickle_empty(self, universe): """Test that an empty AtomGroup can be pickled/unpickled (Issue 293)""" ag = universe.atoms[[]] - pickle_str = cPickle.dumps(ag, protocol=cPickle.HIGHEST_PROTOCOL) - newag = cPickle.loads(pickle_str) + pickle_str = pickle.dumps(ag, protocol=pickle.HIGHEST_PROTOCOL) + newag = pickle.loads(pickle_str) assert len(newag) == 0 @@ -160,15 +158,15 @@ def u(): def test_pickling_uag(self, u): ag = u.atoms[:100] uag = ag.select_atoms('name C', updating=True) - pickle_str = cPickle.dumps(uag, protocol=cPickle.HIGHEST_PROTOCOL) - new_uag = cPickle.loads(pickle_str) + pickle_str = pickle.dumps(uag, protocol=pickle.HIGHEST_PROTOCOL) + new_uag = pickle.loads(pickle_str) assert_equal(uag.indices, new_uag.indices) def test_pickling_uag_of_uag(self, u): uag1 = u.select_atoms('name C or name H', updating=True) uag2 = uag1.select_atoms('name C', updating=True) - pickle_str = cPickle.dumps(uag2, protocol=cPickle.HIGHEST_PROTOCOL) - new_uag2 = cPickle.loads(pickle_str) + pickle_str = pickle.dumps(uag2, protocol=pickle.HIGHEST_PROTOCOL) + new_uag2 = pickle.loads(pickle_str) assert_equal(uag2.indices, new_uag2.indices) diff --git a/testsuite/MDAnalysisTests/utils/test_qcprot.py b/testsuite/MDAnalysisTests/utils/test_qcprot.py index 8c6a3331b0e..f7166b74cc9 100644 --- a/testsuite/MDAnalysisTests/utils/test_qcprot.py +++ b/testsuite/MDAnalysisTests/utils/test_qcprot.py @@ -36,8 +36,6 @@ [-0.0271479 -0.67963547 0.73304748]] """ -from __future__ import division, absolute_import - import numpy as np import MDAnalysis.lib.qcprot as qcp diff --git a/testsuite/MDAnalysisTests/utils/test_selections.py b/testsuite/MDAnalysisTests/utils/test_selections.py index e42f25a7161..32ab90d8a69 100644 --- a/testsuite/MDAnalysisTests/utils/test_selections.py +++ b/testsuite/MDAnalysisTests/utils/test_selections.py @@ -22,10 +22,9 @@ # # Test the selection exporters in MDAnalysis.selections -from __future__ import absolute_import # use StringIO and NamedStream to write to memory instead to temp files import pytest -from six.moves import StringIO +from io import StringIO import re diff --git a/testsuite/MDAnalysisTests/utils/test_streamio.py b/testsuite/MDAnalysisTests/utils/test_streamio.py index 6dbb8073ed6..c5f66a615f4 100644 --- a/testsuite/MDAnalysisTests/utils/test_streamio.py +++ b/testsuite/MDAnalysisTests/utils/test_streamio.py @@ -20,12 +20,9 @@ # MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations. # J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 # -from __future__ import absolute_import - from os.path import abspath, basename, dirname, expanduser, normpath, relpath, split, splitext -import six -from six.moves import range, cStringIO, StringIO +from io import StringIO import pytest import numpy as np @@ -62,17 +59,6 @@ def test_file(self): with open(datafiles.PSF) as obj: assert_equal(util.isstream(obj), True) - def test_cStringIO_read(self): - with open(datafiles.PSF, "r") as f: - obj = cStringIO(f.read()) - assert_equal(util.isstream(obj), True) - obj.close() - - def test_cStringIO_write(self): - obj = cStringIO() - assert_equal(util.isstream(obj), True) - obj.close() - def test_StringIO_read(self): with open(datafiles.PSF, "r") as f: obj = StringIO(f.read()) @@ -96,14 +82,14 @@ class TestNamedStream(object): textname = "jabberwock.txt" def test_closing(self): - obj = cStringIO("".join(self.text)) + obj = StringIO("".join(self.text)) ns = util.NamedStream(obj, self.textname, close=True) assert_equal(ns.closed, False) ns.close() assert_equal(ns.closed, True) def test_closing_force(self): - obj = cStringIO("".join(self.text)) + obj = StringIO("".join(self.text)) ns = util.NamedStream(obj, self.textname) assert_equal(ns.closed, False) ns.close() @@ -111,8 +97,8 @@ def test_closing_force(self): ns.close(force=True) assert_equal(ns.closed, True) - def test_cStringIO_read(self): - obj = cStringIO("".join(self.text)) + def test_StringIO_read(self): + obj = StringIO("".join(self.text)) ns = util.NamedStream(obj, self.textname) assert_equal(ns.name, self.textname) assert_equal(str(ns), self.textname) @@ -131,8 +117,8 @@ def test_File_read(self): assert_equal(len(ns.readlines()), self.numlines) ns.close(force=True) - def test_cStringIO_write(self): - obj = cStringIO() + def test_StringIO_write(self): + obj = StringIO() ns = util.NamedStream(obj, self.textname) ns.writelines(self.text) assert_equal(ns.name, self.textname) @@ -159,7 +145,7 @@ def test_File_write(self, tmpdir): assert_equal("".join(text), "".join(self.text)) def test_matryoshka(self): - obj = cStringIO() + obj = StringIO() ns = util.NamedStream(obj, 'r') with pytest.warns(RuntimeWarning): ns2 = util.NamedStream(ns, 'f') @@ -175,7 +161,7 @@ class TestNamedStream_filename_behavior(object): def create_NamedStream(self, name=None): if name is None: name = self.textname - obj = cStringIO() + obj = StringIO() return util.NamedStream(obj, name) @pytest.mark.parametrize('func', ( @@ -274,7 +260,7 @@ class _StreamData(object): def __init__(self): self.buffers = {name: "".join(open(fn).readlines()) - for name, fn in six.iteritems(self.filenames)} + for name, fn in self.filenames.items()} self.filenames['XYZ_PSF'] = u"bogus/path/mini.psf" self.buffers['XYZ_PSF'] = u"""\ PSF CMAP @@ -330,11 +316,8 @@ def __init__(self): def as_StringIO(self, name): return StringIO(self.buffers[name]) - def as_cStringIO(self, name): - return cStringIO(self.buffers[name]) - def as_NamedStream(self, name): - return util.NamedStream(self.as_cStringIO(name), self.filenames[name]) + return util.NamedStream(self.as_StringIO(name), self.filenames[name]) streamData = _StreamData() diff --git a/testsuite/MDAnalysisTests/utils/test_transformations.py b/testsuite/MDAnalysisTests/utils/test_transformations.py index 1878b9800f8..28811047560 100644 --- a/testsuite/MDAnalysisTests/utils/test_transformations.py +++ b/testsuite/MDAnalysisTests/utils/test_transformations.py @@ -20,9 +20,6 @@ # MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations. # J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 # -from __future__ import division, absolute_import - -from six.moves import range from itertools import permutations import numpy as np diff --git a/testsuite/MDAnalysisTests/utils/test_units.py b/testsuite/MDAnalysisTests/utils/test_units.py index e01985be598..70301cd3e7d 100644 --- a/testsuite/MDAnalysisTests/utils/test_units.py +++ b/testsuite/MDAnalysisTests/utils/test_units.py @@ -20,8 +20,6 @@ # MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations. # J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 # -from __future__ import unicode_literals, absolute_import -import six import pytest import numpy as np diff --git a/testsuite/MDAnalysisTests/visualization/test_streamlines.py b/testsuite/MDAnalysisTests/visualization/test_streamlines.py index 333d8fda495..3c8a1b23585 100644 --- a/testsuite/MDAnalysisTests/visualization/test_streamlines.py +++ b/testsuite/MDAnalysisTests/visualization/test_streamlines.py @@ -20,7 +20,6 @@ # MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations. # J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 # -from __future__ import absolute_import, print_function, division import numpy as np from numpy.testing import assert_almost_equal import MDAnalysis