Exemplo n.º 1
0
class TestBaseMap(unittest.TestCase):
    """Tests for functions in keys module"""
    def setUp(self):
        # basemaps with baked-in labels
        self.dark_map_all = BaseMap(source='dark')
        self.light_map_all = BaseMap(source='light')

        # basemaps with no labels
        self.dark_map_no_labels = BaseMap(source='dark', labels=None)
        self.light_map_no_labels = BaseMap(source='light', labels=None)

        # labels with no basemaps
        self.dark_only_labels = BaseMap(source='dark', only_labels=True)
        self.light_only_labels = BaseMap(source='light', only_labels=True)

    def test_basemap_invalid(self):
        """layer.Basemap exceptions on invalid source"""
        # Raise ValueError if invalid label is entered
        with self.assertRaises(ValueError):
            BaseMap(labels='watermelon')

        # Raise ValueError if custom URL is entered
        with self.assertRaises(ValueError):
            BaseMap(source='http://spinalmap.com/{z}/{x}/{y}.png')

        # Raise ValueError if non-supported style type is entered
        with self.assertRaises(ValueError):
            BaseMap(source='gulab_jamon')

    def test_basemap_source(self):
        """layer.BaseMap with different sources and labels"""

        # ensure correct BaseMap urls are created
        # See URLs here: https://carto.com/location-data-services/basemaps/
        self.assertEqual(
            self.dark_map_all.url,
            'https://cartodb-basemaps-{s}.global.ssl.fastly.net/'
            'dark_all/{z}/{x}/{y}.png')
        self.assertEqual(
            self.light_map_all.url,
            'https://cartodb-basemaps-{s}.global.ssl.fastly.net/'
            'light_all/{z}/{x}/{y}.png')
        self.assertEqual(
            self.dark_map_no_labels.url,
            'https://cartodb-basemaps-{s}.global.ssl.fastly.net/'
            'dark_nolabels/{z}/{x}/{y}.png')
        self.assertEqual(
            self.light_map_no_labels.url,
            'https://cartodb-basemaps-{s}.global.ssl.fastly.net/'
            'light_nolabels/{z}/{x}/{y}.png')
        self.assertEqual(
            self.light_only_labels.url,
            'https://cartodb-basemaps-{s}.global.ssl.fastly.net/'
            'light_only_labels/{z}/{x}/{y}.png')
        self.assertEqual(
            self.dark_only_labels.url,
            'https://cartodb-basemaps-{s}.global.ssl.fastly.net/'
            'dark_only_labels/{z}/{x}/{y}.png')

        # ensure self.is_basic() works as intended
        self.assertTrue(self.light_map_all.is_basic(),
                        msg='is a basic carto basemap')
        self.assertTrue(self.dark_map_all.is_basic())
Exemplo n.º 2
0
class TestBaseMap(unittest.TestCase):  # pylint: disable=too-many-instance-attributes
    """Tests for functions in keys module"""
    def setUp(self):
        # basemaps with baked-in labels
        self.dark_map_all = BaseMap(source='dark')
        self.light_map_all = BaseMap(source='light')
        self.voyager_labels_under = BaseMap(source='voyager')

        # basemaps with no labels
        self.dark_map_no_labels = BaseMap(source='dark', labels=None)
        self.light_map_no_labels = BaseMap(source='light', labels=None)
        self.voyager_map_no_labels = BaseMap(source='voyager', labels=None)

        # labels with no basemaps
        self.dark_only_labels = BaseMap(source='dark', only_labels=True)
        self.light_only_labels = BaseMap(source='light', only_labels=True)
        self.voyager_only_labels = BaseMap(source='voyager', only_labels=True)

    def test_basemap_repr(self):
        """layer.Basemap.__repr__"""
        self.assertEqual(
            self.dark_only_labels.__repr__(),
            'BaseMap(source=dark, labels=back, only_labels=True)')

    def test_basemap_invalid(self):
        """layer.Basemap exceptions on invalid source"""
        # Raise ValueError if invalid label is entered
        with self.assertRaises(ValueError):
            BaseMap(labels='watermelon')

        # Raise ValueError if custom URL is entered
        with self.assertRaises(ValueError):
            BaseMap(source='http://spinalmap.com/{z}/{x}/{y}.png')

        # Raise ValueError if non-supported style type is entered
        with self.assertRaises(ValueError):
            BaseMap(source='gulab_jamon')

    def test_basemap_source(self):
        """layer.BaseMap with different sources and labels"""

        # ensure correct BaseMap urls are created
        # See URLs here: https://carto.com/location-data-services/basemaps/
        self.assertEqual(
            self.dark_map_all.url,
            'https://{s}.basemaps.cartocdn.com/rastertiles/'
            'dark_all/{z}/{x}/{y}.png')
        self.assertEqual(
            self.light_map_all.url,
            'https://{s}.basemaps.cartocdn.com/rastertiles/'
            'light_all/{z}/{x}/{y}.png')
        self.assertEqual(
            self.voyager_labels_under.url,
            'https://{s}.basemaps.cartocdn.com/rastertiles/'
            'voyager_labels_under/{z}/{x}/{y}.png')
        self.assertEqual(
            self.dark_map_no_labels.url,
            'https://{s}.basemaps.cartocdn.com/rastertiles/'
            'dark_nolabels/{z}/{x}/{y}.png')
        self.assertEqual(
            self.light_map_no_labels.url,
            'https://{s}.basemaps.cartocdn.com/rastertiles/'
            'light_nolabels/{z}/{x}/{y}.png')
        self.assertEqual(
            self.voyager_map_no_labels.url,
            'https://{s}.basemaps.cartocdn.com/rastertiles/'
            'voyager_nolabels/{z}/{x}/{y}.png')
        self.assertEqual(
            self.light_only_labels.url,
            'https://{s}.basemaps.cartocdn.com/rastertiles/'
            'light_only_labels/{z}/{x}/{y}.png')
        self.assertEqual(
            self.dark_only_labels.url,
            'https://{s}.basemaps.cartocdn.com/rastertiles/'
            'dark_only_labels/{z}/{x}/{y}.png')
        self.assertEqual(
            self.voyager_only_labels.url,
            'https://{s}.basemaps.cartocdn.com/rastertiles/'
            'voyager_only_labels/{z}/{x}/{y}.png')

        # ensure self.is_basic() works as intended
        self.assertTrue(self.light_map_all.is_basic(),
                        msg='is a basic carto basemap')
        self.assertTrue(self.dark_map_all.is_basic())
        self.assertTrue(self.voyager_labels_under.is_basic(),
                        msg='is a basic carto basemap')