fix: say a config detection fails to read

This commit is contained in:
Abdessamad Derraz committed 2026-11-05 19:15:35 +01:00
1 parent 59c8217280
commit 83f5d161ab
6 files changed
+66 -16

No files matched your search

+37
View File
@@ -737,6 +737,43 @@ class ASettingsFileThisUserCannotRead(unittest.TestCase):
self.assertIn(f"cannot open {path}", err.getvalue())
class AConfigThatFailsToRead(unittest.TestCase):
"""retroarch.cfg on a failing card raised EIO, and a link that loops
ELOOP: both counted as absent without a word, as only a permission
refusal was said. Absence itself stays silent."""
def setUp(self):
self.root = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp"))
self.addCleanup(shutil.rmtree, self.root, True)
install._DETECTION_REFUSED.clear()
self.addCleanup(install._DETECTION_REFUSED.clear)
install._SETUP_SEARCH.active = True
self.addCleanup(setattr, install._SETUP_SEARCH, "active", False)
def test_a_read_error_is_said_with_its_own_words(self):
cfg = self.root / "retroarch.cfg"
cfg.write_text('system_directory = "/x"\n', encoding="utf-8")
failure = OSError(errno.EIO, "Input/output error", str(cfg))
with mock.patch.object(Path, "read_text", side_effect=failure), \
contextlib.redirect_stderr(io.StringIO()) as err:
self.assertIsNone(install._retroarch_cfg_dir(cfg, "system_directory",
self.root, "system"))
self.assertEqual(install._DETECTION_REFUSED, [(cfg, "Input/output error")])
said = " ".join(err.getvalue().split())
self.assertIn(f"{cfg} could not be read (Input/output error)", said)
self.assertNotIn("Run as its owner", said)
@unittest.skipIf(os.name == "nt", "a symbolic link needs privileges on Windows")
def test_a_link_that_loops_is_said_and_absence_is_not(self):
loop = self.root / "retroarch.cfg"
loop.symlink_to(loop.name)
with contextlib.redirect_stderr(io.StringIO()):
self.assertFalse(install._exists(loop))
self.assertFalse(install._exists(self.root / "absent.cfg"))
self.assertFalse(install._exists(self.root / "absent" / "x.cfg"))
self.assertEqual([folder for folder, _why in install._DETECTION_REFUSED], [loop])
class TheFrontendsOwnFolderClosed(unittest.TestCase):
"""The Flatpak RetroArch's folder at 000: its retroarch.cfg names
~/Games/bios, and the run took ~/.config/retroarch/system, a folder it