Skip to content

Commit

Permalink
fixing more style errors
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverba137 committed Apr 25, 2017
1 parent d45d651 commit 8a20518
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 69 deletions.
6 changes: 3 additions & 3 deletions py/desiutil/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,9 +472,9 @@ def ellipse(self, x0, y0, a, b, n, ax=None, **kwargs):
# Generate coordinates of a line in galactic coordinates and convert
# to equatorial coordinates.
galactic_l = np.linspace(0, 2 * np.pi, 1000)
galactic_plane = SkyCoord(
l=galactic_l*u.radian, b=np.zeros_like(galactic_l)*u.radian,
frame='galactic').fk5
galactic_plane = SkyCoord(l=galactic_l*u.radian,
b=np.zeros_like(galactic_l)*u.radian,
frame='galactic').fk5
# Project to map coordinates and display. Use a scatter plot to
# avoid wrap-around complications.
galactic_x, galactic_y = m(galactic_plane.ra.degree,
Expand Down
4 changes: 2 additions & 2 deletions py/desiutil/sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def load(filename):
hdus = fits.open(filename, memmap=False)
hdr = hdus[0].header
covtype = hdr['covtype']
model = GaussianMixtureModel(
hdus['weights'].data, hdus['means'].data, hdus['covars'].data, covtype)
model = GaussianMixtureModel(hdus['weights'].data, hdus['means'].data,
hdus['covars'].data, covtype)
hdus.close()
return model

Expand Down
4 changes: 3 additions & 1 deletion py/desiutil/test/test_bitmask.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ def test_str(self):
self.assertEqual(bitmask[name].bitnum, self.ccdmask[name].bitnum)
self.assertEqual(bitmask[name]._extra, self.ccdmask[name]._extra)

@unittest.skipIf(sys.version_info.major == 2, "Known issue: highest mask bits don't work under python 2")
@unittest.skipIf(sys.version_info.major == 2,
"Known issue: highest mask bits don't work under " +
"Python 2")
def test_highbit(self):
_bitdefs = dict(ccdmask=list())
_bitdefs['ccdmask'].append(['LOWEST', 0, "bit 0"])
Expand Down
21 changes: 14 additions & 7 deletions py/desiutil/test/test_census.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def test_get_options(self):
options = get_options(['-c', 'foo.yaml'])
self.assertEqual(options.config, 'foo.yaml')

@unittest.skipUnless(has_mock, "Skipping test that requires unittest.mock.")
@unittest.skipUnless(has_mock,
"Skipping test that requires unittest.mock.")
def test_walk_error(self):
"""Test error-handling function for os.walk().
"""
Expand All @@ -75,7 +76,8 @@ def test_walk_error(self):
raise OSError(2, 'File not found', 'foo.txt', None, 'bar.txt')
except OSError as e:
walk_error(e)
calls = [call.error("[Errno 2] File not found: 'foo.txt' -> 'bar.txt'")]
calls = [call.error("[Errno 2] File not found: 'foo.txt' -> " +
"'bar.txt'")]
self.assertListEqual(mock.mock_calls, calls)

def test_year(self):
Expand All @@ -87,7 +89,8 @@ def test_year(self):
self.assertEqual(year(mtime), 2017)
self.assertEqual(year(mtime, fy=False), 2016)

@unittest.skipUnless(has_mock, "Skipping test that requires unittest.mock.")
@unittest.skipUnless(has_mock,
"Skipping test that requires unittest.mock.")
def test_scan_file(self):
"""Test analysis of a single file.
"""
Expand All @@ -108,7 +111,8 @@ def test_scan_file(self):
calls = [call.debug("os.stat('{0}')".format(fd)),
call.warning("{0} does not have correct group id!".format(fd))]
with patch('desiutil.log.desi_logger') as mock_log:
with patch.dict('sys.modules', {'os': mock_os, 'os.path': mock_os.path}):
with patch.dict('sys.modules', {'os': mock_os,
'os.path': mock_os.path}):
mock_os.environ = dict()
mock_os.stat.return_value = s
mock_os.path.islink.return_value = False
Expand All @@ -127,7 +131,8 @@ def test_scan_file(self):
call.warning("{0} does not have correct group id!".format(fd)),
call.debug("Found internal link {0} -> {0}.link.".format(fd))]
with patch('desiutil.log.desi_logger') as mock_log:
with patch.dict('sys.modules', {'os': mock_os, 'os.path': mock_os.path}):
with patch.dict('sys.modules', {'os': mock_os,
'os.path': mock_os.path}):
mock_os.environ = dict()
mock_os.stat.return_value = s
mock_os.lstat.return_value = s
Expand All @@ -151,7 +156,8 @@ def test_scan_file(self):
call.warning("{0} does not have correct group id!".format(fd)),
call.debug("Found external link {0} -> {1}.".format(fd, extlink))]
with patch('desiutil.log.desi_logger') as mock_log:
with patch.dict('sys.modules', {'os': mock_os, 'os.path': mock_os.path}):
with patch.dict('sys.modules', {'os': mock_os,
'os.path': mock_os.path}):
mock_os.environ = dict()
mock_os.stat.return_value = s
mock_os.lstat.return_value = s
Expand All @@ -167,7 +173,8 @@ def test_scan_file(self):
self.assertTrue(f.isexternal)
self.assertEqual(f.linkname, extlink)

@unittest.skipUnless(has_commonpath, "Skipping test that requires os.path.commonpath().")
@unittest.skipUnless(has_commonpath,
"Skipping test that requires os.path.commonpath().")
def test_in_path(self):
"""Test directory hierarchy checker.
"""
Expand Down
4 changes: 3 additions & 1 deletion py/desiutil/test/test_funcfits.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ def test_iterfit2(self):
# simplefilter("always")
dfit, mask = iter_fit(x, y, 'legendre', 4, forceimask=True)
self.assertEqual(len(w), 1)
self.assertEqual(str(w[-1].message), "Initial mask cannot be enforced -- no initital mask supplied")
self.assertEqual(str(w[-1].message),
"Initial mask cannot be enforced -- " +
"no initital mask supplied")
x2 = np.linspace(0, np.pi, 100)
y2 = func_val(x2, dfit)
np.testing.assert_allclose(y2[50], 0.99941444872371643)
Expand Down
8 changes: 4 additions & 4 deletions py/desiutil/test/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ def test_sanity_check(self):
def test_get_product_version(self):
"""Test resolution of product/version input.
"""
ini = 'desiInstall_configuration.ini'
options = self.desiInstall.get_options(['foo', 'bar'])
out = self.desiInstall.get_product_version()
self.assertEqual(out, (u'https://github.com/desihub/foo',
Expand All @@ -178,8 +179,7 @@ def test_get_product_version(self):
self.assertEqual(out, (u'https://github.com/desihub/desispec',
'desispec', '2.0.0'))
options = self.desiInstall.get_options(['--configuration',
join(self.data_dir,
'desiInstall_configuration.ini'),
join(self.data_dir, ini),
'my_new_product', '1.2.3'])
out = self.desiInstall.get_product_version()
self.assertEqual(out, (u'https://github.com/me/my_new_product',
Expand Down Expand Up @@ -363,6 +363,7 @@ def test_start_modules(self):
def test_nersc_module_dir(self):
"""Test the nersc_module_dir property.
"""
ini = 'desiInstall_configuration.ini'
self.assertIsNone(self.desiInstall.nersc_module_dir)
self.desiInstall.nersc = None
self.assertIsNone(self.desiInstall.nersc_module_dir)
Expand All @@ -372,8 +373,7 @@ def test_nersc_module_dir(self):
join(self.desiInstall.default_nersc_dir[n],
"modulefiles"))
options = self.desiInstall.get_options(['--configuration',
join(self.data_dir,
'desiInstall_configuration.ini'),
join(self.data_dir, ini),
'my_new_product', '1.2.3'])
self.desiInstall.nersc = 'edison'
self.assertEqual(self.desiInstall.nersc_module_dir,
Expand Down
56 changes: 16 additions & 40 deletions py/desiutil/test/test_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""
from __future__ import absolute_import, print_function
import unittest
import desiutil.log as l
import desiutil.log as dul


class TestLog(unittest.TestCase):
Expand All @@ -19,41 +19,37 @@ def setUp(self):
self.desi_level = environ['DESI_LOGLEVEL']
except KeyError:
self.desi_level = None
l.desi_logger = None
dul.desi_logger = None

def test_log(self):
"""Test basic logging functionality.
def run_logs(self, **kwargs):
"""Loop over log levels.
"""
for level in (None, l.DEBUG, l.INFO, l.WARNING, l.ERROR):
logger = l.get_logger(level)
for level in (None, dul.DEBUG, dul.INFO, dul.WARNING, dul.ERROR):
logger = dul.get_logger(level, **kwargs)
print("With the requested debugging level={0}:".format(level))
if self.desi_level is not None and (self.desi_level != ""):
print(" (but overuled by env. DESI_LOGLEVEL='{0}')".format(self.desi_level))
print((" (but overuled by env. " +
"DESI_LOGLEVEL='{0}')").format(self.desi_level))
print("--------------------------------------------------")
logger.debug("This is a debugging message.")
logger.info("This is an informational message.")
logger.warning("This is a warning message.")
logger.error("This is an error message.")
logger.critical("This is a critical error message.")

def test_log(self):
"""Test basic logging functionality.
"""
self.run_logs()

def test_log_with_desi_loglevel(self):
"""Test basic logging functionality with DESI_LOGLEVEL set.
"""
from os import environ
desi_level_cache = self.desi_level
for lvl in ('warning', 'foobar'):
self.desi_level = environ['DESI_LOGLEVEL'] = lvl
for level in (None, l.DEBUG, l.INFO, l.WARNING, l.ERROR):
logger = l.get_logger(level)
print("With the requested debugging level={0}:".format(level))
if self.desi_level is not None and (self.desi_level != ""):
print(" (but overuled by env. DESI_LOGLEVEL='{0}')".format(self.desi_level))
print("--------------------------------------------------")
logger.debug("This is a debugging message.")
logger.info("This is an informational message.")
logger.warning("This is a warning message.")
logger.error("This is an error message.")
logger.critical("This is a critical error message.")
self.run_logs()
if desi_level_cache is None:
del environ['DESI_LOGLEVEL']
self.desi_level = None
Expand All @@ -64,32 +60,12 @@ def test_log_with_desi_loglevel(self):
def test_log_with_timestamp(self):
"""Test logging with timestamps.
"""
for level in (None, l.DEBUG, l.INFO, l.WARNING, l.ERROR):
logger = l.get_logger(level, timestamp=True)
print("With the requested debugging level={0}:".format(level))
if self.desi_level is not None and (self.desi_level != ""):
print(" (but overuled by env. DESI_LOGLEVEL='{0}'):".format(self.desi_level))
print("--------------------------------------------------")
logger.debug("This is a debugging message.")
logger.info("This is an informational message.")
logger.warning("This is a warning message.")
logger.error("This is an error message.")
logger.critical("This is a critical error message.")
self.run_logs(timestamp=True)

def test_log_with_delimiter(self):
"""Test logging with alternate delimiter.
"""
for level in (None, l.DEBUG, l.INFO, l.WARNING, l.ERROR):
logger = l.get_logger(level, delimiter=' -- ')
print("With the requested debugging level={0}:".format(level))
if self.desi_level is not None and (self.desi_level != ""):
print(" (but overuled by env. DESI_LOGLEVEL='{0}'):".format(self.desi_level))
print("--------------------------------------------------")
logger.debug("This is a debugging message.")
logger.info("This is an informational message.")
logger.warning("This is a warning message.")
logger.error("This is an error message.")
logger.critical("This is a critical error message.")
self.run_logs(delimiter=' -- ')


def test_suite():
Expand Down
6 changes: 4 additions & 2 deletions py/desiutil/test/test_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,14 @@ def test_init_modules(self):
#
self.cache_env(('MODULE_VERSION', 'MODULE_VERSION_STACK', 'TCLSH'))
modulecmd = init_modules(command=True)
self.assertListEqual(modulecmd, [join(self.bin_dir, 'modulecmd'), 'python'])
self.assertListEqual(modulecmd, [join(self.bin_dir, 'modulecmd'),
'python'])
tclfile = join(self.data_dir, 'modulecmd.tcl')
with open(tclfile, 'w') as tcl:
tcl.write('#!/usr/bin/tclsh\nputs "foo"\n')
modulecmd = init_modules(command=True)
self.assertListEqual(modulecmd, [join(self.bin_dir, 'tclsh'), tclfile, 'python'])
self.assertListEqual(modulecmd, [join(self.bin_dir, 'tclsh'), tclfile,
'python'])
environ['TCLSH'] = '/opt/local/bin/tclsh'
modulecmd = init_modules(command=True)
self.assertListEqual(modulecmd, ['/opt/local/bin/tclsh', tclfile,
Expand Down
24 changes: 16 additions & 8 deletions py/desiutil/test/test_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ def test_prepare_data(self):
self.assertFalse(ma.mask.any())
ma = prepare_data(data, mask)
self.assertTrue(np.allclose(data, ma.data))
self.assertTrue((ma.mask == np.array([False, False, True, False, False])).all())
self.assertTrue((ma.mask == np.array([False, False, True, False,
False])).all())
data2 = data.copy()
data2[0] = 0.25
data3 = data.copy()
Expand All @@ -88,19 +89,25 @@ def test_prepare_data(self):
data4[-1] = 3.25
ma = prepare_data(data, mask, clip_lo=0.25)
self.assertTrue(np.allclose(data2, ma.data))
self.assertTrue((ma.mask == np.array([False, False, True, False, False])).all())
self.assertTrue((ma.mask == np.array([False, False, True, False,
False])).all())
ma = prepare_data(data, mask, clip_lo=0.25, clip_hi=0.75)
self.assertTrue(np.allclose(data3, ma.data))
self.assertTrue((ma.mask == np.array([False, False, True, False, False])).all())
self.assertTrue((ma.mask == np.array([False, False, True, False,
False])).all())
ma = prepare_data(data, mask, clip_lo='25%', clip_hi='75%')
self.assertTrue(np.allclose(data4, ma.data))
self.assertTrue((ma.mask == np.array([False, False, True, False, False])).all())
self.assertTrue((ma.mask == np.array([False, False, True, False,
False])).all())
ma = prepare_data(data, mask, clip_lo='!25%', clip_hi='!75%')
self.assertTrue(np.allclose(data4, ma.data))
self.assertTrue((ma.mask == np.array([True, False, True, False, True])).all())
ma = prepare_data(data, mask, clip_lo='25%', clip_hi='75%', save_limits=True)
self.assertTrue((ma.mask == np.array([True, False, True, False,
True])).all())
ma = prepare_data(data, mask, clip_lo='25%', clip_hi='75%',
save_limits=True)
self.assertTrue(np.allclose(data4, ma.data))
self.assertTrue((ma.mask == np.array([False, False, True, False, False])).all())
self.assertTrue((ma.mask == np.array([False, False, True, False,
False])).all())
self.assertEqual(ma.vmin, 0.75)
self.assertEqual(ma.vmax, 3.25)

Expand Down Expand Up @@ -147,7 +154,8 @@ def test_plot_sky_circles(self):
from ..plots import plot_sky_circles

@unittest.skipIf(not (have_matplotlib and have_healpy and have_basemap),
'Skipping tests that require matplotlib, healpy and basemap.')
('Skipping tests that require matplotlib, healpy ' +
'and basemap.'))
def test_plot_sky_binned(self):
"""Test plot_sky_binned
"""
Expand Down
3 changes: 2 additions & 1 deletion py/desiutil/test/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def test_version(self):
s.write(setup)
init = """from ._version import __version__
"""
with open(os.path.join(package_dir, self.fake_name, '__init__.py'), 'w') as i:
with open(os.path.join(package_dir, self.fake_name,
'__init__.py'), 'w') as i:
i.write(init)
os.chdir(package_dir)
v_file = os.path.join(package_dir, self.fake_name, '_version.py')
Expand Down

0 comments on commit 8a20518

Please sign in to comment.