示例#1
0
文件: test_tbx.py 项目: tbarron/tbx
def test_dispatch_help_nopfx():
    """
    Dispatch help with no prefix
    """
    pytest.dbgfunc()
    exp = '*prefix* is required'
    with pytest.raises(SystemExit) as err:
        tbx.dispatch(__name__, args=['help', 'nosuch'])
    assert exp in str(err)
示例#2
0
文件: test_tbx.py 项目: tbarron/tbx
def test_dispatch_help_nosuch():
    """
    Dispatch help on a function that does not exist
    """
    pytest.dbgfunc()
    exp = 'Module test.test_tbx has no attribute foo_nosuch'
    with pytest.raises(SystemExit) as err:
        tbx.dispatch(__name__, 'foo', ['help', 'nosuch'])
    assert exp in str(err)
示例#3
0
文件: test_tbx.py 项目: tbarron/tbx
def test_dispatch_help_nomodule():
    """
    Dispatch help on a non-existent module
    """
    pytest.dbgfunc()
    exp = 'Module xtest.test_tbx is not in sys.modules'
    with pytest.raises(SystemExit) as err:
        tbx.dispatch('x' + __name__, 'foo', ['help', 'nosuch'])
    assert exp in str(err)
示例#4
0
文件: test_tbx.py 项目: tbarron/tbx
def test_dispatch_good(capsys):
    """
    Calling dispatch with a good function name
    """
    pytest.dbgfunc()
    argl = ['foobar', 7, 8, 9, 17]
    tbx.dispatch(__name__, 'dtst', argl)
    out, _ = capsys.readouterr()
    exp = "This is foobar: {0}".format(', '.join([str(_) for _ in argl[1:]]))
    assert exp in out
示例#5
0
文件: test_tbx.py 项目: tbarron/tbx
def test_dispatch_bad(capsys):
    """
    Calling dispatch with a non-existent function name
    """
    with pytest.raises(SystemExit) as err:
        tbx.dispatch(mname=__name__,
                     prefix='dtst',
                     args=['bumble', 1, 2, 3])
    assert 'Module test.test_tbx has no function dtst_bumble' in str(err)
    out, err = capsys.readouterr()
    assert out == ''