Black
This commit is contained in:
1 parent
da05dfe708
commit
4de97abc3a
2676 files changed
+163166
-140084
No files matched your search
+38
-41
@@ -39,8 +39,11 @@ async def raising_session(loop):
|
||||
def test_get_distance_to_same_place():
|
||||
"""Test getting the distance."""
|
||||
meters = location_util.distance(
|
||||
COORDINATES_PARIS[0], COORDINATES_PARIS[1],
|
||||
COORDINATES_PARIS[0], COORDINATES_PARIS[1])
|
||||
COORDINATES_PARIS[0],
|
||||
COORDINATES_PARIS[1],
|
||||
COORDINATES_PARIS[0],
|
||||
COORDINATES_PARIS[1],
|
||||
)
|
||||
|
||||
assert meters == 0
|
||||
|
||||
@@ -48,43 +51,42 @@ def test_get_distance_to_same_place():
|
||||
def test_get_distance():
|
||||
"""Test getting the distance."""
|
||||
meters = location_util.distance(
|
||||
COORDINATES_PARIS[0], COORDINATES_PARIS[1],
|
||||
COORDINATES_NEW_YORK[0], COORDINATES_NEW_YORK[1])
|
||||
COORDINATES_PARIS[0],
|
||||
COORDINATES_PARIS[1],
|
||||
COORDINATES_NEW_YORK[0],
|
||||
COORDINATES_NEW_YORK[1],
|
||||
)
|
||||
|
||||
assert meters/1000 - DISTANCE_KM < 0.01
|
||||
assert meters / 1000 - DISTANCE_KM < 0.01
|
||||
|
||||
|
||||
def test_get_kilometers():
|
||||
"""Test getting the distance between given coordinates in km."""
|
||||
kilometers = location_util.vincenty(
|
||||
COORDINATES_PARIS, COORDINATES_NEW_YORK)
|
||||
kilometers = location_util.vincenty(COORDINATES_PARIS, COORDINATES_NEW_YORK)
|
||||
assert round(kilometers, 2) == DISTANCE_KM
|
||||
|
||||
|
||||
def test_get_miles():
|
||||
"""Test getting the distance between given coordinates in miles."""
|
||||
miles = location_util.vincenty(
|
||||
COORDINATES_PARIS, COORDINATES_NEW_YORK, miles=True)
|
||||
miles = location_util.vincenty(COORDINATES_PARIS, COORDINATES_NEW_YORK, miles=True)
|
||||
assert round(miles, 2) == DISTANCE_MILES
|
||||
|
||||
|
||||
async def test_detect_location_info_ipapi(aioclient_mock, session):
|
||||
"""Test detect location info using ipapi.co."""
|
||||
aioclient_mock.get(
|
||||
location_util.IPAPI, text=load_fixture('ipapi.co.json'))
|
||||
aioclient_mock.get(location_util.IPAPI, text=load_fixture("ipapi.co.json"))
|
||||
|
||||
info = await location_util.async_detect_location_info(
|
||||
session, _test_real=True)
|
||||
info = await location_util.async_detect_location_info(session, _test_real=True)
|
||||
|
||||
assert info is not None
|
||||
assert info.ip == '1.2.3.4'
|
||||
assert info.country_code == 'CH'
|
||||
assert info.country_name == 'Switzerland'
|
||||
assert info.region_code == 'BE'
|
||||
assert info.region_name == 'Bern'
|
||||
assert info.city == 'Bern'
|
||||
assert info.zip_code == '3000'
|
||||
assert info.time_zone == 'Europe/Zurich'
|
||||
assert info.ip == "1.2.3.4"
|
||||
assert info.country_code == "CH"
|
||||
assert info.country_name == "Switzerland"
|
||||
assert info.region_code == "BE"
|
||||
assert info.region_name == "Bern"
|
||||
assert info.city == "Bern"
|
||||
assert info.zip_code == "3000"
|
||||
assert info.time_zone == "Europe/Zurich"
|
||||
assert info.latitude == 46.9480278
|
||||
assert info.longitude == 7.4490812
|
||||
assert info.use_metric
|
||||
@@ -92,23 +94,20 @@ async def test_detect_location_info_ipapi(aioclient_mock, session):
|
||||
|
||||
async def test_detect_location_info_ip_api(aioclient_mock, session):
|
||||
"""Test detect location info using ip-api.com."""
|
||||
aioclient_mock.get(
|
||||
location_util.IP_API, text=load_fixture('ip-api.com.json'))
|
||||
aioclient_mock.get(location_util.IP_API, text=load_fixture("ip-api.com.json"))
|
||||
|
||||
with patch('homeassistant.util.location._get_ipapi',
|
||||
return_value=mock_coro(None)):
|
||||
info = await location_util.async_detect_location_info(
|
||||
session, _test_real=True)
|
||||
with patch("homeassistant.util.location._get_ipapi", return_value=mock_coro(None)):
|
||||
info = await location_util.async_detect_location_info(session, _test_real=True)
|
||||
|
||||
assert info is not None
|
||||
assert info.ip == '1.2.3.4'
|
||||
assert info.country_code == 'US'
|
||||
assert info.country_name == 'United States'
|
||||
assert info.region_code == 'CA'
|
||||
assert info.region_name == 'California'
|
||||
assert info.city == 'San Diego'
|
||||
assert info.zip_code == '92122'
|
||||
assert info.time_zone == 'America/Los_Angeles'
|
||||
assert info.ip == "1.2.3.4"
|
||||
assert info.country_code == "US"
|
||||
assert info.country_name == "United States"
|
||||
assert info.region_code == "CA"
|
||||
assert info.region_name == "California"
|
||||
assert info.city == "San Diego"
|
||||
assert info.zip_code == "92122"
|
||||
assert info.time_zone == "America/Los_Angeles"
|
||||
assert info.latitude == 32.8594
|
||||
assert info.longitude == -117.2073
|
||||
assert not info.use_metric
|
||||
@@ -116,12 +115,10 @@ async def test_detect_location_info_ip_api(aioclient_mock, session):
|
||||
|
||||
async def test_detect_location_info_both_queries_fail(session):
|
||||
"""Ensure we return None if both queries fail."""
|
||||
with patch('homeassistant.util.location._get_ipapi',
|
||||
return_value=mock_coro(None)), \
|
||||
patch('homeassistant.util.location._get_ip_api',
|
||||
return_value=mock_coro(None)):
|
||||
info = await location_util.async_detect_location_info(
|
||||
session, _test_real=True)
|
||||
with patch(
|
||||
"homeassistant.util.location._get_ipapi", return_value=mock_coro(None)
|
||||
), patch("homeassistant.util.location._get_ip_api", return_value=mock_coro(None)):
|
||||
info = await location_util.async_detect_location_info(session, _test_real=True)
|
||||
assert info is None
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user