From 8a7b05f48ee7f8e4667d8ae516a040819b067add Mon Sep 17 00:00:00 2001 From: Alexander Wainwright Date: Tue, 24 Jun 2025 14:33:01 +1000 Subject: [PATCH] Update tests for mount --- test/test_mount.py | 72 +++++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/test/test_mount.py b/test/test_mount.py index 4f61795..3c44685 100644 --- a/test/test_mount.py +++ b/test/test_mount.py @@ -164,37 +164,45 @@ def test_mount_usage_message(capsys): assert 'Usage:' in err -@mock.patch("locutus.mount.LocutusConfig") -@mock.patch("os.path.isdir", return_value=True) -@mock.patch("subprocess.run") -def test_mount_calledprocesserror_on_mount(mock_run, mock_isdir, mock_config, tmp_path, capsys): - mock_config.return_value.get_repo.return_value = "/repo" - mock_config.return_value.env = {} - archives = ["a", "b", "c"] - mock_run.side_effect = [ - mock.Mock(stdout="\n".join(archives) + "\n", returncode=0), # listing works - subprocess.CalledProcessError(1, ["borg", "mount"]) # mount fails - ] - args = make_args("dummy.toml", "dummy.rc", str(tmp_path), archive="0") - rc = run_mount(args) - assert rc == 1 - err = capsys.readouterr().err - assert "borg mount failed:" in err +@mock.patch('locutus.mount.LocutusConfig') +@mock.patch('os.path.isdir', return_value=True) +@mock.patch('subprocess.run') +def test_mount_calledprocesserror_on_mount( + mock_run, mock_isdir, mock_config, tmp_path, capsys +): + mock_config.return_value.get_repo.return_value = '/repo' + mock_config.return_value.env = {} + archives = ['a', 'b', 'c'] + mock_run.side_effect = [ + mock.Mock( + stdout='\n'.join(archives) + '\n', returncode=0 + ), # listing works + subprocess.CalledProcessError(1, ['borg', 'mount']), # mount fails + ] + args = make_args('dummy.toml', 'dummy.rc', str(tmp_path), archive='0') + rc = run_mount(args) + assert rc == 1 + err = capsys.readouterr().err + assert 'borg mount failed:' in err -@mock.patch("locutus.mount.LocutusConfig") -@mock.patch("os.path.isdir", return_value=True) -@mock.patch("subprocess.run") -def test_mount_exception_on_mount(mock_run, mock_isdir, mock_config, tmp_path, capsys): - mock_config.return_value.get_repo.return_value = "/repo" - mock_config.return_value.env = {} - archives = ["a", "b", "c"] - mock_run.side_effect = [ - mock.Mock(stdout="\n".join(archives) + "\n", returncode=0), # listing works - Exception() # mount fails - ] - args = make_args("dummy.toml", "dummy.rc", str(tmp_path), archive="0") - rc = run_mount(args) - assert rc == 1 - err = capsys.readouterr().err - assert "borg mount failed (unexpected)" in err +@mock.patch('locutus.mount.LocutusConfig') +@mock.patch('os.path.isdir', return_value=True) +@mock.patch('subprocess.run') +def test_mount_exception_on_mount( + mock_run, mock_isdir, mock_config, tmp_path, capsys +): + mock_config.return_value.get_repo.return_value = '/repo' + mock_config.return_value.env = {} + archives = ['a', 'b', 'c'] + mock_run.side_effect = [ + mock.Mock( + stdout='\n'.join(archives) + '\n', returncode=0 + ), # listing works + Exception(), # mount fails + ] + args = make_args('dummy.toml', 'dummy.rc', str(tmp_path), archive='0') + rc = run_mount(args) + assert rc == 1 + err = capsys.readouterr().err + assert 'borg mount failed (unexpected)' in err