From 8a38690c9217bc29e5c685217f309f7385822028 Mon Sep 17 00:00:00 2001 From: Son Pham Date: Thu, 25 May 2017 20:32:46 +0100 Subject: [PATCH] Use the right sort key inside `forceTz` (#40) * Add a simple test case * Sort by the right key * Fix tests. setuptools has dropped python 3.2 support * Exclude these files from .coveralls runs --- .coveragerc | 5 +++++ .travis.yml | 3 +-- tests/test_locations.py | 1 + tzwhere/tzwhere.py | 3 ++- 4 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 .coveragerc diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..a5f7fce --- /dev/null +++ b/.coveragerc @@ -0,0 +1,5 @@ +[report] +omit = + */python?.?/* + */site-packages/nose/* + *__init__* diff --git a/.travis.yml b/.travis.yml index 6b4dcef..486e70e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: python python: - "2.7" - - "3.2" - "3.3" - "3.4" - "3.5" @@ -10,7 +9,7 @@ install: - pip install -e . - pip install -r tests/requirements.txt # command to run tests -script: +script: - nosetests --with-coverage --cover-branches --cover-inclusive --cover-package=tzwhere after_script: coveralls diff --git a/tests/test_locations.py b/tests/test_locations.py index 645bc30..0417170 100644 --- a/tests/test_locations.py +++ b/tests/test_locations.py @@ -47,6 +47,7 @@ class LocationTestCase(unittest.TestCase): ( 61.17, -150.02, 'Anchorage, AK', 'America/Anchorage'), ( 40.7271, -73.98, 'Shore Lake Michigan', 'America/New_York'), ( 50.1536, -8.051, 'Off Cornwall', 'Europe/London'), + ( 49.2698, -123.1302, 'Vancouver', 'America/Vancouver'), ( 50.26, -9.051, 'Far off Cornwall', None) ) diff --git a/tzwhere/tzwhere.py b/tzwhere/tzwhere.py index dfdf567..6153b6c 100755 --- a/tzwhere/tzwhere.py +++ b/tzwhere/tzwhere.py @@ -229,7 +229,8 @@ def tzNameAt(self, latitude, longitude, forceTZ=False): d = poly.distance(queryPoint) distances.append((d, tzname)) if len(distances) > 0: - return sorted(distances, key=lambda x: x[1])[0][1] + # Sort by distances, and then return the timezone name of the first instance in the sorted list + return sorted(distances, key=lambda x: x[0])[0][1] @staticmethod def _point_inside_polygon(x, y, poly):