Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Rename TileStore.count to TileStore.__len__

  • Loading branch information...
commit 446eba0ea31f2c87da23d6d251cfb0f92d08691c 1 parent ec6bd5f
@fredj fredj authored
View
2  tc-info
@@ -49,7 +49,7 @@ def main(argv):
print '%d %d/%d (%d%%)' % (z, numerator, denominator,
100 * numerator / denominator)
elif options.tiles == 'count':
- print tile_store.count()
+ print len(tile_store)
elif options.tiles == 'estimate-completion':
bounding_pyramid = \
BoundingPyramid.from_string(options.bounding_pyramid)
View
2  tilecloud/__init__.py
@@ -420,7 +420,7 @@ def __contains__(self, tile):
else:
return False
- def count(self):
+ def __len__(self):
"""Returns the total number of tiles in the store"""
return reduce(lambda x, _: x + 1, ifilter(None, self.list()), 0)
View
2  tilecloud/store/bsddb.py
@@ -12,7 +12,7 @@ def __init__(self, db, **kwargs):
def __contains__(self, tile):
return tile and str(tile.tilecoord) in self.db
- def count(self):
+ def __len__(self):
return len(self.db)
def delete_one(self, tile):
View
2  tilecloud/store/dict.py
@@ -10,7 +10,7 @@ def __init__(self, tiles=None, **kwargs):
def __contains__(self, tile):
return tile and tile.tilecoord in self.tiles
- def count(self):
+ def __len__(self):
return len(self.tiles)
def delete_one(self, tile):
View
2  tilecloud/store/mbtiles.py
@@ -66,7 +66,7 @@ def __init__(self, connection, commit=True, **kwargs):
def __contains__(self, tile):
return tile and tile.tilecoord in self.tiles
- def count(self):
+ def __len__(self):
return len(self.tiles)
def delete_one(self, tile):
View
14 tilecloud/tests/test_tilestore.py
@@ -13,7 +13,7 @@ def test_empty(self):
ts = TileStore()
self.assertEqual(ts.bounding_pyramid, None)
self.assertEqual(ts.content_type, None)
- self.assertEqual(ts.count(), 0)
+ self.assertEqual(len(ts), 0)
self.assertRaises(NotImplementedError, next, ts.delete((Tile(TileCoord(0, 0, 0)),)))
self.assertRaises(NotImplementedError, ts.delete_one, None)
self.assertEqual(ts.get_cheap_bounding_pyramid(), None)
@@ -57,12 +57,12 @@ class TestDictTileStore(unittest.TestCase):
def test_empty(self):
tile_store = DictTileStore()
- self.assertEqual(tile_store.count(), 0)
+ self.assertEqual(len(tile_store), 0)
self.assertEqual(list(tile_store.list()), [])
def test_one(self):
tile_store = DictTileStore()
- self.assertEqual(tile_store.count(), 0)
+ self.assertEqual(len(tile_store), 0)
tilestream = [Tile(TileCoord(1, 0, 0), data='data'), None, Tile(TileCoord(1, 0, 1), error=True)]
tilestream = tile_store.put(tilestream)
tiles = list(tilestream)
@@ -95,11 +95,11 @@ class TestMBTilesTileStore(unittest.TestCase):
def test_one(self):
tile_store = MBTilesTileStore(sqlite3.connect(':memory:'), content_type='image/png')
- self.assertEqual(tile_store.count(), 0)
+ self.assertEqual(len(tile_store), 0)
tilestream = [Tile(TileCoord(1, 0, 0), data='data'), None, Tile(TileCoord(1, 0, 1), error=True)]
tilestream = tile_store.put(tilestream)
tiles = list(tilestream)
- self.assertEqual(tile_store.count(), 2)
+ self.assertEqual(len(tile_store), 2)
self.assertEqual(len(tiles), 2)
self.assertEqual(tiles[0].tilecoord, TileCoord(1, 0, 0))
self.assertEqual(tiles[0].data, 'data')
@@ -111,7 +111,7 @@ def test_one(self):
tilestream = tile_store.get(tilestream)
consume(tilestream, None)
self.assertEqual(tile_store.get_cheap_bounding_pyramid(), BoundingPyramid({1: (Bounds(0, 1), Bounds(0, 2))}))
- self.assertEqual(tile_store.count(), 2)
+ self.assertEqual(len(tile_store), 2)
tiles = list(tile_store.list())
self.assertEqual(len(tiles), 2)
tiles = sorted(tile_store.get_all())
@@ -123,7 +123,7 @@ def test_one(self):
tilestream = [Tile(TileCoord(1, 0, 0))]
tilestream = tile_store.delete(tilestream)
consume(tilestream, None)
- self.assertEqual(tile_store.count(), 1)
+ self.assertEqual(len(tile_store), 1)
tiles = list(tile_store.get_all())
self.assertEqual(len(tiles), 1)
self.assertFalse(Tile(TileCoord(1, 0, 0)) in tile_store)
Please sign in to comment.
Something went wrong with that request. Please try again.