Issue #41 cleaning up some pycodestyle things

This commit is contained in:
Doug 2020-03-12 11:35:12 -04:00
parent 585d095221
commit 46b19392d5
14 changed files with 28 additions and 23 deletions

View File

@ -12,6 +12,7 @@ try:
except ImportError:
from io import StringIO
@contextlib.contextmanager
def redirect_stdout():
"""Redirect stdout to a stream, which is then yielded."""
@ -47,8 +48,8 @@ class CLIHeadlessTests(unittest.TestCase):
json.dumps(datastack_dict, indent=4, sort_keys=True))
with unittest.mock.patch(
'natcap.invest.fisheries.fisheries.execute',
return_value=None) as patched_model:
'natcap.invest.fisheries.fisheries.execute',
return_value=None) as patched_model:
cli.main([
'run',
'fisheries', # uses an exact modelname
@ -57,7 +58,6 @@ class CLIHeadlessTests(unittest.TestCase):
])
patched_model.assert_called_once()
def test_run_fisheries(self):
"""CLI: Run the fisheries model through the cli."""
from natcap.invest import cli
@ -66,8 +66,8 @@ class CLIHeadlessTests(unittest.TestCase):
'fisheries', 'spiny_lobster_belize.invs.json')
with unittest.mock.patch(
'natcap.invest.fisheries.fisheries.execute',
return_value=None) as patched_model:
'natcap.invest.fisheries.fisheries.execute',
return_value=None) as patched_model:
cli.main([
'run',
'fisheries', # uses an exact modelname

View File

@ -964,6 +964,7 @@ class CBCRefactorTest(unittest.TestCase):
numpy.testing.assert_almost_equal(reclassified_array, expected_array)
class CBCValidationTests(unittest.TestCase):
"""Tests for Coastal Blue Carbon Model ARGS_SPEC and validation."""

View File

@ -1212,7 +1212,7 @@ class CoastalVulnerabilityTests(unittest.TestCase):
habitat_table_path = os.path.join(self.workspace_dir, 'bad_table.csv')
df = pandas.DataFrame(
columns=['id','path','rank','protection distance (m)'],
columns=['id', 'path', 'rank', 'protection distance (m)'],
data=[['foo', 'bad_path.shp', 3, 400]])
df.to_csv(habitat_table_path)
with self.assertRaises(ValueError) as cm:

View File

@ -296,6 +296,7 @@ class CropProductionTests(unittest.TestCase):
pandas.testing.assert_frame_equal(
expected_result_table, result_table, check_dtype=False)
class CropValidationTests(unittest.TestCase):
"""Tests for the Crop Productions' ARGS_SPEC and validation."""
@ -333,4 +334,5 @@ class CropValidationTests(unittest.TestCase):
expected_missing_keys = set(
self.base_required_keys +
['fertilization_rate_table_path'])
self.assertEqual(invalid_keys, expected_missing_keys)
self.assertEqual(invalid_keys, expected_missing_keys)

View File

@ -295,6 +295,7 @@ class ForestCarbonEdgeTests(unittest.TestCase):
gdal.Dataset.__swig_destroy__(result_vector)
result_vector = None
class ForestCarbonEdgeValidationTests(unittest.TestCase):
"""Tests for the Forest Carbon Model ARGS_SPEC and validation."""
@ -338,4 +339,4 @@ class ForestCarbonEdgeValidationTests(unittest.TestCase):
'biomass_to_carbon_conversion_factor'])
expected_missing_keys.difference_update(
{'compute_forest_edge_effects'})
self.assertEqual(invalid_keys, expected_missing_keys)
self.assertEqual(invalid_keys, expected_missing_keys)

View File

@ -233,6 +233,7 @@ class GLOBIOTests(unittest.TestCase):
gdal.Dataset.__swig_destroy__(result_vector)
result_vector = None
class GlobioValidationTests(unittest.TestCase):
"""Tests for the GLOBIO Model ARGS_SPEC and validation."""
@ -294,4 +295,4 @@ class GlobioValidationTests(unittest.TestCase):
actual_messages = set()
for keys, error_strings in validation_warnings:
actual_messages.add(error_strings)
self.assertTrue(expected_message in actual_messages)
self.assertTrue(expected_message in actual_messages)

View File

@ -13,6 +13,7 @@ SAMPLE_DATA = os.path.join(
REGRESSION_DATA = os.path.join(
os.path.dirname(__file__), '..', 'data', 'invest-test-data', 'hydropower')
class HydropowerTests(unittest.TestCase):
"""Regression Tests for Annual Water Yield Hydropower Model."""

View File

@ -259,7 +259,6 @@ class NDRTests(unittest.TestCase):
]
self.assertEqual(set(invalid_args), set(expected_missing_args))
@staticmethod
def _assert_regression_results_equal(
workspace_dir, result_vector_path, agg_results_path):

View File

@ -413,4 +413,4 @@ class PollinationValidationTests(unittest.TestCase):
validation_errors = pollination.validate({}) # empty args dict.
invalid_keys = validation.get_invalid_keys(validation_errors)
expected_missing_keys = set(self.base_required_keys)
self.assertEqual(invalid_keys, expected_missing_keys)
self.assertEqual(invalid_keys, expected_missing_keys)

View File

@ -212,7 +212,6 @@ class RouteDEMTests(unittest.TestCase):
gdal.OpenEx(os.path.join(
args['workspace_dir'], 'stream_mask_foo.tif')).ReadAsArray())
expected_flow_accum = numpy.empty((10, 9), dtype=numpy.float64)
expected_flow_accum[:, 0:4] = numpy.arange(1, 5)
expected_flow_accum[:, 5:9] = numpy.flipud(numpy.arange(1, 5))

View File

@ -730,8 +730,8 @@ class ScenicQualityValidationTests(unittest.TestCase):
'refraction',
'structure_path',
'workspace_dir',
'valuation_function',
]))
'valuation_function', ])
)
def test_novaluation_required_keys(self):
"""SQ Validate: assert required keys without valuation."""
@ -1012,11 +1012,12 @@ class ViewshedTests(unittest.TestCase):
visibility_filepath = os.path.join(self.workspace_dir,
'visibility.tif')
pygeoprocessing.testing.create_raster_on_disk(
[numpy.ones((10, 10))],
(0, 0), projection_wkt=srs.ExportToWkt(), nodata=-1,
pixel_size=(1, -1), raster_driver_creation_tuple=(
[numpy.ones((10, 10))], (0, 0), projection_wkt=srs.ExportToWkt(),
nodata=-1, pixel_size=(1, -1),
raster_driver_creation_tuple=(
'GTIFF', ('TILED=NO', 'BIGTIFF=YES', 'COMPRESS=LZW',
'BLOCKXSIZE=20', 'BLOCKYSIZE=40')), filename=dem_filepath)
'BLOCKXSIZE=20', 'BLOCKYSIZE=40')),
filename=dem_filepath)
with self.assertRaises(ValueError):
viewshed(

View File

@ -168,7 +168,7 @@ class SDRTests(unittest.TestCase):
self.workspace_dir, 'watershed.shp')
vector = vector_driver.CreateDataSource(test_watershed_path)
srs = osr.SpatialReference()
srs.ImportFromEPSG(26910) #NAD83 / UTM zone 11N
srs.ImportFromEPSG(26910) # NAD83 / UTM zone 11N
layer = vector.CreateLayer("watershed", srs, ogr.wkbPoint)
# forget to add a 'ws_id' field
layer.CreateField(ogr.FieldDefn("ws_id", ogr.OFTInteger))

View File

@ -109,7 +109,7 @@ class UFRMTests(unittest.TestCase):
(args['soils_hydrological_group_raster_path'], 1), value_map,
bad_soil_raster, gdal.GDT_Int16, -9)
args['soils_hydrological_group_raster_path'] = bad_soil_raster
with self.assertRaises(ValueError) as cm:
urban_flood_risk_mitigation.execute(args)
actual_message = str(cm.exception)

View File

@ -198,6 +198,7 @@ class ValidatorTest(unittest.TestCase):
self.assertTrue('could not be interpreted as a number'
in validation_errors[0][1])
class DirectoryValidation(unittest.TestCase):
def setUp(self):
"""Create a new workspace to use for each test."""
@ -247,7 +248,7 @@ class DirectoryValidation(unittest.TestCase):
dirpath = 'foo'
new_dir = os.path.join(self.workspace_dir, dirpath)
self.assertEqual(None, validation.check_directory(
new_dir, exists=False, permissions='rwx'))
@ -465,7 +466,7 @@ class FreestyleStringValidation(unittest.TestCase):
error_msg = validation.check_freestyle_string(
'foobar12', regexp={'pattern': '^[a-zA-Z]+$',
'case_sensitive':True})
'case_sensitive': True})
self.assertTrue('did not match expected pattern' in error_msg)
@ -519,7 +520,6 @@ class NumberValidation(unittest.TestCase):
self.assertTrue('does not meet condition' in error_msg)
class BooleanValidation(unittest.TestCase):
def test_actual_bool(self):
"""Validation: test when boolean type objects are passed."""