From ea9f092452b4cd8d6d7a1b059bb51d9a9e27e061 Mon Sep 17 00:00:00 2001 From: Delena Malan Date: Mon, 18 Dec 2023 15:11:42 +0200 Subject: [PATCH 1/3] Run Black --- mangum/handlers/alb.py | 1 - mangum/protocols/http.py | 1 - mangum/protocols/lifespan.py | 2 -- 3 files changed, 4 deletions(-) diff --git a/mangum/handlers/alb.py b/mangum/handlers/alb.py index 875c4ee..c98cd82 100644 --- a/mangum/handlers/alb.py +++ b/mangum/handlers/alb.py @@ -104,7 +104,6 @@ def body(self) -> bytes: @property def scope(self) -> Scope: - headers = transform_headers(self.event) list_headers = [list(x) for x in headers] # Unique headers. If there are duplicates, it will use the last defined. diff --git a/mangum/protocols/http.py b/mangum/protocols/http.py index b43b11b..942bb24 100644 --- a/mangum/protocols/http.py +++ b/mangum/protocols/http.py @@ -93,7 +93,6 @@ async def send(self, message: Message) -> None: self.state is HTTPCycleState.RESPONSE and message["type"] == "http.response.body" ): - body = message.get("body", b"") more_body = message.get("more_body", False) self.buffer.write(body) diff --git a/mangum/protocols/lifespan.py b/mangum/protocols/lifespan.py index ca87392..5b27b0b 100644 --- a/mangum/protocols/lifespan.py +++ b/mangum/protocols/lifespan.py @@ -98,14 +98,12 @@ async def run(self) -> None: async def receive(self) -> Message: """Awaited by the application to receive ASGI `lifespan` events.""" if self.state is LifespanCycleState.CONNECTING: - # Connection established. The next event returned by the queue will be # `lifespan.startup` to inform the application that the connection is # ready to receive lfiespan messages. self.state = LifespanCycleState.STARTUP elif self.state is LifespanCycleState.STARTUP: - # Connection shutting down. The next event returned by the queue will be # `lifespan.shutdown` to inform the application that the connection is now # closing so that it may perform cleanup. From a2c8eb0343e7a5baa39f502fec23a13b4647df27 Mon Sep 17 00:00:00 2001 From: Delena Malan Date: Mon, 18 Dec 2023 15:18:39 +0200 Subject: [PATCH 2/3] Add separate linting workflow --- .github/workflows/lint.yml | 27 +++++++++++++++++++++++++++ .github/workflows/test.yml | 15 +++------------ 2 files changed, 30 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..94668a7 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,27 @@ +name: Lint + +on: + push: + branches: ["main"] + pull_request: + branches: ["main"] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.10"] + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + cache: 'pip' + - name: Install dependencies + run: | + pip install -U -r requirements.txt + - name: Run linters + run: | + scripts/lint diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7d28d50..a8692a0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,26 +13,17 @@ jobs: matrix: python-version: ["3.7", "3.8", "3.9", "3.10"] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - - uses: actions/cache@v2 - name: Configure pip caching - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/setup.py') }} - restore-keys: | - ${{ runner.os }}-pip- + cache: 'pip' - name: Install dependencies run: | pip install -U -r requirements.txt - name: Run tests run: | scripts/test - - name: Run linters - run: | - scripts/lint - name: Run codecov run: codecov From 351fa53cf964580675b3cf5ade77382ad2fc1517 Mon Sep 17 00:00:00 2001 From: Delena Malan Date: Mon, 18 Dec 2023 15:30:11 +0200 Subject: [PATCH 3/3] Fix flake8 errors --- tests/handlers/test_alb.py | 2 +- tests/handlers/test_api_gateway.py | 2 +- tests/handlers/test_custom.py | 2 +- tests/handlers/test_http_gateway.py | 4 ++-- tests/handlers/test_lambda_at_edge.py | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/handlers/test_alb.py b/tests/handlers/test_alb.py index e75d2d9..5f99130 100644 --- a/tests/handlers/test_alb.py +++ b/tests/handlers/test_alb.py @@ -205,7 +205,7 @@ def test_aws_alb_scope_real( if scope_path == "": scope_path = "/" - assert type(handler.body) == bytes + assert type(handler.body) is bytes assert handler.scope == { "asgi": {"version": "3.0", "spec_version": "2.0"}, "aws.context": {}, diff --git a/tests/handlers/test_api_gateway.py b/tests/handlers/test_api_gateway.py index e2458c2..23d2a4a 100644 --- a/tests/handlers/test_api_gateway.py +++ b/tests/handlers/test_api_gateway.py @@ -105,7 +105,7 @@ def test_aws_api_gateway_scope_basic(): example_context = {} handler = APIGateway(example_event, example_context, {"api_gateway_base_path": "/"}) - assert type(handler.body) == bytes + assert type(handler.body) is bytes assert handler.scope == { "asgi": {"version": "3.0", "spec_version": "2.0"}, "aws.context": {}, diff --git a/tests/handlers/test_custom.py b/tests/handlers/test_custom.py index c330bb6..ab4360d 100644 --- a/tests/handlers/test_custom.py +++ b/tests/handlers/test_custom.py @@ -52,7 +52,7 @@ def __call__(self, *, status: int, headers: Headers, body: bytes) -> dict: def test_custom_handler(): event = {"my-custom-key": 1} handler = CustomHandler(event, {}, {"api_gateway_base_path": "/"}) - assert type(handler.body) == bytes + assert type(handler.body) is bytes assert handler.scope == { "asgi": {"version": "3.0", "spec_version": "2.0"}, "aws.context": {}, diff --git a/tests/handlers/test_http_gateway.py b/tests/handlers/test_http_gateway.py index 6549042..44e51db 100644 --- a/tests/handlers/test_http_gateway.py +++ b/tests/handlers/test_http_gateway.py @@ -199,7 +199,7 @@ def test_aws_http_gateway_scope_basic_v1(): example_event, example_context, {"api_gateway_base_path": "/"} ) - assert type(handler.body) == bytes + assert type(handler.body) is bytes assert handler.scope == { "asgi": {"version": "3.0", "spec_version": "2.0"}, "aws.context": {}, @@ -308,7 +308,7 @@ def test_aws_http_gateway_scope_basic_v2(): example_event, example_context, {"api_gateway_base_path": "/"} ) - assert type(handler.body) == bytes + assert type(handler.body) is bytes assert handler.scope == { "asgi": {"version": "3.0", "spec_version": "2.0"}, "aws.context": {}, diff --git a/tests/handlers/test_lambda_at_edge.py b/tests/handlers/test_lambda_at_edge.py index 563e144..df4b861 100644 --- a/tests/handlers/test_lambda_at_edge.py +++ b/tests/handlers/test_lambda_at_edge.py @@ -138,7 +138,7 @@ def test_aws_cf_lambda_at_edge_scope_basic(): example_event, example_context, {"api_gateway_base_path": "/"} ) - assert type(handler.body) == bytes + assert type(handler.body) is bytes assert handler.scope == { "asgi": {"version": "3.0", "spec_version": "2.0"}, "aws.context": {},