Skip to content

Commit cf2e78b

Browse files
johtoblanmfroelund
authored andcommitted
Set version to v.1.1 and add testing (vinsci#2)
* Set version to v.1.1 and add testing for all current python versions
1 parent 8177c41 commit cf2e78b

File tree

5 files changed

+40
-5
lines changed

5 files changed

+40
-5
lines changed

.github/workflows/pytest.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#.github/workflows/tests.yaml
2+
name: Unit Tests
3+
4+
on:
5+
push:
6+
branches: [ master ]
7+
pull_request:
8+
branches: [ master ]
9+
10+
11+
jobs:
12+
pyTest:
13+
strategy:
14+
matrix:
15+
python-version: [ "3.10", "3.11", "3.12", "3.13" ]
16+
runs-on: "ubuntu-latest"
17+
steps:
18+
- name: Python Setup
19+
uses: actions/setup-python@v4
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
architecture: x64
23+
- name: Checkout Source
24+
uses: actions/checkout@v3
25+
- name: Install Dependencies
26+
run: |
27+
pip install --upgrade pip
28+
pip install .
29+
pip install pytest
30+
- name: Run Tests
31+
run: python -m pytest -v

geohash/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
License along with Geohash. If not, see
1919
<http://www.gnu.org/licenses/>.
2020
"""
21-
from .geohash import decode_exactly, decode, encode
21+
from .geohash import decode_exactly, decode, encode

geohash/geohash.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
'z': 31
3232
}
3333

34+
3435
def decode_exactly(geohash):
3536
"""
3637
Decode the geohash to its exact values, including the error
@@ -45,7 +46,7 @@ def decode_exactly(geohash):
4546
for c in geohash:
4647
cd = __decodemap[c]
4748
for mask in [16, 8, 4, 2, 1]:
48-
if is_even: # adds longitude info
49+
if is_even: # adds longitude info
4950
lon_err /= 2
5051
if cd & mask:
5152
lon_interval = ((lon_interval[0]+lon_interval[1])/2, lon_interval[1])
@@ -62,6 +63,7 @@ def decode_exactly(geohash):
6263
lon = (lon_interval[0] + lon_interval[1]) / 2
6364
return lat, lon, lat_err, lon_err
6465

66+
6567
def decode(geohash):
6668
"""
6769
Decode geohash, returning two strings with latitude and longitude
@@ -77,14 +79,15 @@ def decode(geohash):
7779
lons = lons.rstrip('0') if "." in lons else lons
7880
return lats, lons
7981

82+
8083
def encode(latitude, longitude, precision=12):
8184
"""
8285
Encode a position given in float arguments latitude, longitude to
8386
a geohash which will have the character count precision.
8487
"""
8588
lat_interval, lon_interval = (-90.0, 90.0), (-180.0, 180.0)
8689
geohash = []
87-
bits = [ 16, 8, 4, 2, 1 ]
90+
bits = [16, 8, 4, 2, 1]
8891
bit = 0
8992
ch = 0
9093
even = True

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "geohash"
3-
version = "1.0"
3+
version = "1.1"
44
authors = [
55
{name = "Leonard Norrgard", email = "leonard.norrgard@gmail.com"},
66
]

test/test_geohash.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ def test_encode():
1313
outhash = geohash.encode(42.6, -5.6, precision=5)
1414
assert outhash == "ezs42"
1515
outhash = geohash.encode(42.6, -5.6, precision=1)
16+
assert outhash == "e"
1617

1718

1819
def test_decode():
19-
lat, lon = geohash.decode('ezs42')
20+
lat, lon = geohash.decode('ezs42')
2021
assert lat == "42.6"
2122
assert lon == "-5.6"
2223

0 commit comments

Comments
 (0)