def test_guestfs_conn_ro_expand_wrong_var(self, mock_gfs, monkeypatch): monkeypatch.delenv('SOME_PATH', raising=False) with guestfs_tools.guestfs_conn_ro(disk='$SOME_PATH/file') as conn: assert conn.add_drive_ro.call_args == call('$SOME_PATH/file')
def test_guestfs_conn_ro_env_backend(self, monkeypatch, mock_gfs): monkeypatch.setenv('LIBGUESTFS_BACKEND', 'libvirt') with guestfs_tools.guestfs_conn_ro(disk='dummy') as conn: assert conn.set_backend.call_args == call('libvirt')
def test_guestfs_conn_ro_expand_vars(self, mock_gfs, monkeypatch): expanded_path = '/some/path' monkeypatch.setenv('SOME_PATH', expanded_path) with guestfs_tools.guestfs_conn_ro(disk='$SOME_PATH/file') as conn: assert conn.add_drive_ro.call_args == call('/some/path/file')
def test_guestfs_conn_ro_error(self, mock_gfs): mock_gfs.return_value.launch.side_effect = RuntimeError('mocking') with pytest.raises(guestfs_tools.GuestFSError): with guestfs_tools.guestfs_conn_ro(disk='dummy'): pass
def test_guestfs_conn_ro_fallback_backend(self, mock_gfs): with guestfs_tools.guestfs_conn_ro(disk='dummy') as conn: assert conn.set_backend.call_args == call('direct')
def test_guestfs_conn_ro_teardown(self, mock_gfs): with guestfs_tools.guestfs_conn_ro(disk='dummy') as conn: pass assert call.add_drive_ro('dummy') in conn.mock_calls assert conn.mock_calls[-1] == call.close() assert conn.mock_calls[-2] == call.shutdown()