Skip to content

Commit

Permalink
-added new test_imports.py module to enforce the ban on relative impo…
Browse files Browse the repository at this point in the history
…rts in unit testing modules (Issue #189)

-manually repaired unit testing modules caught by above unit testing of import statements
  • Loading branch information
tylerjereddy committed Jun 15, 2015
1 parent d77bd84 commit c074991
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 11 deletions.
2 changes: 1 addition & 1 deletion testsuite/MDAnalysisTests/test_altloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import tempfile
import os
from numpy.testing import *
from .datafiles import altloc
from MDAnalysisTests.datafiles import altloc


class TestAltloc(TestCase):
Expand Down
2 changes: 1 addition & 1 deletion testsuite/MDAnalysisTests/test_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import itertools
import warnings

from MDAnalysis.tests.datafiles import PSF, DCD, FASTA, PDB_helix, PDB_HOLE, XTC_HOLE, GRO, XTC, waterDCD, waterPSF
from MDAnalysisTests.datafiles import PSF, DCD, FASTA, PDB_helix, PDB_HOLE, XTC_HOLE, GRO, XTC, waterDCD, waterPSF
from MDAnalysisTests import executable_not_found_runtime


Expand Down
2 changes: 1 addition & 1 deletion testsuite/MDAnalysisTests/test_atomgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import tempfile
import itertools

from . import knownfailure
from MDAnalysisTests import knownfailure

try:
from numpy.testing import assert_
Expand Down
6 changes: 3 additions & 3 deletions testsuite/MDAnalysisTests/test_coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from nose.plugins.attrib import attr
import warnings

from .datafiles import (
from MDAnalysisTests.datafiles import (
PSF, DCD, DCD_empty, PDB_small, XPDB_small, PDB_closed, PDB_multiframe,
PDB, CRD, XTC, TRR, GRO, DMS, CONECT,
XYZ, XYZ_bz2, XYZ_psf, PRM, TRJ, TRJ_bz2, PRMpbc, TRJpbc_bz2, PRMncdf, NCDF, PQR,
Expand All @@ -38,7 +38,7 @@
DLP_CONFIG, DLP_CONFIG_order, DLP_CONFIG_minimal,
DLP_HISTORY, DLP_HISTORY_order, DLP_HISTORY_minimal)

from . import knownfailure
from MDAnalysisTests import knownfailure

import os
import shutil
Expand Down Expand Up @@ -2978,7 +2978,7 @@ def test_datareader_VE():
class _TestLammpsData_Coords(TestCase):
"""Tests using a .data file for loading single frame.
All topology loading from .data is done in test_topology
All topology loading from MDAnalysisTests.data is done in test_topology
"""

def setUp(self):
Expand Down
49 changes: 49 additions & 0 deletions testsuite/MDAnalysisTests/test_imports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -*- 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
#
from __future__ import print_function
import MDAnalysis

from numpy.testing import *
from nose.plugins.attrib import attr

#import os
#import errno
#import tempfile
#import itertools
#import warnings
import glob

from MDAnalysis.tests.datafiles import PSF, DCD, FASTA, PDB_helix, PDB_HOLE, XTC_HOLE, GRO, XTC, waterDCD, waterPSF


class TestRelativeImports(TestCase):
'''Relative imports are banned in unit testing modules (Issue #189), so run tests to enforce this policy.'''

def setUp(self):
self.path_to_testing_modules = './'

def tearDown(self):
del self.path_to_testing_modules

def test_relative_imports(self):
list_testing_modules = glob.glob(self.path_to_testing_modules + '*.py')
for testing_module in list_testing_modules:
relative_import_counts = 0
with open(testing_module, 'r') as test_module_file_object:
for line in test_module_file_object:
if 'from .' in line and 'import' in line and not 'test_imports' in testing_module:
relative_import_counts += 1
assert_equal(relative_import_counts, 0, "A relative import statement was found in module {module_name}.".format(module_name = testing_module))
2 changes: 1 addition & 1 deletion testsuite/MDAnalysisTests/test_mol2.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import os
from numpy.testing import *

from .datafiles import mol2_molecules, mol2_molecule, mol2_broken_molecule
from MDAnalysisTests.datafiles import mol2_molecules, mol2_molecule, mol2_broken_molecule
from MDAnalysis import Universe


Expand Down
4 changes: 2 additions & 2 deletions testsuite/MDAnalysisTests/test_streamio.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import MDAnalysis
import MDAnalysis.core.util as util
import MDAnalysis.tests.datafiles as datafiles
from .test_coordinates import RefAdKSmall
from . import knownfailure
from MDAnalysisTests.test_coordinates import RefAdKSmall
from MDAnalysisTests import knownfailure

import StringIO
import cStringIO
Expand Down
4 changes: 2 additions & 2 deletions testsuite/MDAnalysisTests/test_timestep_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
assert_array_almost_equal)
from nose.plugins.attrib import attr
from nose.tools import assert_not_equal
from . import knownfailure
from MDAnalysisTests import knownfailure

import MDAnalysis as mda

from .datafiles import PSF, DCD, DCD_empty, PDB_small, XPDB_small, PDB_closed, PDB_multiframe, \
from MDAnalysisTests.datafiles import PSF, DCD, DCD_empty, PDB_small, XPDB_small, PDB_closed, PDB_multiframe, \
PDB, CRD, XTC, TRR, GRO, DMS, CONECT, \
XYZ, XYZ_bz2, XYZ_psf, PRM, TRJ, TRJ_bz2, PRMpbc, TRJpbc_bz2, PRMncdf, NCDF, PQR, \
PDB_sub_dry, TRR_sub_sol, PDB_sub_sol, TRZ, TRZ_psf, LAMMPSdata, LAMMPSdata_mini, \
Expand Down

0 comments on commit c074991

Please sign in to comment.