def test_bw_error(mocker):
    run = mocker.patch("subprocess.run")
    run.side_effect = bwkr.subprocess.CalledProcessError(output=b"Error",
                                                         cmd=None,
                                                         returncode=1)

    with pytest.raises(ValueError):
        bwkr.bw("yay", "ho")
def test_bw(mocker):
    run = mocker.patch("bitwarden_keyring.bw_run")
    run.return_value.stdout = "yay"

    assert bwkr.bw("a", "b", "c") == "yay"

    run.assert_called_with("bw", "a", "b", "c")
def test_bw(mocker, session, args):
    run = mocker.patch("subprocess.run")

    run.return_value.stdout = " haha "

    assert bwkr.bw("yay", "ho", session=session) == "haha"

    run.assert_called_with(args, check=True, stdout=bwkr.subprocess.PIPE)
def test_bw_wrong_password(mocker):
    run = mocker.patch("subprocess.run")
    run.side_effect = [
        bwkr.subprocess.CalledProcessError(
            output=b"Username or password is incorrect.",
            cmd=None,
            returncode=1),
        mocker.Mock(stdout="{}"),
    ]

    assert bwkr.bw("yay", "ho") == "{}"
    assert run.call_count == 2