improvements to CI test suite

This commit is contained in:
Brandon Liu
2022-07-20 16:13:14 +08:00
parent bde4a2f75c
commit be57f1f61d
8 changed files with 142 additions and 35 deletions

View File

@@ -5,6 +5,7 @@ sha = subprocess.check_output(["git", "describe", "--always"]).strip()
with zipfile.ZipFile("lambda_function.zip", "w", zipfile.ZIP_DEFLATED) as z:
z.write("lambda_function.py")
z.write("util.py")
z.write("../../python/pmtiles/reader.py", "pmtiles/reader.py")
z.writestr("version",sha)

View File

@@ -1,10 +1,8 @@
import base64
import collections
from functools import lru_cache
import gzip
import json
import os
import re
# Exists inside all lambda functions
import boto3
@@ -12,8 +10,7 @@ from botocore.exceptions import ClientError
# create_lambda_function.py will vendor the relevant file
from pmtiles.reader import Reader
Zxy = collections.namedtuple("Zxy", ["z", "x", "y"])
from util import pmtiles_path, parse_tile_path
s3 = boto3.client("s3")
@@ -33,29 +30,6 @@ def get_object_bytes(key, offset, length):
)
def pmtiles_path(p, name):
if not p:
p = "{name}.pmtiles"
return p.replace("{name}", name)
def parse_tile_path(p, str):
if not p:
p = "/{name}/{z}/{x}/{y}.pbf"
p = re.escape(p)
p = p.replace(r"\{name\}", r"(?P<name>[0-9a-zA-Z/!\-_\.\*'\(\)]+)")
p = p.replace(r"\{z\}", r"(?P<z>\d+)")
p = p.replace(r"\{x\}", r"(?P<x>\d+)")
p = p.replace(r"\{y\}", r"(?P<y>\d+)")
m = re.match(f"^{p}$", str)
if not m:
return None, None
return (
m.group("name"),
Zxy(int(m.group("z")), int(m.group("x")), int(m.group("y"))),
)
# Assumes event is a API Gateway V2 or Lambda Function URL formatted dict
# and returns API Gateway V2 / Lambda Function dict responses
# Does not work with CloudFront events/Lambda@Edge; see README

View File

@@ -1,5 +1,5 @@
import unittest
from lambda_function import parse_tile_path, pmtiles_path
from util import parse_tile_path, pmtiles_path
class TestLambda(unittest.TestCase):
@@ -48,7 +48,3 @@ class TestLambda(unittest.TestCase):
pmtiles_path("folder/{name}.pmtiles", "foo/bar"),
"folder/foo/bar.pmtiles",
)
if __name__ == "__main__":
unittest.main()

27
serverless/aws/util.py Normal file
View File

@@ -0,0 +1,27 @@
import collections
import re
Zxy = collections.namedtuple("Zxy", ["z", "x", "y"])
def pmtiles_path(p, name):
if not p:
p = "{name}.pmtiles"
return p.replace("{name}", name)
def parse_tile_path(p, str):
if not p:
p = "/{name}/{z}/{x}/{y}.pbf"
p = re.escape(p)
p = p.replace(r"\{name\}", r"(?P<name>[0-9a-zA-Z/!\-_\.\*'\(\)]+)")
p = p.replace(r"\{z\}", r"(?P<z>\d+)")
p = p.replace(r"\{x\}", r"(?P<x>\d+)")
p = p.replace(r"\{y\}", r"(?P<y>\d+)")
m = re.match(f"^{p}$", str)
if not m:
return None, None
return (
m.group("name"),
Zxy(int(m.group("z")), int(m.group("x")), int(m.group("y"))),
)