Пример #1
0
def test_doccommander_add__while_running():
    dc = rc.DocCommander()
    dc.add('sleep 2\n', ['bash', 'test1'])
    t = threading.Thread(target=doccommander_worker, args=(dc, ))
    t.start()
    time.sleep(1)
    with pytest.raises(RundocException):
        dc.add('echo "bad"\n', ['bash', 'test1'])
Пример #2
0
def test_parsers__parse_doc__single_session():
    f = io.StringIO()
    data = '```env\na=b\n```\n```bash#test1\nls\n```\n\n```bash#test2\nls -al\n```'
    expected = rc.DocCommander()
    expected.add('ls\nls -al\n', ['bash'])
    expected.env.import_string("a=b")
    f.write(data)
    f.seek(0)
    c = rp.parse_doc(f, single_session='bash')
    assert c.get_dict() == expected.get_dict()
Пример #3
0
def test_parsers__parse_doc():
    f = io.StringIO()
    data = '```env\na=b\n```\n```bash#test1\nls\n```\n\n```bash#test2\nls -al\n```'
    expected = rc.DocCommander()
    expected.add('ls\n', ['bash', 'test1'])
    expected.add('ls -al\n', ['bash', 'test2'])
    f.write(data)
    f.seek(0)
    c = rp.parse_doc(f, 'bash')
    assert c.get_dict() == expected.get_dict()
Пример #4
0
def test_doccommander_run(dummy_file):
    dc = rc.DocCommander()
    dc.add('echo "test1"\n', ['bash', 'test1'])
    dc.add('echo "test2"\n', ['bash', 'test1'])
    dc.add('echo "test3"\n', ['bash', 'test1'])
    with open(dummy_file, 'w') as f:
        dc.run(inherit_env=True, output=f)
    assert len(dc.get_dict()['code_blocks']) == 3
    for cb in dc.get_dict()['code_blocks']:
        assert len(cb['runs']) == 1
Пример #5
0
def test_doccommander_write_output(dummy_file):
    dc = rc.DocCommander()
    dc.add('echo "test"\n', ['bash', 'test1'])
    dc.run()
    with open(dummy_file, 'w') as f:
        dc.output = f
        dc.write_output()
    with open(dummy_file, 'r') as f:
        output = json.loads(f.read())
        assert len(output['code_blocks']) == 1
Пример #6
0
def test_doccommander_get_dict():
    dc = rc.DocCommander()
    dc.add('ls\n', ['bash', 'test1'])
    assert dc.get_dict() == {
        "code_blocks": [{
            "code": "ls\n",
            "tags": ["bash", "test1"],
            "interpreter": "bash",
            "runs": []
        }],
        "env": {}
    }
Пример #7
0
def test_doccommander_die_with_grace(dummy_file):
    dc = rc.DocCommander()
    dc.add('echo "test"\n', ['bash', 'test1'])
    dc.add('sleep 2\n', ['bash', 'test1'])
    with open(dummy_file, 'w') as f:
        dc.output = f
        t = threading.Thread(target=doccommander_worker, args=(dc, ))
        t.start()
        time.sleep(1)
        dc.die_with_grace()
    with open(dummy_file, 'r') as f:
        output = json.loads(f.read())
        assert output['code_blocks'][0]['runs'][0]['output'] == 'test\n'
Пример #8
0
def test_doccommander_add():
    dc = rc.DocCommander()
    assert len(dc.doc_blocks) == 0
    dc.add('ls\n', ['bash', 'test1'])
    assert len(dc.doc_blocks) == 1
    assert dc.doc_blocks[0].code == 'ls\n'
    assert dc.doc_blocks[0].tags == ['bash', 'test1']
    dc.add('ls -al\n', ['bash', 'test2'])
    assert len(dc.doc_blocks) == 2
    assert dc.doc_blocks[0].code == 'ls\n'
    assert dc.doc_blocks[0].tags == ['bash', 'test1']
    assert dc.doc_blocks[1].code == 'ls -al\n'
    assert dc.doc_blocks[1].tags == ['bash', 'test2']
Пример #9
0
def test_doccommander_run__failed():
    dc = rc.DocCommander()
    dc.add('cat /non_existent', ['bash', 'test1'])
    with pytest.raises(CodeFailed):
        dc.run(retry=5, retry_pause=0.1)
Пример #10
0
def test_doccommander_add__unknown_interpreter():
    dc = rc.DocCommander()
    with pytest.raises(SystemExit):
        dc.add('sleep 1\n', ['unknown', 'test1'])
Пример #11
0
def test_doccommander_doc_block__no_step():
    dc = rc.DocCommander()
    dc.add('ls\n', ['bash', 'test1'])
    assert dc.doc_block == None
Пример #12
0
def test_doccommander_doc_block__step():
    dc = rc.DocCommander()
    dc.add('ls\n', ['bash', 'test1'])
    dc.step = 1
    assert dc.doc_block == dc.doc_blocks[0]