Skip to content

Commit

Permalink
Merge pull request #922 from ghoshbishakh/pep8topleveltest
Browse files Browse the repository at this point in the history
Fix PEP8 in top-level tests
  • Loading branch information
arokem committed Feb 15, 2016
2 parents 57a8a9e + 2616ed8 commit 5917814
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
41 changes: 21 additions & 20 deletions dipy/tests/scriptrunner.py
Expand Up @@ -18,22 +18,22 @@

from subprocess import Popen, PIPE

try: # Python 2
try: # Python 2
string_types = basestring,
except NameError: # Python 3
except NameError: # Python 3
string_types = str,


def _get_package():
""" Workaround for missing ``__package__`` in Python 3.2
"""
if '__package__' in globals() and not __package__ is None:
if(('__package__' in globals()) and (__package__ is not None)):
return __package__
return __name__.split('.', 1)[0]


# Same as __package__ for Python 2.6, 2.7 and >= 3.3
MY_PACKAGE=_get_package()
MY_PACKAGE = _get_package()


def local_script_dir(script_sdir):
Expand Down Expand Up @@ -66,12 +66,12 @@ class ScriptRunner(object):
Finds local scripts and local modules if running in the development
directory, otherwise finds system scripts and modules.
"""

def __init__(self,
script_sdir = 'scripts',
module_sdir = MY_PACKAGE,
debug_print_var = None,
output_processor = lambda x : x
):
script_sdir='scripts',
module_sdir=MY_PACKAGE,
debug_print_var=None,
output_processor=lambda x: x):
""" Init ScriptRunner instance
Parameters
Expand Down Expand Up @@ -120,12 +120,13 @@ def run_command(self, cmd, check_code=True):
cmd = [cmd]
else:
cmd = list(cmd)
if not self.local_script_dir is None:
# Windows can't run script files without extensions natively so we need
# to run local scripts (no extensions) via the Python interpreter. On
# Unix, we might have the wrong incantation for the Python interpreter
# in the hash bang first line in the source file. So, either way, run
# the script through the Python interpreter
if self.local_script_dir is not None:
# Windows can't run script files without extensions
# natively so we need to run local scripts (no extensions)
# via the Python interpreter. On Unix, we might have the
# wrong incantation for the Python interpreter
# in the hash bang first line in the source file. So, either way,
# run the script through the Python interpreter
cmd = [sys.executable,
pjoin(self.local_script_dir, cmd[0])] + cmd[1:]
elif os.name == 'nt':
Expand All @@ -139,10 +140,10 @@ def run_command(self, cmd, check_code=True):
if self.debug_print:
print("Running command '%s'" % cmd)
env = os.environ
if not self.local_module_dir is None:
# module likely comes from the current working directory. We might need
# that directory on the path if we're running the scripts from a
# temporary directory
if self.local_module_dir is not None:
# module likely comes from the current working directory.
# We might need that directory on the path if we're running
# the scripts from a temporary directory
env = env.copy()
pypath = env.get('PYTHONPATH', None)
if pypath is None:
Expand All @@ -151,7 +152,7 @@ def run_command(self, cmd, check_code=True):
env['PYTHONPATH'] = self.local_module_dir + pathsep + pypath
proc = Popen(cmd, stdout=PIPE, stderr=PIPE, env=env)
stdout, stderr = proc.communicate()
if proc.poll() == None:
if proc.poll() is None:
proc.terminate()
if check_code and proc.returncode != 0:
raise RuntimeError(
Expand Down
11 changes: 7 additions & 4 deletions dipy/tests/test_scripts.py
Expand Up @@ -19,7 +19,7 @@

from dipy.data import get_data

# Quickbundles command-line requires matplotlib:
# Quickbundles command-line requires matplotlib:
try:
import matplotlib
no_mpl = False
Expand All @@ -29,12 +29,13 @@
from .scriptrunner import ScriptRunner

runner = ScriptRunner(
script_sdir = 'bin',
debug_print_var = 'NIPY_DEBUG_PRINT')
script_sdir='bin',
debug_print_var='NIPY_DEBUG_PRINT')
run_command = runner.run_command

DATA_PATH = abspath(pjoin(dirname(__file__), 'data'))


def test_dipy_peak_extraction():
# test dipy_peak_extraction script
cmd = 'dipy_peak_extraction'
Expand Down Expand Up @@ -93,7 +94,8 @@ def test_dipy_fit_tensor_again():
shutil.copyfile(bval, "small_25.bval")
shutil.copyfile(bvec, "small_25.bvec")
# Call script
cmd = ["dipy_fit_tensor", "--save-tensor", "--mask=none", "small_25.nii.gz"]
cmd = ["dipy_fit_tensor", "--save-tensor",
"--mask=none", "small_25.nii.gz"]
out = run_command(cmd)
assert_equal(out[0], 0)
# Get expected values
Expand All @@ -113,6 +115,7 @@ def test_dipy_fit_tensor_again():
assert_image_shape_affine("small_25_tensor.nii.gz", ten_shape,
affine)


@nt.dec.skipif(no_mpl)
def test_qb_commandline():
with InTemporaryDirectory():
Expand Down

0 comments on commit 5917814

Please sign in to comment.