Pylint cleanups (#15626)

* Pylint 2 no-else-return fixes

* Remove unneeded abstract-class-not-used pylint disable
This commit is contained in:
Ville Skyttä authored and Paulus Schoutsen committed 2018-07-23 10:16:05 +02:00
1 parent a38c0d6d15
commit b7c336a687
166 files changed
+425 -490

No files matched your search

+6 -7
View File
@@ -496,14 +496,13 @@ class MockToggleDevice(entity.ToggleEntity):
"""Return the last call."""
if not self.calls:
return None
elif method is None:
if method is None:
return self.calls[-1]
else:
try:
return next(call for call in reversed(self.calls)
if call[0] == method)
except StopIteration:
return None
try:
return next(call for call in reversed(self.calls)
if call[0] == method)
except StopIteration:
return None
class MockConfigEntry(config_entries.ConfigEntry):
+1 -1
View File
@@ -124,7 +124,7 @@ def discovery_test(device, hass, expected_endpoints=1):
if expected_endpoints == 1:
return endpoints[0]
elif expected_endpoints > 1:
if expected_endpoints > 1:
return endpoints
return None
+1 -2
View File
@@ -45,8 +45,7 @@ class TestUVCSetup(unittest.TestCase):
"""Create a mock camera."""
if uuid == 'id3':
return {'model': 'airCam'}
else:
return {'model': 'UVC'}
return {'model': 'UVC'}
mock_remote.return_value.index.return_value = mock_cameras
mock_remote.return_value.get_camera.side_effect = mock_get_camera
@@ -22,9 +22,9 @@ def mock_session_response(*args, **kwargs):
# Password: bar
if args[0].headers['Authorization'] != 'Basic Zm9vOmJhcg==':
return MockSessionResponse(None, 401)
elif "gimmie_bad_data" in args[0].body:
if "gimmie_bad_data" in args[0].body:
return MockSessionResponse('This shouldn\'t (wldev = be here.;', 200)
elif "gimmie_good_data" in args[0].body:
if "gimmie_good_data" in args[0].body:
return MockSessionResponse(
"wldev = [ ['eth1','F4:F5:D8:AA:AA:AA',"
"-42,5500,1000,7043,0],['eth1','58:EF:68:00:00:00',"
@@ -55,21 +55,21 @@ def mocked_requests(*args, **kwargs):
"code": "401",
"msg": "Invalid token"
}, 200)
elif data and data.get('username', None) == TOKEN_TIMEOUT_USERNAME:
if data and data.get('username', None) == TOKEN_TIMEOUT_USERNAME:
# deliver an expired token
return MockResponse({
"url": "/cgi-bin/luci/;stok=ef5860/web/home",
"token": "timedOut",
"code": "0"
}, 200)
elif str(args[0]).startswith(URL_AUTHORIZE):
if str(args[0]).startswith(URL_AUTHORIZE):
# deliver an authorized token
return MockResponse({
"url": "/cgi-bin/luci/;stok=ef5860/web/home",
"token": "ef5860",
"code": "0"
}, 200)
elif str(args[0]).endswith("timedOut/" + URL_LIST_END) \
if str(args[0]).endswith("timedOut/" + URL_LIST_END) \
and FIRST_CALL is True:
FIRST_CALL = False
# deliver an error when called with expired token
@@ -77,7 +77,7 @@ def mocked_requests(*args, **kwargs):
"code": "401",
"msg": "Invalid token"
}, 200)
elif str(args[0]).endswith(URL_LIST_END):
if str(args[0]).endswith(URL_LIST_END):
# deliver the device list
return MockResponse({
"mac": "1C:98:EC:0E:D5:A4",
@@ -149,8 +149,7 @@ def mocked_requests(*args, **kwargs):
],
"code": 0
}, 200)
else:
_LOGGER.debug('UNKNOWN ROUTE')
_LOGGER.debug('UNKNOWN ROUTE')
class TestXiaomiDeviceScanner(unittest.TestCase):
+1 -1
View File
@@ -182,7 +182,7 @@ def mock_bridge(hass):
if path == 'lights':
return bridge.mock_light_responses.popleft()
elif path == 'groups':
if path == 'groups':
return bridge.mock_group_responses.popleft()
return None
+1 -2
View File
@@ -26,8 +26,7 @@ class TestNotifyGroup(unittest.TestCase):
def mock_get_service(hass, config, discovery_info=None):
if config['name'] == 'demo1':
return self.service1
else:
return self.service2
return self.service2
with assert_setup_component(2), \
patch.object(demo, 'get_service', mock_get_service):
+2 -3
View File
@@ -157,7 +157,6 @@ def _process_timestamp(ts):
"""Process a timestamp into datetime object."""
if ts is None:
return None
elif ts.tzinfo is None:
if ts.tzinfo is None:
return dt_util.UTC.localize(ts)
else:
return dt_util.as_utc(ts)
return dt_util.as_utc(ts)
+7 -8
View File
@@ -83,7 +83,7 @@ def mocked_requests_get(*args, **kwargs):
"id": 12
}
], 200)
elif 'api/command' in url:
if 'api/command' in url:
return MockResponse([
{
"name": "RescanMovie",
@@ -94,7 +94,7 @@ def mocked_requests_get(*args, **kwargs):
"id": 24
}
], 200)
elif 'api/movie' in url:
if 'api/movie' in url:
return MockResponse([
{
"title": "Assassin's Creed",
@@ -149,7 +149,7 @@ def mocked_requests_get(*args, **kwargs):
"id": 1
}
], 200)
elif 'api/diskspace' in url:
if 'api/diskspace' in url:
return MockResponse([
{
"path": "/data",
@@ -158,7 +158,7 @@ def mocked_requests_get(*args, **kwargs):
"totalSpace": 499738734592
}
], 200)
elif 'api/system/status' in url:
if 'api/system/status' in url:
return MockResponse({
"version": "0.2.0.210",
"buildTime": "2017-01-22T23:12:49Z",
@@ -182,10 +182,9 @@ def mocked_requests_get(*args, **kwargs):
"(Stable 4.6.1.3/abb06f1 "
"Mon Oct 3 07:57:59 UTC 2016)")
}, 200)
else:
return MockResponse({
"error": "Unauthorized"
}, 401)
return MockResponse({
"error": "Unauthorized"
}, 401)
class TestRadarrSetup(unittest.TestCase):
+9 -10
View File
@@ -139,7 +139,7 @@ def mocked_requests_get(*args, **kwargs):
"id": 14402
}
], 200)
elif 'api/command' in url:
if 'api/command' in url:
return MockResponse([
{
"name": "RescanSeries",
@@ -150,7 +150,7 @@ def mocked_requests_get(*args, **kwargs):
"id": 24
}
], 200)
elif 'api/wanted/missing' in url or 'totalRecords' in url:
if 'api/wanted/missing' in url or 'totalRecords' in url:
return MockResponse(
{
"page": 1,
@@ -325,7 +325,7 @@ def mocked_requests_get(*args, **kwargs):
}
]
}, 200)
elif 'api/queue' in url:
if 'api/queue' in url:
return MockResponse([
{
"series": {
@@ -449,7 +449,7 @@ def mocked_requests_get(*args, **kwargs):
"id": 1503378561
}
], 200)
elif 'api/series' in url:
if 'api/series' in url:
return MockResponse([
{
"title": "Marvel's Daredevil",
@@ -540,7 +540,7 @@ def mocked_requests_get(*args, **kwargs):
"id": 7
}
], 200)
elif 'api/diskspace' in url:
if 'api/diskspace' in url:
return MockResponse([
{
"path": "/data",
@@ -549,7 +549,7 @@ def mocked_requests_get(*args, **kwargs):
"totalSpace": 499738734592
}
], 200)
elif 'api/system/status' in url:
if 'api/system/status' in url:
return MockResponse({
"version": "2.0.0.1121",
"buildTime": "2014-02-08T20:49:36.5560392Z",
@@ -568,10 +568,9 @@ def mocked_requests_get(*args, **kwargs):
"startOfWeek": 0,
"urlBase": ""
}, 200)
else:
return MockResponse({
"error": "Unauthorized"
}, 401)
return MockResponse({
"error": "Unauthorized"
}, 401)
class TestSonarrSetup(unittest.TestCase):
+17 -33
View File
@@ -92,8 +92,7 @@ class TestSwitchFlux(unittest.TestCase):
def event_date(hass, event, now=None):
if event == 'sunrise':
return sunrise_time
else:
return sunset_time
return sunset_time
with patch('homeassistant.util.dt.now', return_value=test_time):
with patch('homeassistant.helpers.sun.get_astral_event_date',
@@ -134,8 +133,7 @@ class TestSwitchFlux(unittest.TestCase):
def event_date(hass, event, now=None):
if event == 'sunrise':
return sunrise_time
else:
return sunset_time
return sunset_time
with patch('homeassistant.util.dt.now', return_value=test_time):
with patch('homeassistant.helpers.sun.get_astral_event_date',
@@ -181,8 +179,7 @@ class TestSwitchFlux(unittest.TestCase):
def event_date(hass, event, now=None):
if event == 'sunrise':
return sunrise_time
else:
return sunset_time
return sunset_time
with patch('homeassistant.util.dt.now', return_value=test_time):
with patch('homeassistant.helpers.sun.get_astral_event_date',
@@ -228,8 +225,7 @@ class TestSwitchFlux(unittest.TestCase):
def event_date(hass, event, now=None):
if event == 'sunrise':
return sunrise_time
else:
return sunset_time
return sunset_time
with patch('homeassistant.util.dt.now', return_value=test_time):
with patch('homeassistant.helpers.sun.get_astral_event_date',
@@ -276,8 +272,7 @@ class TestSwitchFlux(unittest.TestCase):
def event_date(hass, event, now=None):
if event == 'sunrise':
return sunrise_time
else:
return sunset_time
return sunset_time
with patch('homeassistant.util.dt.now', return_value=test_time):
with patch('homeassistant.helpers.sun.get_astral_event_date',
@@ -323,8 +318,7 @@ class TestSwitchFlux(unittest.TestCase):
def event_date(hass, event, now=None):
if event == 'sunrise':
return sunrise_time
else:
return sunset_time
return sunset_time
with patch('homeassistant.util.dt.now', return_value=test_time):
with patch('homeassistant.helpers.sun.get_astral_event_date',
@@ -374,8 +368,7 @@ class TestSwitchFlux(unittest.TestCase):
def event_date(hass, event, now=None):
if event == 'sunrise':
return sunrise_time
else:
return sunset_time
return sunset_time
with patch('homeassistant.util.dt.now', return_value=test_time):
with patch('homeassistant.helpers.sun.get_astral_event_date',
@@ -426,8 +419,7 @@ class TestSwitchFlux(unittest.TestCase):
def event_date(hass, event, now=None):
if event == 'sunrise':
return sunrise_time
else:
return sunset_time
return sunset_time
with patch('homeassistant.util.dt.now', return_value=test_time):
with patch('homeassistant.helpers.sun.get_astral_event_date',
@@ -477,8 +469,7 @@ class TestSwitchFlux(unittest.TestCase):
def event_date(hass, event, now=None):
if event == 'sunrise':
return sunrise_time
else:
return sunset_time
return sunset_time
with patch('homeassistant.util.dt.now', return_value=test_time):
with patch('homeassistant.helpers.sun.get_astral_event_date',
@@ -528,8 +519,7 @@ class TestSwitchFlux(unittest.TestCase):
def event_date(hass, event, now=None):
if event == 'sunrise':
return sunrise_time
else:
return sunset_time
return sunset_time
with patch('homeassistant.util.dt.now', return_value=test_time):
with patch('homeassistant.helpers.sun.get_astral_event_date',
@@ -579,8 +569,7 @@ class TestSwitchFlux(unittest.TestCase):
def event_date(hass, event, now=None):
if event == 'sunrise':
return sunrise_time
else:
return sunset_time
return sunset_time
with patch('homeassistant.util.dt.now', return_value=test_time):
with patch('homeassistant.helpers.sun.get_astral_event_date',
@@ -627,8 +616,7 @@ class TestSwitchFlux(unittest.TestCase):
def event_date(hass, event, now=None):
if event == 'sunrise':
return sunrise_time
else:
return sunset_time
return sunset_time
with patch('homeassistant.util.dt.now', return_value=test_time):
with patch('homeassistant.helpers.sun.get_astral_event_date',
@@ -677,8 +665,7 @@ class TestSwitchFlux(unittest.TestCase):
def event_date(hass, event, now=None):
if event == 'sunrise':
return sunrise_time
else:
return sunset_time
return sunset_time
with patch('homeassistant.util.dt.now', return_value=test_time):
with patch('homeassistant.helpers.sun.get_astral_event_date',
@@ -739,9 +726,8 @@ class TestSwitchFlux(unittest.TestCase):
if event == 'sunrise':
print('sunrise {}'.format(sunrise_time))
return sunrise_time
else:
print('sunset {}'.format(sunset_time))
return sunset_time
print('sunset {}'.format(sunset_time))
return sunset_time
with patch('homeassistant.util.dt.now', return_value=test_time):
with patch('homeassistant.helpers.sun.get_astral_event_date',
@@ -793,8 +779,7 @@ class TestSwitchFlux(unittest.TestCase):
def event_date(hass, event, now=None):
if event == 'sunrise':
return sunrise_time
else:
return sunset_time
return sunset_time
with patch('homeassistant.util.dt.now', return_value=test_time):
with patch('homeassistant.helpers.sun.get_astral_event_date',
@@ -838,8 +823,7 @@ class TestSwitchFlux(unittest.TestCase):
def event_date(hass, event, now=None):
if event == 'sunrise':
return sunrise_time
else:
return sunset_time
return sunset_time
with patch('homeassistant.util.dt.now', return_value=test_time):
with patch('homeassistant.helpers.sun.get_astral_event_date',
+3 -4
View File
@@ -224,13 +224,12 @@ class TestGraphite(unittest.TestCase):
def fake_get():
if len(runs) >= 2:
return self.gf._quit_object
elif runs:
if runs:
runs.append(1)
return mock.MagicMock(event_type='somethingelse',
data={'new_event': None})
else:
runs.append(1)
return event
runs.append(1)
return event
with mock.patch.object(self.gf, '_queue') as mock_queue:
with mock.patch.object(self.gf, '_report_attributes') as mock_r: