Skip to content

Commit

Permalink
Fix error types
Browse files Browse the repository at this point in the history
  • Loading branch information
uvchik committed Aug 27, 2019
1 parent 3b579b8 commit 396ba97
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
9 changes: 5 additions & 4 deletions tests/test_wind_farm.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ def test_initialization_dataframe(self):

def test_initialization_1(self):
"""test catching error when wind_turbine_fleet not provided as list"""
msg = 'Wind turbine fleet not provided properly.'
msg = 'Wind turbine must be provided as WindTurbine object'
with pytest.raises(ValueError, match=msg):
WindFarm(wind_turbine_fleet=[{'wind_turbine': 'turbine',
'number_of_turbines': 2}, 'dummy'])
WindFarm(wind_turbine_fleet={'wind_turbine': 'turbine',
'number_of_turbines': 2},
name='dummy')

def test_initialization_2(self):
"""test catching error when WindTurbine in wind_turbine_fleet
Expand All @@ -71,7 +72,7 @@ def test_initialization_3(self):
WindTurbine(**self.test_turbine_2)],
'number_of_turbines': [3, 2]})
msg = 'Missing wind_turbine key/column in wind_turbine_fleet'
with pytest.raises(ValueError, match=msg):
with pytest.raises(KeyError, match=msg):
WindFarm(wind_turbine_fleet=wind_turbine_fleet)

def test_initialization_4(self, recwarn):
Expand Down
8 changes: 4 additions & 4 deletions windpowerlib/wind_farm.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ def check_and_complete_wind_turbine_fleet(self):
'Wind turbine must be provided as WindTurbine object '
'but was provided as {}.'.format(type(turbine)))
except KeyError:
raise ValueError('Missing wind_turbine key/column in '
'wind_turbine_fleet parameter.')
raise KeyError('Missing wind_turbine key/column in '
'wind_turbine_fleet parameter.')

# add columns for number of turbines and total capacity if they don't
# yet exist
Expand All @@ -161,7 +161,7 @@ def check_and_complete_wind_turbine_fleet(self):
else:
self.wind_turbine_fleet.loc[ix, 'number_of_turbines'] = \
number_of_turbines
except ValueError:
except TypeError:
raise ValueError(msg.format(row['wind_turbine']))

# calculate total capacity if necessary and check that total capacity
Expand All @@ -172,7 +172,7 @@ def check_and_complete_wind_turbine_fleet(self):
self.wind_turbine_fleet.loc[ix, 'total_capacity'] = \
row['number_of_turbines'] * \
row['wind_turbine'].nominal_power
except ValueError:
except TypeError:
raise ValueError(
'Total capacity of turbines of type {turbine} cannot '
'be deduced. Please check if the nominal power of the '
Expand Down

0 comments on commit 396ba97

Please sign in to comment.