Skip to content

Commit 9aef996

Browse files
committed
feat: add initial pre-commit config
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
1 parent 26a005f commit 9aef996

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

.pre-commit-config.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# We use poetry to run formatting and linting before commit/push
2+
# Longers checks such as tests, security and complexity baseline
3+
# are run as part of CI to prevent slower feedback loop
4+
# All checks can be run locally via `make pr`
5+
6+
repos:
7+
- repo: local
8+
hooks:
9+
- id: black
10+
name: formatting::black
11+
entry: poetry run black
12+
language: system
13+
types: [python]
14+
- id: isort
15+
name: formatting::isort
16+
entry: poetry run isort -rc
17+
language: system
18+
types: [python]
19+
- repo: local
20+
hooks:
21+
- id: flake8
22+
name: linting::flake8
23+
entry: poetry run flake8
24+
language: system
25+
types: [python]
26+
exclude: example
27+
fail_fast: true

example/hello_world/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
_cold_start = True
2222

23-
metrics.add_dimension(name="operation", value="example") # added at cold start only
23+
metrics.add_dimension(name="operation", value="example") # added at cold start only
2424

2525

2626
async def aioboto_task():

example/tests/test_handler.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from hello_world import app
77

8+
89
@pytest.fixture()
910
def apigw_event():
1011
""" Generates API GW Event"""
@@ -61,30 +62,32 @@ def apigw_event():
6162
"path": "/examplepath",
6263
}
6364

65+
6466
@dataclass
6567
class Context:
6668
function_name: str = "test"
6769
memory_limit_in_mb: int = 128
6870
invoked_function_arn: str = "arn:aws:lambda:eu-west-1:298026489:function:test"
6971
aws_request_id: str = "5b441b59-a550-11c8-6564-f1c833cf438c"
7072

73+
7174
def test_lambda_handler(apigw_event, mocker, capsys):
7275
ret = app.lambda_handler(apigw_event, Context())
7376
data = json.loads(ret["body"])
7477

7578
output = capsys.readouterr()
76-
output = output.out.split('\n')
77-
stdout_one_string = '\t'.join(output)
79+
output = output.out.split("\n")
80+
stdout_one_string = "\t".join(output)
7881

7982
assert ret["statusCode"] == 200
8083
assert data["message"] == "hello world"
8184
assert "location" in data
8285
assert "message" in ret["body"]
8386
assert "async_http" in data
84-
87+
8588
# assess custom metric was flushed in stdout/logs
86-
assert "SuccessfulLocations" in stdout_one_string
87-
assert "ColdStart" in stdout_one_string
89+
assert "SuccessfulLocations" in stdout_one_string
90+
assert "ColdStart" in stdout_one_string
8891
assert "UniqueMetricDimension" in stdout_one_string
8992

9093
# assess our custom middleware ran

0 commit comments

Comments
 (0)