Skip to content

Commit

Permalink
Lint tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amh4r committed Oct 22, 2023
1 parent 66ce93a commit de63c86
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 25 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ itest: check-venv
precommit: format-check lint type-check utest

lint: check-venv
@pylint inngest
@pylint inngest tests

type-check: check-venv
@mypy inngest
@mypy inngest tests

utest: check-venv
@pytest inngest
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ disable = [
'missing-docstring',
'too-few-public-methods',
'too-many-arguments',
'unused-argument',
]
6 changes: 3 additions & 3 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .net import HOST


class FrameworkTestCase(Protocol):
class _FrameworkTestCase(Protocol):
dev_server_port: int
http_proxy: HTTPProxy

Expand All @@ -30,11 +30,11 @@ def register(app_port: int) -> None:
assert res.status_code == 200


def set_up(case: FrameworkTestCase) -> None:
def set_up(case: _FrameworkTestCase) -> None:
case.http_proxy = HTTPProxy(case.on_proxy_request).start()


def tear_down(case: FrameworkTestCase) -> None:
def tear_down(case: _FrameworkTestCase) -> None:
case.http_proxy.stop()


Expand Down
12 changes: 6 additions & 6 deletions tests/dev_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

_enabled = os.getenv("DEV_SERVER_ENABLED") != "0"

dev_server_port: int
DEV_SERVER_PORT: int
dev_server_port_env_var = os.getenv("DEV_SERVER_PORT")
if dev_server_port_env_var:
dev_server_port = int(dev_server_port_env_var)
DEV_SERVER_PORT = int(dev_server_port_env_var)
elif _enabled:
dev_server_port = get_available_port()
DEV_SERVER_PORT = get_available_port()
else:
dev_server_port = _DEFAULT_DEV_SERVER_PORT
DEV_SERVER_PORT = _DEFAULT_DEV_SERVER_PORT


class _DevServer:
Expand All @@ -31,15 +31,15 @@ def start(self) -> None:
return

def _run() -> None:
self._process = subprocess.Popen(
self._process = subprocess.Popen( # pylint: disable=consider-using-with
[
"npx",
"inngest-cli@latest",
"dev",
"--no-discovery",
"--no-poll",
"--port",
f"{dev_server_port}",
f"{DEV_SERVER_PORT}",
],
)
self._process.communicate()
Expand Down
8 changes: 4 additions & 4 deletions tests/http_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _set_response(self, res: Response) -> None:
if res.body is not None:
self.wfile.write(res.body)

def do_DELETE(self) -> None:
def do_DELETE(self) -> None: # pylint: disable=invalid-name
res = on_request(
body=self.rfile.read(int(self.headers["Content-Length"])),
headers=self._get_headers(),
Expand All @@ -56,7 +56,7 @@ def do_GET(self) -> None:
)
self._set_response(res)

def do_PATCH(self) -> None:
def do_PATCH(self) -> None: # pylint: disable=invalid-name
res = on_request(
body=self.rfile.read(int(self.headers["Content-Length"])),
headers=self._get_headers(),
Expand All @@ -65,7 +65,7 @@ def do_PATCH(self) -> None:
)
self._set_response(res)

def do_POST(self) -> None:
def do_POST(self) -> None: # pylint: disable=invalid-name
res = on_request(
body=self.rfile.read(int(self.headers["Content-Length"])),
headers=self._get_headers(),
Expand All @@ -74,7 +74,7 @@ def do_POST(self) -> None:
)
self._set_response(res)

def do_PUT(self) -> None:
def do_PUT(self) -> None: # pylint: disable=invalid-name
res = on_request(
body=self.rfile.read(int(self.headers["Content-Length"])),
headers=self._get_headers(),
Expand Down
10 changes: 5 additions & 5 deletions tests/test_flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@

import inngest

from .base import FrameworkTestCase, register, set_up, tear_down
from .base import register, set_up, tear_down
from .cases import create_cases
from .dev_server import dev_server_port
from .dev_server import DEV_SERVER_PORT
from .http_proxy import HTTPProxy, Response
from .net import HOST

_client = inngest.Inngest(
base_url=f"http://{HOST}:{dev_server_port}",
base_url=f"http://{HOST}:{DEV_SERVER_PORT}",
id="flask",
)

_cases = create_cases(_client, "flask")


class TestFlask(unittest.TestCase, FrameworkTestCase):
class TestFlask(unittest.TestCase):
app: FlaskClient
dev_server_port: int
http_proxy: HTTPProxy
Expand Down Expand Up @@ -63,7 +63,7 @@ def on_proxy_request(

return Response(
body=res.data,
headers={k: v for k, v in res.headers},
headers=dict(res.headers),
status_code=res.status_code,
)

Expand Down
10 changes: 5 additions & 5 deletions tests/test_tornado.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@

import inngest

from .base import FrameworkTestCase, register, set_up, tear_down
from .base import register, set_up, tear_down
from .cases import create_cases
from .dev_server import dev_server_port
from .dev_server import DEV_SERVER_PORT
from .http_proxy import HTTPProxy, Response
from .net import HOST

_client = inngest.Inngest(
base_url=f"http://{HOST}:{dev_server_port}",
base_url=f"http://{HOST}:{DEV_SERVER_PORT}",
id="tornado",
)

_cases = create_cases(_client, "tornado")


class TestTornado(tornado.testing.AsyncHTTPTestCase, FrameworkTestCase):
class TestTornado(tornado.testing.AsyncHTTPTestCase):
app: Application
dev_server_port: int
http_proxy: HTTPProxy
Expand Down Expand Up @@ -63,7 +63,7 @@ def on_proxy_request(

return Response(
body=res.body,
headers={k: v for k, v in res.headers.items()},
headers=dict(res.headers.items()),
status_code=res.code,
)

Expand Down

0 comments on commit de63c86

Please sign in to comment.