Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test_cli and test_cookies #2479

Merged
merged 9 commits into from Jun 19, 2022
7 changes: 4 additions & 3 deletions tests/test_cli.py
Expand Up @@ -2,6 +2,7 @@
import subprocess

from pathlib import Path
from typing import List

import pytest

Expand All @@ -18,21 +19,21 @@ def capture(command):
cwd=Path(__file__).parent,
)
try:
out, err = proc.communicate(timeout=1)
out, err = proc.communicate(timeout=10)
except subprocess.TimeoutExpired:
proc.kill()
out, err = proc.communicate()
return out, err, proc.returncode


def starting_line(lines):
def starting_line(lines: List[str]):
for idx, line in enumerate(lines):
if line.strip().startswith(b"Sanic v"):
return idx
return 0


def read_app_info(lines):
def read_app_info(lines: List[str]):
for line in lines:
if line.startswith(b"{") and line.endswith(b"}"):
return json.loads(line)
Expand Down
4 changes: 3 additions & 1 deletion tests/test_cookies.py
Expand Up @@ -3,6 +3,7 @@

import pytest

from sanic import Sanic
from sanic.cookies import Cookie
from sanic.response import text

Expand Down Expand Up @@ -224,7 +225,7 @@ def handler(request):
@pytest.mark.parametrize(
"expires", [datetime.utcnow() + timedelta(seconds=60)]
)
def test_cookie_expires(app, expires):
def test_cookie_expires(app: Sanic, expires: datetime):
expires = expires.replace(microsecond=0)
cookies = {"test": "wait"}

Expand All @@ -238,6 +239,7 @@ def handler(request):
request, response = app.test_client.get(
"/", cookies=cookies, raw_cookies=True
)

cookie_expires = datetime.utcfromtimestamp(
response.raw_cookies["test"].expires
).replace(microsecond=0)
Expand Down