Fix test failures: correct path literal and formatting issues

This commit is contained in:
Vedant Madane 2026-01-26 14:05:46 +05:30
parent acb57a7162
commit c836955162
2 changed files with 15 additions and 8 deletions

View file

@ -330,6 +330,7 @@ ignore = [
"test/plugins/test_ftintitle.py" = ["E501"]
"test/test_util.py" = ["E501"]
"test/ui/test_field_diff.py" = ["E501"]
"test/ui/test_ui_init.py" = ["PT"]
"test/util/test_id_extractors.py" = ["E501"]
"test/**" = ["RUF001"] # we use Unicode characters in tests

View file

@ -129,15 +129,19 @@ class DatabaseErrorTest(BeetsTestCase):
def test_database_error_with_unable_to_open(self):
"""Test error message when database fails with 'unable to open' error."""
test_config = deepcopy(config)
test_config["library"] = os.path.join(self.temp_dir, b"test.db")
test_config["library"] = os.path.join(self.temp_dir, "test.db")
# Mock Library to raise OperationalError with "unable to open"
with mock.patch.object(
library, 'Library', side_effect=sqlite3.OperationalError("unable to open database file")
library,
"Library",
side_effect=sqlite3.OperationalError(
"unable to open database file"
),
):
with self.assertRaises(ui.UserError) as cm:
ui._open_library(test_config)
error_message = str(cm.exception)
# Should mention directory permissions
self.assertIn("directory", error_message.lower())
@ -146,15 +150,17 @@ class DatabaseErrorTest(BeetsTestCase):
def test_database_error_fallback(self):
"""Test fallback error message for other database errors."""
test_config = deepcopy(config)
test_config["library"] = os.path.join(self.temp_dir, b"test.db")
test_config["library"] = os.path.join(self.temp_dir, "test.db")
# Mock Library to raise a different OperationalError
with mock.patch.object(
library, 'Library', side_effect=sqlite3.OperationalError("disk I/O error")
library,
"Library",
side_effect=sqlite3.OperationalError("disk I/O error"),
):
with self.assertRaises(ui.UserError) as cm:
ui._open_library(test_config)
error_message = str(cm.exception)
# Should contain the error but not the directory writable message
self.assertIn("could not be opened", error_message)