Skip to content

Commit

Permalink
Merge branch 'forslund-cache-fetching'
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbedrich committed May 8, 2015
2 parents e13dff4 + 61f404c commit 5d930f3
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 60 deletions.
7 changes: 4 additions & 3 deletions pycaching/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ class Cache(object):
"teamwork": "Teamwork Required",
"thorn": "Thorns",
"ticks": "Ticks",
"touristOK": "Tourist Friendly",
"touristok": "Tourist Friendly",
"treeclimbing": "Tree Climbing",
"UV": "UV Light Required",
"uv": "UV Light Required",
"wading": "May Require Wading",
"water": "Drinking Water Nearby",
"wheelchair": "Wheelchair Accessible",
Expand All @@ -107,6 +107,7 @@ class Cache(object):
"mega": "Mega-Event Cache",
"giga": "Giga-Event Cache",
"earthcache": "Earthcache",
"137": "Earthcache",
"13": "Cache in Trash out Event",
"11": "Webcam Cache",
"4": "Virtual Cache",
Expand Down Expand Up @@ -325,7 +326,7 @@ def attributes(self, attributes):

self._attributes = {}
for name, allowed in attributes.items():
name = name.strip()
name = name.strip().lower()
if name in self._possible_attributes:
self._attributes[name] = allowed
else:
Expand Down
6 changes: 0 additions & 6 deletions pycaching/geocaching.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ class Geocaching(object):
"grid": _tile_url + "map.info",
}

# interesting URLs:
# https://staging.api.groundspeak.com/Live/V6Beta/geocaching.svc/help
# http://tiles01.geocaching.com/map.details?i=GCNJ2Z
# http://tiles01.geocaching.com/map.info?x=8803&y=5576&z=14 (http://www.mapbox.com/developers/utfgrid/)
# http://tiles01.geocaching.com/map.png?x=8803&y=5576&z=14

def __init__(self):
self._logged_in = False
self._browser = ms.Browser()
Expand Down
1 change: 0 additions & 1 deletion test/sample.json

This file was deleted.

64 changes: 33 additions & 31 deletions test/sample_caches → test/sample_caches.csv
Original file line number Diff line number Diff line change
@@ -1,40 +1,42 @@
GC1T0MH,49.74999624181945,13.373451232910156
GCZ5J3,49.74933075001044,13.378944396972656
GCW21Q,49.74733421979961,13.377914428710938
GCX6GH,49.74733421979961,13.37310791015625
GC1NT7W,49.750883550028384,13.370361328125
GC1T0KZ,49.748887083731866,13.361091613769531
GCZ55B,49.748221576705156,13.379974365234375
GC10EBM,49.75043989795293,13.365211486816406
GC15W53,49.7440064868336,13.378257751464844
GCZKXM,49.74733421979961,13.377571105957031
GC18V5Z,49.75177084200527,13.374824523925781
GC18NNN,49.74866524907081,13.376884460449219
GCXFXT,49.74755606054778,13.367958068847656
GC2YPEF,49.73890351959557,13.361778259277344
GC3AHCH,49.74799973900054,13.38134765625
GC2NMZB,49.74067852559541,13.367271423339844
GC17G5F,49.74023478018286,13.363151550292969
GC11AZF,49.74844341339524,13.373794555664062
GC50EFF,49.74267532973123,13.381004333496094
GC18RYQ,49.74156600424579,13.372077941894531
GC59TJW,49.74799973900054,13.376884460449219
GC1CG3K,49.748221576705156,13.376884460449219
GC17G5F,49.74023478018286,13.363151550292969
GC4MFBT,49.74001290595473,13.366584777832031
GC157P2,49.74533760741242,13.3758544921875
GC18RXP,49.74533760741242,13.379631042480469
GC57PG8,49.748887083731866,13.377914428710938
GC5KNMV,49.75110537454435,13.379287719726562
GCW21Q,49.74733421979961,13.377914428710938
GC18NNN,49.74866524907081,13.376884460449219
GCZ55B,49.748221576705156,13.379974365234375
GCY81P,49.74555945729134,13.374137878417969
GCQDB8,49.74777790028142,13.377571105957031
GCZKXM,49.74733421979961,13.377571105957031
GC1NT7W,49.750883550028384,13.370361328125
GC1JT5W,49.74733421979961,13.376884460449219
GC1F2NP,49.75243630033572,13.378257751464844
GCQDB8,49.74777790028142,13.377571105957031
GC5CB1V,49.746446846661705,13.376884460449219
GC5TNQQ,49.75177084200527,13.376884460449219
GC1T3RH,49.752879934150215,13.379287719726562
GC20CJX,49.74866524907081,13.380661010742188
GC2YPEF,49.73890351959557,13.361778259277344
GCX846,49.74622500084091,13.366241455078125
GC5BY5Z,49.74289719178466,13.365898132324219
GC5Q8W6,49.74489390461096,13.370361328125
GC18RXP,49.74533760741242,13.379631042480469
GC18V5Z,49.75177084200527,13.374824523925781
GC5TYMJ,49.74933075001044,13.378257751464844
GC1F2NP,49.75243630033572,13.378257751464844
GCVMNH,49.74533760741242,13.373451232910156
GC3HRHF,49.73979103071204,13.371047973632812
GC59WVV,49.74489390461096,13.379287719726562
GC3AHCH,49.74799973900054,13.38134765625
GC1QJNJ,49.74844341339524,13.374481201171875
GC10EBM,49.75043989795293,13.365211486816406
GC1T0KZ,49.748887083731866,13.361091613769531
GC3DN3N,49.741344136105035,13.37860107421875
GC5CGNC,49.74799973900054,13.376884460449219
GC1XP9V,49.74689053525971,13.377227783203125
GCX846,49.74622500084091,13.366241455078125
GC1T3RH,49.752879934150215,13.379287719726562
GC11AZF,49.74844341339524,13.373794555664062
GC1534Q,49.74866524907081,13.373451232910156
GC1QJNJ,49.74844341339524,13.374481201171875
GC1XP9V,49.74689053525971,13.377227783203125
GCZ5J3,49.74933075001044,13.378944396972656
GCX6GH,49.74733421979961,13.37310791015625
GC1CG3K,49.748221576705156,13.376884460449219
GC3HRHF,49.73979103071204,13.371047973632812
GC57PG8,49.748887083731866,13.377914428710938
GC1T0MH,49.74999624181945,13.373451232910156
GC15W53,49.7440064868336,13.378257751464844
1 change: 1 addition & 0 deletions test/sample_utfgrid.json

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion test/test_geocaching.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,22 +109,28 @@ def test_calculate_initial_tiles(self):

def test_get_utfgrid_caches(self):
"""Load tiles and check if expected caches are found"""
file_path = os.path.join(os.path.dirname(__file__), "sample_caches")

# load expected result
file_path = os.path.join(os.path.dirname(__file__), "sample_caches.csv")
expected_caches = set()
with open(file_path) as f:
for row in f:
wp = row.split(',')[0]
expected_caches.add(wp)
n_orig = len(expected_caches)

# load search result
additional_caches = set()
for c in self.g._get_utfgrid_caches((8800, 5574, 14),):
if c.wp in expected_caches:
expected_caches.discard(c.wp)
else:
additional_caches.add(c.wp)

with self.subTest("Expected caches found"):
self.assertLess(len(expected_caches) / n_orig, 0.2,
"Over 20 % of expected caches are lost.")

with self.subTest("Unexpected caches not found"):
self.assertLess(len(additional_caches) / n_orig, 0.2,
"Over 20 % of found caches are unexpected.")
Expand Down
33 changes: 15 additions & 18 deletions test/test_utfgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import logging
import unittest

import pycaching
from pycaching import Geocaching
from pycaching.utfgrid import UTFGrid, GridCoordinateBlock
from pycaching.errors import Error
Expand All @@ -14,8 +13,8 @@


_this_folder = os.path.dirname(__file__)
sample_files = {i: os.path.join(_this_folder, i)
for i in ["sample_caches", "sample.json"]}
sample_files = {i: os.path.join(_this_folder, i) for i in ["sample_caches.csv", "sample_utfgrid.json"]}


class TestUTFGrid(unittest.TestCase):

Expand All @@ -26,27 +25,25 @@ def test_download(self):
"""Test if downloading a tile goes nice without errors"""
self.grid._gc.login(_username, _password)
with self.subTest("Not getting .png tile first"):
caches = list(self.grid.download())
list(self.grid.download())
with self.subTest("Getting .png tile first"):
caches = list(self.grid.download(get_png_first=True))
list(self.grid.download(get_png_first=True))

def test_parse(self):
"""Parse locally stored grid and compare to expected results"""
expected_caches = {}
with open(sample_files["sample_caches"]) as f:
with open(sample_files["sample_caches.csv"]) as f:
for row in f:
wp, lat, lon = row.split(',')
expected_caches[wp] = (float(lat), float(lon))
with open(sample_files["sample.json"]) as f:
with open(sample_files["sample_utfgrid.json"]) as f:
j = json.loads(f.read())
caches = self.grid._parse_utfgrid(j)
for c in caches:
with self.subTest("Cache " + wp):
self.assertIn(c.wp, expected_caches)
self.assertAlmostEqual(c.location.latitude,
expected_caches[c.wp][0])
self.assertAlmostEqual(c.location.longitude,
expected_caches[c.wp][1])
self.assertAlmostEqual(c.location.latitude, expected_caches[c.wp][0])
self.assertAlmostEqual(c.location.longitude, expected_caches[c.wp][1])
expected_caches.pop(c.wp)
self.assertEqual(len(expected_caches), 0)

Expand Down Expand Up @@ -80,9 +77,9 @@ class TestGridCoordinateBlock(unittest.TestCase):
(-2, 0), (63, 65)],
}
bad_cases = {'too much points':
[(1, 1), (1, 2), (1, 3),
(2, 1), (2, 2), (2, 3),
(3, 1), (3, 2), (3, 3), (3, 4)],
[(1, 1), (1, 2), (1, 3),
(2, 1), (2, 2), (2, 3),
(3, 1), (3, 2), (3, 3), (3, 4)],
'still too much points':
[(63, 30), (63, 31), (63, 32), (63, 33)],
'point missing: 9':
Expand All @@ -93,11 +90,11 @@ class TestGridCoordinateBlock(unittest.TestCase):
[(1, 0), (1, 1),
(2, 0),
(3, 0), (3, 1)],
'points not aligned':
'points not aligned':
[(1, 1), (1, 2), (1, 3),
(2, 1), (2, 3), (2, 4),
(2, 1), (2, 3), (2, 4),
(3, 1), (3, 2), (3, 3)],
}
}

def setUp(self):
self.grid = UTFGrid(Geocaching(), 8800, 5574, 14)
Expand Down Expand Up @@ -142,7 +139,7 @@ def test_add_point(self):
self.cb.points = []
self.cb.add((3, 4))
self.assertEqual(self.cb.points,
GridCoordinateBlock(self.grid, (3,4)).points)
GridCoordinateBlock(self.grid, (3, 4)).points)

with self.subTest("Multiple points: pass directly"):
points = [(0, 0), (1, 2), (3, 4), (1, 2), (5, 6)]
Expand Down

0 comments on commit 5d930f3

Please sign in to comment.