本文整理汇总了Python中mapproxy.test.image.tmp_image函数的典型用法代码示例。如果您正苦于以下问题:Python tmp_image函数的具体用法?Python tmp_image怎么用?Python tmp_image使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了tmp_image函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_combined_mixed_fwd_req_params
def test_combined_mixed_fwd_req_params(self):
# not merged to one request because fwd_req_params are different
common_params = (r'/service_a?SERVICE=WMS&FORMAT=image%2Fpng'
'&REQUEST=GetMap&HEIGHT=200&SRS=EPSG%3A4326&styles='
'&VERSION=1.1.1&BBOX=9.0,50.0,10.0,51.0'
'&WIDTH=200&transparent=True')
with tmp_image((200, 200), format='png') as img:
img = img.read()
expected_req = [({'path': common_params + '&layers=a_one&TIME=20041012'},
{'body': img, 'headers': {'content-type': 'image/png'}}),
({'path': common_params + '&layers=a_two&TIME=20041012&VENDOR=foo'},
{'body': img, 'headers': {'content-type': 'image/png'}}),
({'path': common_params + '&layers=a_four'},
{'body': img, 'headers': {'content-type': 'image/png'}}),
]
with mock_httpd(('localhost', 42423), expected_req):
self.common_map_req.params.layers = 'layer_fwdparams1,single'
self.common_map_req.params['time'] = '20041012'
self.common_map_req.params['vendor'] = 'foo'
self.common_map_req.params.transparent = True
resp = self.app.get(self.common_map_req)
resp.content_type = 'image/png'
data = BytesIO(resp.body)
assert is_png(data)
示例2: test_seed_refresh_remove_before_from_file
def test_seed_refresh_remove_before_from_file(self):
# tile already there but too old, will be refreshed and removed
t000 = self.make_tile((0, 0, 0), timestamp=time.time() - (60*60*25))
with tmp_image((256, 256), format='png') as img:
img_data = img.read()
expected_req = ({'path': r'/service?LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng'
'&REQUEST=GetMap&VERSION=1.1.1&bbox=-180.0,-90.0,180.0,90.0'
'&width=256&height=128&srs=EPSG:4326'},
{'body': img_data, 'headers': {'content-type': 'image/png'}})
with mock_httpd(('localhost', 42423), [expected_req]):
# touch the seed_conf file and refresh everything
timestamp = time.time() - 60
os.utime(self.seed_conf_file, (timestamp, timestamp))
with local_base_config(self.mapproxy_conf.base_config):
seed_conf = load_seed_tasks_conf(self.seed_conf_file, self.mapproxy_conf)
tasks = seed_conf.seeds(['refresh_from_file'])
seed(tasks, dry_run=False)
assert os.path.exists(t000)
assert os.path.getmtime(t000) - 5 < time.time() < os.path.getmtime(t000) + 5
# now touch the seed_conf again and remove everything
os.utime(self.seed_conf_file, None)
with local_base_config(self.mapproxy_conf.base_config):
seed_conf = load_seed_tasks_conf(self.seed_conf_file, self.mapproxy_conf)
cleanup_tasks = seed_conf.cleanups(['remove_from_file'])
cleanup(cleanup_tasks, verbose=False, dry_run=False)
示例3: test_get_tile_intersection_tms
def test_get_tile_intersection_tms(self):
with tmp_image((256, 256), format='jpeg') as img:
expected_req = ({'path': r'/tms/1.0.0/foo/1/1/1.jpeg'},
{'body': img.read(), 'headers': {'content-type': 'image/jpeg'}})
with mock_httpd(('localhost', 42423), [expected_req]):
resp = self.app.get('/tms/1.0.0/tms_cache/0/1/1.jpeg')
eq_(resp.content_type, 'image/jpeg')
self.created_tiles.append('tms_cache_EPSG900913/01/000/000/001/000/000/001.jpeg')
示例4: test_get_tile_without_caching
def test_get_tile_without_caching(self):
with tmp_image((256, 256), format='png') as img:
expected_req = ({'path': r'/tile.png'},
{'body': img.read(), 'headers': {'content-type': 'image/png'}})
with mock_httpd(('localhost', 42423), [expected_req]):
resp = self.app.get('/tms/1.0.0/tiles/0/0/0.png')
eq_(resp.content_type, 'image/png')
is_png(resp.body)
assert not os.path.exists(test_config['cache_dir'])
with tmp_image((256, 256), format='png') as img:
expected_req = ({'path': r'/tile.png'},
{'body': img.read(), 'headers': {'content-type': 'image/png'}})
with mock_httpd(('localhost', 42423), [expected_req]):
resp = self.app.get('/tms/1.0.0/tiles/0/0/0.png')
eq_(resp.content_type, 'image/png')
is_png(resp.body)
示例5: check_get_cached
def check_get_cached(self, layer, source, tms_format, cache_format, req_format):
self.created_tiles.append((layer+'_EPSG900913/01/000/000/001/000/000/001.'+cache_format, cache_format))
with tmp_image((256, 256), format=req_format) as img:
expected_req = ({'path': self.expected_base_path +
'&layers=' + source +
'&format=image%2F' + req_format},
{'body': img.read(), 'headers': {'content-type': 'image/'+req_format}})
with mock_httpd(('localhost', 42423), [expected_req], bbox_aware_query_comparator=True):
resp = self.app.get('/tms/1.0.0/%s/0/1/1.%s' % (layer, tms_format))
eq_(resp.content_type, 'image/'+tms_format)
示例6: tile_server
def tile_server(tile_coords):
with tmp_image((256, 256), format='jpeg') as img:
img = img.read()
expected_reqs = []
for tile in tile_coords:
expected_reqs.append(
({'path': r'/tiles/%d/%d/%d.png' % (tile[2], tile[0], tile[1])},
{'body': img, 'headers': {'content-type': 'image/png'}}))
with mock_httpd(('localhost', 42423), expected_reqs, unordered=True):
yield
示例7: test_get_tile_intersections
def test_get_tile_intersections(self):
with tmp_image((256, 256), format='jpeg') as img:
expected_req = ({'path': r'/service?LAYERs=foo,bar&SERVICE=WMS&FORMAT=image%2Fjpeg'
'&REQUEST=GetMap&HEIGHT=25&SRS=EPSG%3A900913&styles='
'&VERSION=1.1.1&BBOX=1113194.90793,1689200.13961,3339584.7238,3632749.14338'
'&WIDTH=28'},
{'body': img.read(), 'headers': {'content-type': 'image/jpeg'}})
with mock_httpd(('localhost', 42423), [expected_req]):
resp = self.app.get('/tms/1.0.0/wms_cache/0/1/1.jpeg')
eq_(resp.content_type, 'image/jpeg')
self.created_tiles.append('wms_cache_EPSG900913/01/000/000/001/000/000/001.jpeg')
示例8: test_get_tile
def test_get_tile(self):
with tmp_image((256, 256), format='jpeg') as img:
expected_req = ({'path': r'/service?LAYERs=bar&SERVICE=WMS&FORMAT=image%2Fjpeg'
'&REQUEST=GetMap&HEIGHT=256&SRS=EPSG%3A25832&styles='
'&VERSION=1.1.1&BBOX=283803.311362,5609091.90862,319018.942566,5644307.53982'
'&WIDTH=256'},
{'body': img.read(), 'headers': {'content-type': 'image/jpeg'}})
with mock_httpd(('localhost', 42423), [expected_req]):
resp = self.app.get('/tms/1.0.0/wms_cache/utm32n/4/2/2.jpeg')
eq_(resp.content_type, 'image/jpeg')
self.created_tiles.append('wms_cache/utm32n/04/000/000/002/000/000/002.jpeg')
示例9: test_get_tile_with_watermark_cache
def test_get_tile_with_watermark_cache(self):
with tmp_image((256, 256), format='png', color=(0, 0, 0)) as img:
expected_req = ({'path': r'/tiles/01/000/000/000/000/000/000.png'},
{'body': img.read(), 'headers': {'content-type': 'image/png'}})
with mock_httpd(('localhost', 42423), [expected_req]):
resp = self.app.get('/tms/1.0.0/watermark_cache/0/0/0.png')
eq_(resp.content_type, 'image/png')
img = Image.open(BytesIO(resp.body))
colors = img.getcolors()
assert len(colors) >= 2
eq_(sorted(colors)[-1][1], (0, 0, 0))
示例10: check_get_direct
def check_get_direct(self, layer, source, wms_format, req_format):
with tmp_image((256, 256), format=req_format) as img:
expected_req = ({'path': self.expected_direct_base_path +
'&layers=' + source +
'&format=image%2F' + req_format},
{'body': img.read(), 'headers': {'content-type': 'image/'+req_format}})
with mock_httpd(('localhost', 42423), [expected_req], bbox_aware_query_comparator=True):
self.common_direct_map_req.params['layers'] = layer
self.common_direct_map_req.params['format'] = 'image/'+wms_format
resp = self.app.get(self.common_direct_map_req)
eq_(resp.content_type, 'image/'+wms_format)
check_format(BytesIO(resp.body), wms_format)
示例11: test_02_get_legendgraphic_layer_static_url
def test_02_get_legendgraphic_layer_static_url(self):
self.common_lg_req_111.params['layer'] = 'wms_layer_static_url'
with tmp_image((256, 256), format='png') as img:
img_data = img.read()
expected_req1 = ({'path': r'/staticlegend_layer.png'},
{'body': img_data, 'headers': {'content-type': 'image/png'}})
with mock_httpd(('localhost', 42423), [expected_req1]):
resp = self.app.get(self.common_lg_req_111)
eq_(resp.content_type, 'image/png')
data = StringIO(resp.body)
assert is_png(data)
assert Image.open(data).size == (256,256)
示例12: test_seed
def test_seed(self):
with tmp_image((256, 256), format='png') as img:
img_data = img.read()
expected_req = ({'path': r'/service?LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng'
'&REQUEST=GetMap&VERSION=1.1.1&bbox=-180.0,-90.0,180.0,90.0'
'&width=256&height=128&srs=EPSG:4326'},
{'body': img_data, 'headers': {'content-type': 'image/png'}})
with mock_httpd(('localhost', 42423), [expected_req]):
seed_conf = load_seed_tasks_conf(self.seed_conf_file, self.mapproxy_conf)
tasks, cleanup_tasks = seed_conf.seeds(['one']), seed_conf.cleanups()
seed(tasks, dry_run=False)
cleanup(cleanup_tasks, verbose=False, dry_run=False)
示例13: test_get_map
def test_get_map(self):
with tmp_image((512, 512)) as img:
expected_req = ({'path': r'/service?LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng'
'&REQUEST=GetMap&HEIGHT=512&SRS=EPSG%3A4326&styles='
'&VERSION=1.1.1&BBOX=0.0,10.0,10.0,20.0&WIDTH=512'},
{'body': img.read(), 'headers': {'content-type': 'image/png'}})
with mock_httpd(TEST_SERVER_ADDRESS, [expected_req]):
q = MapQuery((0.0, 10.0, 10.0, 20.0), (512, 512), SRS(4326))
result = self.source.get_map(q)
assert isinstance(result, ImageSource)
eq_(result.size, (512, 512))
assert is_png(result.as_buffer(seekable=True))
eq_(result.as_image().size, (512, 512))
示例14: check_get_cached
def check_get_cached(self, layer, source, wms_format, cache_format, req_format):
self.created_tiles.append((layer+'_EPSG900913/01/000/000/001/000/000/001.'+cache_format, cache_format))
with tmp_image((256, 256), format=req_format) as img:
expected_req = ({'path': self.expected_base_path +
'&layers=' + source +
'&format=image%2F' + req_format},
{'body': img.read(), 'headers': {'content-type': 'image/'+req_format}})
with mock_httpd(('localhost', 42423), [expected_req]):
self.common_map_req.params['layers'] = layer
self.common_map_req.params['format'] = 'image/'+wms_format
resp = self.app.get(self.common_map_req)
eq_(resp.content_type, 'image/'+wms_format)
check_format(StringIO(resp.body), wms_format)
示例15: test_transparent_watermark_tile
def test_transparent_watermark_tile(self):
with tmp_image((256, 256), format='png', color=(0, 0, 0, 0), mode='RGBA') as img:
expected_req = ({'path': r'/service?LAYERs=blank&SERVICE=WMS&FORMAT=image%2Fpng'
'&REQUEST=GetMap&HEIGHT=256&SRS=EPSG%3A4326&styles='
'&VERSION=1.1.1&BBOX=-180.0,-90.0,0.0,90.0'
'&WIDTH=256'},
{'body': img.read(), 'headers': {'content-type': 'image/jpeg'}})
with mock_httpd(('localhost', 42423), [expected_req]):
resp = self.app.get('/tms/1.0.0/watermark_transp/EPSG4326/0/0/0.png')
eq_(resp.content_type, 'image/png')
img = Image.open(BytesIO(resp.body))
colors = img.getcolors()
assert len(colors) >= 2
eq_(sorted(colors)[-1][1], (0, 0, 0, 0))