コード例 #1
0
ファイル: test_cmdline.py プロジェクト: Demonware/bladerunner
def test_output_file_failure():
    """If we can't write the output file, it should raise SystemExit."""

    with pytest.raises(SystemExit) as error:
        setup_output_file({"output_file": "/this/file/path/probably/doesnt/exist/i/hope"})

    assert "Could not open output file: " in error.exconly()
コード例 #2
0
ファイル: test_cmdline.py プロジェクト: agronholm/bladerunner
def test_touching_output_file():
    """Check that the output file is writable before starting."""

    output_file = tempfile.mktemp()

    assert not os.path.exists(output_file)
    setup_output_file({"output_file": output_file})
    assert os.path.exists(output_file)
コード例 #3
0
ファイル: test_cmdline.py プロジェクト: a-tal/bladerunner
def test_touching_output_file():
    """Check that the output file is writable before starting."""

    output_file = tempfile.mktemp()

    assert not os.path.exists(output_file)
    setup_output_file({"output_file": output_file})
    assert os.path.exists(output_file)
コード例 #4
0
ファイル: test_cmdline.py プロジェクト: agronholm/bladerunner
def test_output_file_failure():
    """If we can't write the output file, it should raise SystemExit."""

    with pytest.raises(SystemExit) as error:
        setup_output_file({
            "output_file":
            "/this/file/path/probably/doesnt/exist/i/hope",
        })

    assert "Could not open output file: " in error.exconly()
コード例 #5
0
ファイル: test_cmdline.py プロジェクト: Demonware/bladerunner
def test_output_file_encoding_failure():
    """All of the encodings should be tried, then finally raise SystemExit."""

    if sys.version_info > (3,):
        err = UnicodeEncodeError("utf-8", "yes", 1, 1, "ok")
    else:
        err = UnicodeEncodeError(str("utf-8"), unicode("yes"), 1, 1, str("ok"))

    open_patch = patch.object(cmdline.io, "open", side_effect=err)

    with open_patch as p_open:
        with pytest.raises(SystemExit) as error:
            cmdline.setup_output_file({"output_file": "is fake"})

    for call_, enc in zip(p_open.call_args_list, cmdline.DEFAULT_ENCODINGS):
        assert call_ == call("is fake", "a", encoding=enc)

    assert "Could not create output file: is fake" in error.exconly()
コード例 #6
0
ファイル: test_cmdline.py プロジェクト: agronholm/bladerunner
def test_output_file_encoding_failure():
    """All of the encodings should be tried, then finally raise SystemExit."""

    if sys.version_info > (3, ):
        err = UnicodeEncodeError("utf-8", "yes", 1, 1, "ok")
    else:
        err = UnicodeEncodeError(
            str("utf-8"),
            unicode("yes"),  # nopep8
            1,
            1,
            str("ok"),
        )

    open_patch = patch.object(cmdline.io, "open", side_effect=err)

    with open_patch as p_open:
        with pytest.raises(SystemExit) as error:
            cmdline.setup_output_file({"output_file": "is fake"})

    for call_, enc in zip(p_open.call_args_list, cmdline.DEFAULT_ENCODINGS):
        assert call_ == call("is fake", "a", encoding=enc)

    assert "Could not create output file: is fake" in error.exconly()