-
Notifications
You must be signed in to change notification settings - Fork 2
/
tests.py
executable file
·74 lines (51 loc) · 1.94 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#! /usr/bin/env python3
import unittest
import os
import sqlite3
import map_utils
class TestMBTiles (unittest.TestCase):
def setUp (self):
# the bbox is not really important
self.backend= map_utils.MBTilesBackend ('TestMBTiles', [10, 20, 30, 40])
session= sqlite3.connect ('TestMBTiles.mbt')
self.session.set_trace_callback (print)
self.db= session.cursor ()
def test_single_tile (self):
data= open ('sea.png', 'rb').read ()
self.backend.store (0, 0, 0, data)
self.backend.commit ()
self.assertTrue (self.backend.exists (0, 0, 0))
def test_two_seas_one_tile (self):
data= open ('sea.png', 'rb').read ()
self.backend.store (0, 0, 0, data)
self.backend.store (1, 1, 1, data)
self.backend.commit ()
self.backend.close ()
# test two seas
seas= self.db.execute ('select * from map;').fetchall ()
self.assertEqual (len (seas), 2)
# test one id
self.assertEqual (seas[0][3], seas[1][3])
# test one tile
tile= self.db.execute ('select * from images;').fetchall ()
self.assertEqual (len (tile), 1)
# test one id, again
self.assertEqual (seas[0][3], tile[0][0])
# test one view
tiles= self.db.execute ('select * from tiles;').fetchall ()
self.assertEqual (len (tiles), 2)
def test_update (self):
data1= open ('data1.png', 'rb').read ()
data2= open ('data2.png', 'rb').read ()
self.backend.store (0, 0, 0, data1)
self.backend.commit ()
self.backend.store (0, 0, 0, data2)
self.backend.commit ()
self.backend.close ()
data3= self.db.execute ('SELECT tile_data FROM tiles;').fetchall ()
self.assertEqual (data3[0][0], data2)
def tearDown (self):
self.backend.close ()
os.unlink ('TestMBTiles.mbt')
if __name__ == '__main__':
unittest.main(verbosity=2)