Update tests for mount
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user