From 0a4f2de842d29896b261905b8dfe2ac348521af4 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Sun, 10 Feb 2019 08:59:43 +0100 Subject: [PATCH 1/2] Cast set_location arguments to float --- appium/webdriver/extensions/location.py | 6 +++--- test/unit/webdriver/device/location_test.py | 13 +++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/appium/webdriver/extensions/location.py b/appium/webdriver/extensions/location.py index 8c469fc8..7c96f863 100644 --- a/appium/webdriver/extensions/location.py +++ b/appium/webdriver/extensions/location.py @@ -33,9 +33,9 @@ def set_location(self, latitude, longitude, altitude): """ data = { "location": { - "latitude": str(latitude), - "longitude": str(longitude), - "altitude": str(altitude) + "latitude": float(latitude), + "longitude": float(longitude), + "altitude": float(altitude) } } self.execute(Command.SET_LOCATION, data) diff --git a/test/unit/webdriver/device/location_test.py b/test/unit/webdriver/device/location_test.py index ad6a07bb..2b36b886 100644 --- a/test/unit/webdriver/device/location_test.py +++ b/test/unit/webdriver/device/location_test.py @@ -22,6 +22,7 @@ from appium.webdriver.webdriver import WebDriver +FLT_EPSILON = 1e-9 class TestWebDriverLocation(object): @@ -44,9 +45,9 @@ def test_set_location(self): assert isinstance(driver.set_location(11.1, 22.2, 33.3), WebDriver) == True d = get_httpretty_request_body(httpretty.last_request()) - assert d['location']['latitude'] == '11.1' - assert d['location']['longitude'] == '22.2' - assert d['location']['altitude'] == '33.3' + assert abs(d['location']['latitude'] - 11.1) <= FLT_EPSILON + assert abs(d['location']['longitude'] - 22.2) <= FLT_EPSILON + assert abs(d['location']['altitude'] - 33.3) <= FLT_EPSILON @httpretty.activate def test_location(self): @@ -57,6 +58,6 @@ def test_location(self): body='{"value": {"latitude": 11.1, "longitude": 22.2, "altitude": 33.3}}' ) val = driver.location - assert val['latitude'] == 11.1 - assert val['longitude'] == 22.2 - assert val['altitude'] == 33.3 + assert abs(val['latitude'] - 11.1) <= FLT_EPSILON + assert abs(val['longitude'] - 22.2) <= FLT_EPSILON + assert abs(val['altitude'] - 33.3) <= FLT_EPSILON From 7f874fcbb7ce41c0eaeeae12b8417dd64030d2e1 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Sun, 10 Feb 2019 12:59:15 +0100 Subject: [PATCH 2/2] Fix formatting --- test/unit/webdriver/device/location_test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unit/webdriver/device/location_test.py b/test/unit/webdriver/device/location_test.py index 2b36b886..f8adb2f2 100644 --- a/test/unit/webdriver/device/location_test.py +++ b/test/unit/webdriver/device/location_test.py @@ -24,6 +24,7 @@ FLT_EPSILON = 1e-9 + class TestWebDriverLocation(object): @httpretty.activate