Пример #1
0
def test_without_error_handling():
    o = options.Options(optspec)
    with utils.raises(options.UsageRequested):
        o.parse(['-h'])

    with utils.raises(options.UsageError):
        o.parse(['--foo'])
Пример #2
0
def test_show_usage():
    o = options.Options(optspec)

    with utils.stderr_patcher as mock_stderr:
        o.show_usage()
        assert o.usage in mock_stderr._data

    with utils.stderr_patcher as mock_stderr:
        o.show_usage("This is a message")
        assert o.usage in mock_stderr._data
        assert "This is a message" in mock_stderr._data

    o = options.Options(
        optspec,
        onabort=utils.mock_onabort)

    with utils.stderr_patcher as mock_stderr:
        with utils.raises(utils.MockError):
            o.show_usage()
            assert o.usage in mock_stderr._data

    with utils.stderr_patcher as mock_stderr:
        with utils.raises(utils.MockError):
            o.show_usage("This is a message")
            assert o.usage in mock_stderr._data
            assert "This is a message" in mock_stderr._data
Пример #3
0
def test_with_error_handling():
    o = options.Options(optspec, onabort=utils.mock_onabort)

    with utils.stderr_patcher as mock_stderr:
        with utils.raises(utils.MockError):
            with options.ErrorHandler(o):
                o.parse(['-h'])
                assert o.usage in mock_stderr._data

    with utils.stderr_patcher as mock_stderr:
        with utils.raises(utils.MockError):
            with options.ErrorHandler(o):
                o.parse(['--foo'])
                assert o.usage in mock_stderr._data
Пример #4
0
def test_parse():
    o = options.Options(optspec, onabort=None)
    with utils.raises(options.UsageRequested):
        assert o.parse(['-h']) == None

    (opt, flags, extra) = o.parse(["-t"])

    assert flags == [('-t', '')]
    assert not extra