Beispiel #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)
Beispiel #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)