本文整理汇总了Python中mapproxy.test.image.create_tmp_image函数的典型用法代码示例。如果您正苦于以下问题:Python create_tmp_image函数的具体用法?Python create_tmp_image怎么用?Python create_tmp_image使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_tmp_image函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_layers_with_opacity
def test_layers_with_opacity(self):
# overlay with opacity -> request should not be combined
common_params = (r'?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')
img_bg = create_tmp_image((200, 200), color=(0, 0, 0))
img_fg = create_tmp_image((200, 200), color=(255, 0, 128))
expected_req = [
({'path': '/service_a' + common_params + '&layers=a_one'},
{'body': img_bg, 'headers': {'content-type': 'image/png'}}),
({'path': '/service_a' + common_params + '&layers=a_two'},
{'body': img_fg, 'headers': {'content-type': 'image/png'}}),
]
with mock_httpd(('localhost', 42423), expected_req):
self.common_map_req.params.layers = 'opacity_base,opacity_overlay'
resp = self.app.get(self.common_map_req)
eq_(resp.content_type, 'image/png')
data = BytesIO(resp.body)
assert is_png(data)
img = Image.open(data)
eq_(img.getcolors()[0], ((200*200),(127, 0, 64)))
示例2: test_get_tile_limited_to
def test_get_tile_limited_to(self):
def auth(service, layers, environ, query_extent, **kw):
eq_(environ['PATH_INFO'], '/wmts/layer3/GLOBAL_MERCATOR/1/0/0.jpeg')
eq_(service, 'wmts')
eq_(len(layers), 1)
eq_(query_extent[0], 'EPSG:900913')
assert bbox_equals(query_extent[1], (-20037508.342789244, 0, 0, 20037508.342789244))
return {
'authorized': 'partial',
'limited_to': {
'geometry': [-180, -89, -90, 89],
'srs': 'EPSG:4326',
},
'layers': {
'layer3': {'tile': True},
}
}
serv = MockServ(port=42423)
serv.expects('/1/0/1.png')
serv.returns(create_tmp_image((256, 256), color=(255, 0, 0)), headers={'content-type': 'image/png'})
with serv:
resp = self.app.get('/wmts/layer3/GLOBAL_MERCATOR/1/0/0.jpeg', extra_environ={'mapproxy.authorize': auth})
eq_(resp.content_type, 'image/png')
img = img_from_buf(resp.body)
img = img.convert('RGBA')
# left part authorized, red
eq_(img.crop((0, 0, 127, 255)).getcolors()[0], (127*255, (255, 0, 0, 255)))
# right part not authorized, transparent
eq_(img.crop((129, 0, 255, 255)).getcolors()[0][1][3], 0)
示例3: test_get_map_uncached
def test_get_map_uncached(self):
mbtiles_file = os.path.join(test_config['base_dir'], 'cache.mbtiles')
tiles_lock_dir = os.path.join(test_config['base_dir'], 'testlockdir')
assert os.path.exists(mbtiles_file) # already created on startup
assert not os.path.exists(tiles_lock_dir)
self.common_map_req.params.bbox = '-180,0,0,80'
serv = MockServ(port=42423)
serv.expects('/tiles/01/000/000/000/000/000/001.png')
serv.returns(create_tmp_image((256, 256)))
with serv:
resp = self.app.get(self.common_map_req)
eq_(resp.content_type, 'image/png')
data = StringIO(resp.body)
assert is_png(data)
# now cached
resp = self.app.get(self.common_map_req)
eq_(resp.content_type, 'image/png')
data = StringIO(resp.body)
assert is_png(data)
# custom tile_lock_dir created
assert os.path.exists(tiles_lock_dir)
示例4: test_get_tile_limited_to_inside
def test_get_tile_limited_to_inside(self):
def auth(service, layers, environ, **kw):
eq_(environ['PATH_INFO'], '/wmts/layer3/GLOBAL_MERCATOR/1/0/0.jpeg')
eq_(service, 'wmts')
eq_(len(layers), 1)
return {
'authorized': 'partial',
'limited_to': {
'geometry': [-180, -89, 180, 89],
'srs': 'EPSG:4326',
},
'layers': {
'layer3': {'tile': True},
}
}
serv = MockServ(port=42423)
serv.expects('/1/0/1.png')
serv.returns(create_tmp_image((256, 256), color=(255, 0, 0)), headers={'content-type': 'image/png'})
with serv:
resp = self.app.get('/wmts/layer3/GLOBAL_MERCATOR/1/0/0.jpeg', extra_environ={'mapproxy.authorize': auth})
eq_(resp.content_type, 'image/jpeg')
img = img_from_buf(resp.body)
eq_(img.getcolors()[0], (256*256, (255, 0, 0)))
示例5: test_sld_file
def test_sld_file(self):
self.common_map_req.params['layers'] = 'sld_file'
with mock_httpd(TESTSERVER_ADDRESS, [
({'path': self.common_wms_url + '&sld_body=' +quote('<sld>'), 'method': 'GET'},
{'body': create_tmp_image((200, 200), format='png')}
)]):
resp = self.app.get(self.common_map_req)
eq_(resp.content_type, 'image/png')
示例6: test_get_tile_flipped_axis
def test_get_tile_flipped_axis(self):
serv = MockServ(port=42423)
# source is ll, cache/service ul
serv.expects("/tiles/01/000/000/000/000/000/001.png")
serv.returns(create_tmp_image((256, 256)))
with serv:
resp = self.app.get("/wmts/myrest/tms_cache_ul/ulgrid/01/0/0.png", status=200)
eq_(resp.content_type, "image/png")
示例7: test_get_tile_flipped_axis
def test_get_tile_flipped_axis(self):
self.common_tile_req.params['layer'] = 'tms_cache_ul'
self.common_tile_req.params['tilematrixset'] = 'ulgrid'
self.common_tile_req.params['format'] = 'image/png'
self.common_tile_req.tile = (0, 0, '01')
serv = MockServ(port=42423)
# source is ll, cache/service ul
serv.expects('/tiles/01/000/000/000/000/000/001.png')
serv.returns(create_tmp_image((256, 256)))
with serv:
resp = self.app.get(str(self.common_tile_req), status=200)
eq_(resp.content_type, 'image/png')
示例8: test_get_map_cached
def test_get_map_cached(self):
# mock_s3 interferes with MockServ, use boto to manually upload tile
tile = create_tmp_image((256, 256))
boto3.client("s3").upload_fileobj(
BytesIO(tile),
Bucket='default_bucket',
Key='default_cache/WebMerc/4/1/9.png',
)
resp = self.app.get(self.common_map_req)
eq_(resp.content_type, 'image/png')
data = BytesIO(resp.body)
assert is_png(data)
示例9: test_get_map_cached_quadkey
def test_get_map_cached_quadkey(self):
# mock_s3 interferes with MockServ, use boto to manually upload tile
tile = create_tmp_image((256, 256))
boto3.client("s3").upload_fileobj(
BytesIO(tile),
Bucket='tiles',
Key='quadkeytiles/2003.png',
)
self.common_map_req.params.layers = 'quadkey'
resp = self.app.get(self.common_map_req)
eq_(resp.content_type, 'image/png')
data = BytesIO(resp.body)
assert is_png(data)
示例10: test_seed_refresh_remove_before_from_file
def test_seed_refresh_remove_before_from_file(self):
# tile already there but old
t000 = self.make_tile((0, 0, 0), timestamp=time.time() - (60*60*25))
# mtime is older than tile, no create of the tile
timestamp = time.time() - (60*60*30)
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)
# touch the seed_conf file and refresh everything
os.utime(self.seed_conf_file, None)
img_data = create_tmp_image((256, 256), format='png')
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
# mtime is older than tile, no cleanup
timestamp = time.time() - 5
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)
cleanup_tasks = seed_conf.cleanups(['remove_from_file'])
cleanup(cleanup_tasks, verbose=False, dry_run=False)
assert os.path.exists(t000)
# now touch the seed_conf again and remove everything
timestamp = time.time() + 5
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)
cleanup_tasks = seed_conf.cleanups(['remove_from_file'])
cleanup(cleanup_tasks, verbose=False, dry_run=False)
assert not os.path.exists(t000)
示例11: test_get_map_uncached
def test_get_map_uncached(self):
self.common_map_req.params.bbox = '-180,0,0,80'
serv = MockServ(port=42423)
serv.expects('/tiles/01/000/000/000/000/000/001.png')
serv.returns(create_tmp_image((256, 256)))
with serv:
resp = self.app.get(self.common_map_req)
eq_(resp.content_type, 'image/png')
data = StringIO(resp.body)
assert is_png(data)
# now cached
resp = self.app.get(self.common_map_req)
eq_(resp.content_type, 'image/png')
data = StringIO(resp.body)
assert is_png(data)
示例12: test_get_map_uncached
def test_get_map_uncached(self):
assert os.path.exists(os.path.join(test_config['base_dir'], 'cache.gpkg')) # already created on startup
self.common_map_req.params.bbox = '-180,0,0,80'
serv = MockServ(port=42423)
serv.expects('/tiles/01/000/000/000/000/000/001.png')
serv.returns(create_tmp_image((256, 256)))
with serv:
resp = self.app.get(self.common_map_req)
eq_(resp.content_type, 'image/png')
data = BytesIO(resp.body)
assert is_png(data)
# now cached
resp = self.app.get(self.common_map_req)
eq_(resp.content_type, 'image/png')
data = BytesIO(resp.body)
assert is_png(data)
示例13: test_get_tile_flipped_axis
def test_get_tile_flipped_axis(self):
# test default tile lock directory
tiles_lock_dir = os.path.join(test_config['base_dir'], 'cache_data', 'tile_locks')
# make sure default tile_lock_dir was not created by other tests
shutil.rmtree(tiles_lock_dir, ignore_errors=True)
assert not os.path.exists(tiles_lock_dir)
self.common_tile_req.params['layer'] = 'tms_cache_ul'
self.common_tile_req.params['tilematrixset'] = 'ulgrid'
self.common_tile_req.params['format'] = 'image/png'
self.common_tile_req.tile = (0, 0, '01')
serv = MockServ(port=42423)
# source is ll, cache/service ul
serv.expects('/tiles/01/000/000/000/000/000/001.png')
serv.returns(create_tmp_image((256, 256)))
with serv:
resp = self.app.get(str(self.common_tile_req), status=200)
eq_(resp.content_type, 'image/png')
# test default tile lock directory was created
assert os.path.exists(tiles_lock_dir)
示例14: check_get_tile_limited_to
def check_get_tile_limited_to(self, auth_dict):
def auth(service, layers, environ, query_extent, **kw):
eq_(environ['PATH_INFO'], '/kml/layer3_EPSG900913/1/0/0.jpeg')
eq_(service, 'kml')
eq_(len(layers), 1)
eq_(query_extent[0], 'EPSG:900913')
assert bbox_equals(query_extent[1], (-20037508.342789244, -20037508.342789244, 0, 0))
return auth_dict
serv = MockServ(port=42423)
serv.expects('/1/0/0.png')
serv.returns(create_tmp_image((256, 256), color=(255, 0, 0)), headers={'content-type': 'image/png'})
with serv:
resp = self.app.get('/kml/layer3_EPSG900913/1/0/0.jpeg', extra_environ={'mapproxy.authorize': auth})
eq_(resp.content_type, 'image/png')
img = img_from_buf(resp.body)
img = img.convert('RGBA')
# left part authorized, red
eq_(img.crop((0, 0, 127, 255)).getcolors()[0], (127*255, (255, 0, 0, 255)))
# right part not authorized, transparent
eq_(img.crop((129, 0, 255, 255)).getcolors()[0][1][3], 0)
示例15: do_POST
def do_POST(self):
length = int(self.headers['content-length'])
json_data = self.rfile.read(length)
task = json.loads(json_data.decode('utf-8'))
eq_(task['command'], 'tile')
# request main tile of metatile
eq_(task['tiles'], [[15, 17, 5]])
eq_(task['cache_identifier'], 'wms_cache_GLOBAL_MERCATOR')
eq_(task['priority'], 100)
# this id should not change for the same tile/cache_identifier combination
eq_(task['id'], 'aeb52b506e4e82d0a1edf649d56e0451cfd5862c')
# manually create tile renderd should create
tile_filename = os.path.join(test_self.config['cache_dir'],
'wms_cache_EPSG900913/05/000/000/016/000/000/016.jpeg')
ensure_directory(tile_filename)
with open(tile_filename, 'wb') as f:
f.write(create_tmp_image((256, 256), format='jpeg', color=(255, 0, 100)))
self.send_response(200)
self.send_header('Content-type', 'application/json')
self.end_headers()
self.wfile.write(b'{"status": "ok"}')