예제 #1
0
def test_tikzcd_config_options(monkeypatch, tmpdir, document_cd):
    mock_call = Mock()
    mock_move = Mock()
    monkeypatch.setattr('subprocess.call', mock_call)
    monkeypatch.setattr('os.remove', Mock)
    monkeypatch.setattr('shutil.move', mock_move)

    with py.path.local(os.path.dirname(__file__)).as_cwd():
        doc = document_cd(compiler='xelatex',
                          converter='mockconv',
                          template='tikzcdtemplate')
    tikz_tmpdir = doc.userdata['tikzcd']['tmp_dir']

    with tmpdir.as_cwd():
        renderer = Renderer()
        renderer.render(doc)

    pics = doc.getElementsByTagName('tikzcd')
    assert pics
    tex_path = os.path.join(tikz_tmpdir, pics[0].id + '.tex')
    assert os.path.isfile(tex_path)
    with open(tex_path, 'r') as f:
        assert 'usetikzlibrary' in f.read()

    assert 'xelatex' in mock_call.call_args_list[0][0][0]
    assert 'mockconv' in mock_call.call_args_list[1][0][0]
예제 #2
0
def test_tikz_basic_setup(monkeypatch, tmpdir, document):
    mock_call = Mock()
    mock_move = Mock()
    monkeypatch.setattr('subprocess.call', mock_call)
    monkeypatch.setattr('os.remove', Mock)
    monkeypatch.setattr('shutil.move', mock_move)

    doc = document()
    tikz_tmpdir = doc.userdata['tikzpicture']['tmp_dir']

    with tmpdir.as_cwd():
        renderer = Renderer()
        renderer.render(doc)

    pics = doc.getElementsByTagName('tikzpicture')
    assert pics
    tex_path = os.path.join(tikz_tmpdir, pics[0].id + '.tex')
    assert os.path.isfile(tex_path)
    with open(tex_path, 'r') as f:
        assert 'draw' in f.read()

    assert 'pdflatex' in mock_call.call_args_list[0][0][0]
    assert 'pdf2svg' in mock_call.call_args_list[1][0][0]
    assert mock_move.called

    assert 'TikZ picture' in tmpdir.join('index.html').read()
예제 #3
0
def test_tikzcd_basic_setup(monkeypatch, tmpdir, document_cd):
    cur_dir = os.getcwd()
    os.chdir(os.path.dirname(__file__))
    mock_call = Mock()
    mock_move = Mock()
    monkeypatch.setattr('subprocess.call', mock_call)
    monkeypatch.setattr('os.remove', Mock)
    monkeypatch.setattr('shutil.move', mock_move)

    doc = document_cd()
    tikz_tmpdir = doc.userdata['tikzcd']['tmp_dir']
    os.chdir(str(tmpdir))
    renderer = Renderer()
    renderer.render(doc)

    pics = doc.getElementsByTagName('tikzcd')
    assert pics
    tex_path = os.path.join(tikz_tmpdir, pics[0].id + '.tex')
    assert os.path.isfile(tex_path)
    with open(tex_path, 'r') as f:
        assert '\\rar' in f.read()

    assert 'pdflatex' in mock_call.call_args_list[0][0][0]
    assert 'pdf2svg' in mock_call.call_args_list[1][0][0]
    assert mock_move.called

    assert 'Commutative diagram' in tmpdir.join('index.html').read()
    os.chdir(cur_dir)