Example #1
0
def test_docblock__run_action(dummy_file):
    docblock = rb.DocBlock(
        'some content',
        ['r-create-file:{}'.format(dummy_file), 'test'],
    )
    docblock.run(prompt=False)
    assert docblock.last_run['retcode'] == 0
Example #2
0
def docblock_bash_light():
    code = 'echo "it is working"'
    # use bash as interpreter
    tags = ['bash', 'test', 'main']
    # color print optimized for light background terminal
    light = True
    return rb.DocBlock(code, tags, light)
Example #3
0
def test_docblock__get_dict(docblock_bash):
    assert type(docblock_bash.get_dict()) == type({})
    bash_block_dict = {
        'interpreter': 'bash',
        'code': 'echo "this is a test"',
        'tags': ['bash', 'test', 'main'],
        'runs': []
    }
    docblock = rb.DocBlock(
        bash_block_dict['code'],
        bash_block_dict['tags'],
    )
    actual_dict = docblock.get_dict()
    assert bash_block_dict == actual_dict
    docblock.run(prompt=False)
    while docblock.process:
        time.sleep(0.1)
    actual_dict = docblock.get_dict()
    for key in ('interpreter', 'code', 'tags'):
        assert bash_block_dict[key] == actual_dict[key]
    assert actual_dict['runs'][0]['user_code'] == docblock.code
    assert actual_dict['runs'][0]['output'] == 'this is a test\n'
    assert actual_dict['runs'][0]['retcode'] == 0
    assert actual_dict['runs'][0]['time_start'] > 0
    assert actual_dict['runs'][0]['time_stop'] > 0
Example #4
0
def test_docblock__run_and_kill():
    # Note that kill will only send SIGKILL to the running process without
    # any knowledge on how this will be handeled. What is guaranteed is that
    # process.poll() will contain some exitcode.
    docblock = rb.DocBlock(
        'echo "start"\nsleep 2\necho "this is test"',
        ['bash', 'test'],
    )
    assert docblock.process == None
    t = threading.Thread(target=docblock_worker, args=(docblock, ))
    t.start()
    time.sleep(1)
    assert docblock.process and docblock.process.poll() is None
    docblock.kill()
    time.sleep(0.1)
    assert docblock.process and type(docblock.process.poll()) is int
Example #5
0
def docblock_unknown():
    code = 'echo "it is working"'
    # use binary in path as interpreter but one that has no code highlighting
    tags = ['cd', 'test', 'main']
    light = False
    return rb.DocBlock(code, tags, light)
Example #6
0
def docblock_bash():
    code = 'echo "it is working"'
    # use bash as interpreter
    tags = ['bash', 'test', 'main']
    light = False
    return rb.DocBlock(code, tags, light)
Example #7
0
def test_docblock__run_unknown_action():
    with pytest.raises(BadInterpreter):
        docblock = rb.DocBlock(
            'some content',
            ['unknown-action:bad-data', 'test'],
        )
Example #8
0
def test_docblock_init_with_bad_interpreter():
    with pytest.raises(BadInterpreter):
        rb.DocBlock(tags=['bad_interpreter'], code='')