Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
test(pytest): remove unnecessary await & async
Browse files Browse the repository at this point in the history
  • Loading branch information
frgfm committed Apr 19, 2024
1 parent 0ff81fc commit cef94b2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 25 deletions.
23 changes: 10 additions & 13 deletions src/tests/test_security.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,22 @@
from app.core.security import create_access_token, hash_password, verify_password


@pytest.mark.asyncio()
async def test_hash_password():
def test_hash_password():
pwd1 = "my_password"
hash_pwd1 = await hash_password(pwd1)
hash_pwd1 = hash_password(pwd1)

assert hash_pwd1 != pwd1
assert hash_pwd1 != await hash_password(pwd1 + "bis")
assert hash_pwd1 != hash_password(pwd1 + "bis")
# Check that it's non deterministic
assert hash_pwd1 != await hash_password(pwd1)
assert hash_pwd1 != hash_password(pwd1)


@pytest.mark.asyncio()
async def test_verify_password():
def test_verify_password():
pwd1 = "my_password"
hash_pwd1 = await hash_password(pwd1)
hash_pwd1 = hash_password(pwd1)

assert await verify_password(pwd1, hash_pwd1)
assert not await verify_password("another_try", hash_pwd1)
assert verify_password(pwd1, hash_pwd1)
assert not verify_password("another_try", hash_pwd1)


@pytest.mark.parametrize(
Expand All @@ -34,9 +32,8 @@ async def test_verify_password():
({"data": "my_data"}, None, settings.ACCESS_TOKEN_EXPIRE_MINUTES),
],
)
@pytest.mark.asyncio()
async def test_create_access_token(content, expires_minutes, expected_delta):
payload = await create_access_token(content, expires_minutes)
def test_create_access_token(content, expires_minutes, expected_delta):
payload = create_access_token(content, expires_minutes)
after = datetime.utcnow()
assert isinstance(payload, str)
decoded_data = jwt.decode(payload, settings.SECRET_KEY, algorithms=[settings.JWT_ENCODING_ALGORITHM])
Expand Down
12 changes: 0 additions & 12 deletions src/tests/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
(249513553, 200, None, "frgfm/torch-cam"),
],
)
@pytest.mark.asyncio()
def test_githubclient_get_repo(repo_id, status_code, status_detail, expected_name):
github_client = GitHubClient()
if isinstance(expected_name, str):
Expand All @@ -32,7 +31,6 @@ def test_githubclient_get_repo(repo_id, status_code, status_detail, expected_nam
(26927750, 200, None, "frgfm"),
],
)
@pytest.mark.asyncio()
def test_githubclient_get_user(user_id, status_code, status_detail, expected_name):
github_client = GitHubClient()
if isinstance(expected_name, str):
Expand All @@ -52,7 +50,6 @@ def test_githubclient_get_user(user_id, status_code, status_detail, expected_nam
("frgfm/torch-cam", 200, None, "README.md"),
],
)
@pytest.mark.asyncio()
def test_githubclient_get_readme(repo_name, status_code, status_detail, expected_path):
github_client = GitHubClient()
if isinstance(expected_path, str):
Expand All @@ -73,7 +70,6 @@ def test_githubclient_get_readme(repo_name, status_code, status_detail, expected
("frgfm/torch-cam", "CONTRIBUTING.md", 200, None),
],
)
@pytest.mark.asyncio()
def test_githubclient_get_file(repo_name, file_path, status_code, status_detail):
github_client = GitHubClient()
if status_code // 100 == 2:
Expand All @@ -94,7 +90,6 @@ def test_githubclient_get_file(repo_name, file_path, status_code, status_detail)
("frgfm/torch-cam", 200, None),
],
)
@pytest.mark.asyncio()
def test_githubclient_list_pulls(repo_name, status_code, status_detail):
github_client = GitHubClient()
if status_code // 100 == 2:
Expand All @@ -113,7 +108,6 @@ def test_githubclient_list_pulls(repo_name, status_code, status_detail):
("frgfm/torch-cam", 181, 200, None),
],
)
@pytest.mark.asyncio()
def test_githubclient_list_comments_from_issue(repo_name, issue_number, status_code, status_detail):
github_client = GitHubClient()
if status_code // 100 == 2:
Expand All @@ -132,7 +126,6 @@ def test_githubclient_list_comments_from_issue(repo_name, issue_number, status_c
("frgfm/Holocron", 279, 200, None),
],
)
@pytest.mark.asyncio()
def test_githubclient_list_reviews_from_pull(repo_name, pull_number, status_code, status_detail):
github_client = GitHubClient()
if status_code // 100 == 2:
Expand All @@ -151,7 +144,6 @@ def test_githubclient_list_reviews_from_pull(repo_name, pull_number, status_code
("frgfm/Holocron", 279, 200, None),
],
)
@pytest.mark.asyncio()
def test_githubclient_list_review_comments_from_pull(repo_name, pull_number, status_code, status_detail):
github_client = GitHubClient()
if status_code // 100 == 2:
Expand All @@ -170,7 +162,6 @@ def test_githubclient_list_review_comments_from_pull(repo_name, pull_number, sta
("frgfm/Holocron", 200, None),
],
)
@pytest.mark.asyncio()
def test_githubclient_fetch_reviews_from_repo(repo_name, status_code, status_detail):
github_client = GitHubClient()
if status_code // 100 == 2:
Expand All @@ -189,7 +180,6 @@ def test_githubclient_fetch_reviews_from_repo(repo_name, status_code, status_det
("frgfm/Holocron", 200, None),
],
)
@pytest.mark.asyncio()
def test_githubclient_fetch_pull_comments_from_repo(repo_name, status_code, status_detail):
github_client = GitHubClient()
if status_code // 100 == 2:
Expand Down Expand Up @@ -220,7 +210,6 @@ def test_githubclient_fetch_pull_comments_from_repo(repo_name, status_code, stat
),
],
)
@pytest.mark.asyncio()
def test_githubclient_arrange_in_threads(comments, expected_output):
assert GitHubClient.arrange_in_threads(comments) == expected_output

Expand All @@ -231,7 +220,6 @@ def test_githubclient_arrange_in_threads(comments, expected_output):
(lambda x: x**2, [1, 2, 3], [1, 4, 9]),
],
)
@pytest.mark.asyncio()
def test_execute_in_parallel(func, arr, output):
assert list(execute_in_parallel(func, arr, num_threads=1)) == output
assert list(execute_in_parallel(func, arr, num_threads=2)) == output

0 comments on commit cef94b2

Please sign in to comment.