Пример #1
0
class TestUTFGrid(unittest.TestCase):
    def setUp(self):
        self.grid = UTFGrid(Geocaching(), 8800, 5574, 14)

    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"):
            list(self.grid.download())
        with self.subTest("Getting .png tile first"):
            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.csv"]) as f:
            for row in f:
                wp, lat, lon = row.split(',')
                expected_caches[wp] = (float(lat), float(lon))
        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])
                expected_caches.pop(c.wp)
        self.assertEqual(len(expected_caches), 0)
Пример #2
0
class TestUTFGrid(unittest.TestCase):

    def setUp(self):
        self.grid = UTFGrid(Geocaching(), 8800, 5574, 14)

    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"):
            list(self.grid.download())
        with self.subTest("Getting .png tile first"):
            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.csv"]) as f:
            for row in f:
                wp, lat, lon = row.split(',')
                expected_caches[wp] = (float(lat), float(lon))
        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])
                expected_caches.pop(c.wp)
        self.assertEqual(len(expected_caches), 0)
Пример #3
0
    def _get_utfgrid_caches(self, *tiles):
        """Get location of geocaches within tiles, using UTFGrid service

        Parameter tiles contains one or more tuples dictionaries that
        are of form (x, y, z).  Return generator object of Cache
        instances."""

        found_caches = set()
        for tile in tiles:
            ug = UTFGrid(self, *tile)
            for c in ug.download():
                # Some geocaches may be found multiple times if they are on the
                # border of the UTFGrid. Throw additional ones away.
                if c.wp in found_caches:
                    logging.debug("Found cache {} again".format(c.wp))
                    continue
                found_caches.add(c.wp)
                yield c
        logging.info("{} tiles downloaded".format(len(tiles)))
Пример #4
0
    def _get_utfgrid_caches(self, *tiles):
        """Get location of geocaches within tiles, using UTFGrid service

        Parameter tiles contains one or more tuples dictionaries that
        are of form (x, y, z).  Return generator object of Cache
        instances."""

        found_caches = set()
        for tile in tiles:
            ug = UTFGrid(self, *tile)
            for c in ug.download():
                # Some geocaches may be found multiple times if they are on the
                # border of the UTFGrid. Throw additional ones away.
                if c.wp in found_caches:
                    logging.debug("Found cache {} again".format(c.wp))
                    continue
                found_caches.add(c.wp)
                yield c
        logging.info("{} tiles downloaded".format(len(tiles)))
Пример #5
0
 def setUp(self):
     self.grid = UTFGrid(Geocaching(), 8800, 5574, 14)
     self.grid.size = 64
     self.cb = GridCoordinateBlock(self.grid)
Пример #6
0
 def setUp(self):
     self.grid = UTFGrid(Geocaching(), 8800, 5574, 14)
Пример #7
0
 def setUp(self):
     self.grid = UTFGrid(Geocaching(), 8800, 5574, 14)