Exemplo n.º 1
0
    def test_create(self):
        # Make a new file if it doesn't exist
        os.remove(self.tempfile.name)
        storage = MbtilesStorage.create(renderer=self.renderer,
                                        filename=self.tempfile.name,
                                        metadata=self.metadata)
        self.assertEqual(storage.filename, self.tempfile.name)
        self.assertEqual(storage.mbtiles.metadata, self.metadata)
        self.assertTrue(os.path.isfile(self.tempfile.name))

        # Make a duplicate file
        MbtilesStorage.create(renderer=self.renderer,
                              filename=self.tempfile.name,
                              metadata=self.metadata)
        self.assertEqual(storage.filename, self.tempfile.name)
        self.assertTrue(os.path.isfile(self.tempfile.name))
Exemplo n.º 2
0
 def setUp(self):
     self.tempfile = NamedTemporaryFile()
     # Use the PngRenderer because we want to know that callback
     # works properly.
     self.renderer = PngRenderer(png8=False, optimize=False)
     self.metadata = dict(
         name='transparent',
         type=Metadata.latest().TYPES.BASELAYER,
         version='1.0.0',
         description='Transparent World 2012',
         format=Metadata.latest().FORMATS.PNG,
     )
     self.storage = MbtilesStorage.create(renderer=self.renderer,
                                          filename=':memory:',
                                          metadata=self.metadata)
Exemplo n.º 3
0
    def test_save(self):
        # We must create this on disk
        self.storage = MbtilesStorage.create(renderer=self.renderer,
                                             filename=self.tempfile.name,
                                             metadata=self.metadata)

        # Transparent 1×1 image
        image = VImage.new_rgba(width=1, height=1,
                                ink=rgba(r=0, g=0, b=0, a=0))

        # Save it twice, assuming that MBTiles will deduplicate
        self.storage.save(x=0, y=1, z=2, image=image)
        self.storage.save(x=1, y=0, z=2, image=image)
        self.storage.waitall()

        # Assert that things were saved properly
        self.assertEqual(
            [(z, x, y, intmd5(data))
             for z, x, y, data in self.storage.mbtiles.all()],
            [
                (2, 0, 1, 89446660811628514001822794642426893173),
                (2, 1, 0, 89446660811628514001822794642426893173),
            ]
        )

        # Close the existing database.
        self.storage.mbtiles.close()

        # Re-open the created file
        storage = MbtilesStorage(renderer=self.renderer,
                                 filename=self.tempfile.name)

        # Read out of the backend
        self.assertEqual(
            [(z, x, y, intmd5(data))
             for z, x, y, data in storage.mbtiles.all()],
            [
                (2, 0, 1, 89446660811628514001822794642426893173),
                (2, 1, 0, 89446660811628514001822794642426893173),
            ]
        )