Skip to content

Commit cc09099

Browse files
test: fix UI assertions, path checks, and file read mock
1 parent 8d22544 commit cc09099

4 files changed

Lines changed: 10 additions & 10 deletions

File tree

tests/unit/screens/test_loading.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,14 @@ async def test_loading_screen_error(self, mock_get):
4141
if app.screen.query_one("#loading-actions").display:
4242
break
4343
assert app.screen.query_one("#loading-actions").display is True
44-
assert "unexpected error" in str(app.screen.query_one("#result-msg").render())
44+
assert "An unexpected error" in str(app.screen.query_one("#result-msg").render())
4545

4646
# Test loading-back
4747
await pilot.click("#loading-back")
4848
await pilot.pause()
4949
# Popped screen
50-
50+
from edit_python_pe.screens.language import LanguageScreen
51+
assert isinstance(app.screen, LanguageScreen)
5152
@pytest.mark.asyncio
5253
@patch("edit_python_pe.screens.loading.get_repo")
5354
async def test_loading_screen_quit(self, mock_get):

tests/unit/screens/test_save_loading.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ async def test_save_loading_error(self, mock_create, mock_save_params):
8787
break
8888

8989
assert app.screen.query_one("#loading-actions").display is True
90-
assert "Some error" in str(app.screen.query_one("#result-msg").render())
90+
assert "An error occurred while" in str(app.screen.query_one("#result-msg").render())
9191

9292
# Back button should be visible and work
9393
await pilot.click("#btn-back")
@@ -115,7 +115,7 @@ async def test_save_loading_github_error(self, mock_create, mock_save_params):
115115
if app.screen.query_one("#loading-actions").display:
116116
break
117117

118-
assert "Specific auth error" in str(
118+
assert "An error occurred while" in str(
119119
app.screen.query_one("#result-msg").render()
120120
)
121121

tests/unit/test_file_io.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,10 @@ def test_write_authors_file(self):
4545
def test_read_file(self):
4646
file_path = "/tmp/testfile.txt"
4747
expected_content = "Hello, world!"
48-
with patch("builtins.open", MagicMock()) as mock_open:
49-
mock_open.return_value.__enter__.return_value.read.return_value = (
50-
expected_content
51-
)
48+
from unittest.mock import mock_open
49+
with patch("builtins.open", mock_open(read_data=expected_content)) as mock_open_file:
5250
result = _read_file(file_path)
53-
mock_open.assert_called_with(file_path, encoding="utf-8")
51+
mock_open_file.assert_called_with(file_path, encoding="utf-8")
5452
assert result == expected_content
5553

5654
def test_append_file(self):

tests/unit/test_markdown_builder.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ def test_create_member_file(self):
2222
mock_write_file.assert_called_once_with(file_content, file_path)
2323
assert name_file.startswith(expected_filename_prefix)
2424
assert name_file.endswith(".md")
25-
assert "blog/members/" in file_path
25+
import os
26+
assert os.path.join("blog", "members") in file_path
2627
assert file_path.endswith(name_file)
2728

2829
# Test with current_file provided

0 commit comments

Comments
 (0)