示例#1
0
def test_snippets_errors(actions, snippets):

    _actions = []

    @actions.add(name='my_test', alias='t')
    def test(arg):
        # Enforce single-character argument.
        assert len(str(arg)) == 1
        _actions.append(arg)

    with captured_logging() as buf:
        snippets.run(':t1')
    assert 'couldn\'t' in buf.getvalue().lower()

    with captured_logging() as buf:
        snippets.run(':t')
    assert 'error' in buf.getvalue().lower()

    with captured_logging() as buf:
        snippets.run(':t 1 2')
    assert 'error' in buf.getvalue().lower()

    with captured_logging() as buf:
        snippets.run(':t aa')
    assert 'assert 2 == 1' in buf.getvalue()

    snippets.run(':t a')
    assert _actions == ['a']
示例#2
0
文件: test_actions.py 项目: ablot/phy
def test_snippets_errors(actions, snippets):

    _actions = []

    @actions.add(name='my_test', alias='t')
    def test(arg):
        # Enforce single-character argument.
        assert len(str(arg)) == 1
        _actions.append(arg)

    with captured_logging() as buf:
        snippets.run(':t1')
    assert 'couldn\'t' in buf.getvalue().lower()

    with captured_logging() as buf:
        snippets.run(':t')
    assert 'error' in buf.getvalue().lower()

    with captured_logging() as buf:
        snippets.run(':t 1 2')
    assert 'error' in buf.getvalue().lower()

    with captured_logging() as buf:
        snippets.run(':t aa')
    assert 'assert 2 == 1' in buf.getvalue()

    snippets.run(':t a')
    assert _actions == ['a']
示例#3
0
def test_download_already_exists_invalid(tempdir, mock_url):
    with captured_logging() as buf:
        path = op.join(tempdir, 'test')
        # Create empty file.
        open(path, 'a').close()
        _check(_dl(path))
    assert 'redownload' in buf.getvalue()
示例#4
0
def test_download_already_exists_invalid(tempdir, mock_url):
    with captured_logging() as buf:
        path = op.join(tempdir, 'test')
        # Create empty file.
        open(path, 'a').close()
        _check(_dl(path))
    assert 'redownload' in buf.getvalue()
示例#5
0
def test_download_already_exists_valid(tempdir, mock_url):
    with captured_logging() as buf:
        path = op.join(tempdir, 'test')
        # Create valid file.
        with open(path, 'ab') as f:
            f.write(_DATA.tostring())
        _check(_dl(path))
    assert 'skip' in buf.getvalue()
示例#6
0
def test_download_already_exists_valid(tempdir, mock_url):
    with captured_logging() as buf:
        path = op.join(tempdir, 'test')
        # Create valid file.
        with open(path, 'ab') as f:
            f.write(_DATA.tostring())
        _check(_dl(path))
    assert 'skip' in buf.getvalue()