Example #1
0
def test_invalid_json_output(monkeypatch, popen):
    expected = "[[}"
    popen.communicate.return_value = expected.encode(), b'stderr'

    app = Application("foo")
    output = app._execute("bar",
                          "a",
                          "b",
                          "c",
                          expect_json=False,
                          accept_empty=True)
    assert output == expected

    output = app._execute("bar",
                          "a",
                          "b",
                          "c",
                          expect_json=False,
                          accept_empty=False)
    assert output == expected

    with pytest.raises(ExecutionError):
        app._execute("bar",
                     "a",
                     "b",
                     "c",
                     expect_json=True,
                     accept_empty=False)

    with pytest.raises(ExecutionError):
        app._execute("bar", "a", "b", "c", expect_json=True, accept_empty=True)
Example #2
0
def test_json_output(monkeypatch, popen):
    expected = {"foo": "bar"}
    popen.communicate.return_value = json.dumps(expected).encode(), b'stderr'

    app = Application("foo")
    output = app._execute("bar", "a", "b", "c", expect_json=True, accept_empty=True)
    assert output == expected

    output = app._execute("bar", "a", "b", "c", expect_json=False, accept_empty=True)
    assert output == json.dumps(expected)

    output = app._execute("bar", "a", "b", "c", expect_json=True, accept_empty=False)
    assert output == expected

    output = app._execute("bar", "a", "b", "c", expect_json=False, accept_empty=False)
    assert output == json.dumps(expected)
Example #3
0
def test_invalid_json_output(monkeypatch, popen):
    expected = "[[}"
    popen.communicate.return_value = expected.encode(), b'stderr'

    app = Application("foo")
    output = app._execute("bar", "a", "b", "c", expect_json=False, accept_empty=True)
    assert output == expected

    output = app._execute("bar", "a", "b", "c", expect_json=False, accept_empty=False)
    assert output == expected

    with pytest.raises(ExecutionError):
        app._execute("bar", "a", "b", "c", expect_json=True, accept_empty=False)

    with pytest.raises(ExecutionError):
        app._execute("bar", "a", "b", "c", expect_json=True, accept_empty=True)
Example #4
0
def test_json_output(monkeypatch, popen):
    expected = {"foo": "bar"}
    popen.communicate.return_value = json.dumps(expected).encode(), b'stderr'

    app = Application("foo")
    output = app._execute("bar",
                          "a",
                          "b",
                          "c",
                          expect_json=True,
                          accept_empty=True)
    assert output == expected

    output = app._execute("bar",
                          "a",
                          "b",
                          "c",
                          expect_json=False,
                          accept_empty=True)
    assert output == json.dumps(expected)

    output = app._execute("bar",
                          "a",
                          "b",
                          "c",
                          expect_json=True,
                          accept_empty=False)
    assert output == expected

    output = app._execute("bar",
                          "a",
                          "b",
                          "c",
                          expect_json=False,
                          accept_empty=False)
    assert output == json.dumps(expected)