Skip to content

Commit

Permalink
fix: test_file_manager assertions (#2207)
Browse files Browse the repository at this point in the history
* fix: test_file_manager assertions

* fix test

* maybe fix windows

* skip windows

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
akshayka and pre-commit-ci[bot] authored Sep 3, 2024
1 parent b612b8f commit 620f0fc
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions tests/_server/test_file_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import os
import sys
import tempfile
from typing import Generator

Expand Down Expand Up @@ -68,7 +69,7 @@ def test_rename_to_existing_filename(app_file_manager: AppFileManager) -> None:
try:
with pytest.raises(HTTPException) as e: # noqa: PT012
app_file_manager.rename(existing_filename)
assert e.value == HTTPStatus.BAD_REQUEST
assert e.value.status_code == HTTPStatus.BAD_REQUEST
finally:
os.remove(existing_filename)

Expand All @@ -91,7 +92,7 @@ def test_rename_exception(app_file_manager: AppFileManager) -> None:
new_filename = "/invalid/path/new_filename.py"
with pytest.raises(HTTPException) as e: # noqa: PT012
app_file_manager.rename(new_filename)
assert e.value.status_code == HTTPStatus.SERVER_ERROR
assert e.value.status_code == HTTPStatus.SERVER_ERROR


def test_rename_create_new_file(app_file_manager: AppFileManager) -> None:
Expand Down Expand Up @@ -153,11 +154,15 @@ def test_save_app_config_valid(app_file_manager: AppFileManager) -> None:
os.remove(app_file_manager.filename)


@pytest.mark.skipif(
condition=sys.platform == "win32",
reason="filename is not invalid on Windows",
)
def test_save_app_config_exception(app_file_manager: AppFileManager) -> None:
app_file_manager.filename = "/invalid/path/app_config.py"
with pytest.raises(HTTPException) as e: # noqa: PT012
app_file_manager.save_app_config({})
assert e.value.status_code == HTTPStatus.SERVER_ERROR
assert e.value.status_code == HTTPStatus.SERVER_ERROR


def test_save_filename_change_not_allowed(
Expand All @@ -167,7 +172,7 @@ def test_save_filename_change_not_allowed(
save_request.filename = "new.py"
with pytest.raises(HTTPException) as e: # noqa: PT012
app_file_manager.save(save_request)
assert e.value.status_code == HTTPStatus.BAD_REQUEST
assert e.value.status_code == HTTPStatus.BAD_REQUEST


def test_save_existing_filename(app_file_manager: AppFileManager) -> None:
Expand All @@ -178,7 +183,7 @@ def test_save_existing_filename(app_file_manager: AppFileManager) -> None:
try:
with pytest.raises(HTTPException) as e: # noqa: PT012
app_file_manager.save(save_request)
assert e.value.status_code == HTTPStatus.BAD_REQUEST
assert e.value.status_code == HTTPStatus.BAD_REQUEST
finally:
os.remove(existing_filename)

Expand Down

0 comments on commit 620f0fc

Please sign in to comment.