Ejemplo n.º 1
0
def test_custom_font_family(graph_cases_factory, port):
    """
    :type graph_cases_factory: callable
    :type port: qmxgraph.tests.conftest.Port
    """
    options = GraphOptions(font_family=('Helvetica', ), )

    with server.host(port=port.get(), options=options) as host:
        cases = graph_cases_factory(host)
        graph = cases("1v")

        match = graph.selenium.find_elements_by_css_selector(
            'div[style*="font-family:Helvetica"]')
        assert len(match) == 1
Ejemplo n.º 2
0
def test_custom_shapes(selenium, port, tmpdir, wait_graph_page_ready):
    """
    :type selenium: selenium.webdriver.remote.webdriver.WebDriver
    :type port: qmxgraph.tests.conftest.Port
    """
    # Shape found in by https://www.draw.io/stencils/basic.xml
    custom_stencil = '''\
<shapes>
    <shape name="Moon" h="103.05" w="77.05" aspect="variable" strokewidth="inherit">
        <connections>
            <constraint x="0.48" y="0" perimeter="0" name="N"/>
            <constraint x="1" y="0.89" perimeter="0" name="SE"/>
        </connections>
        <background>
            <path>
                <move x="37.05" y="0"/>
                    <arc rx="48" ry="48" x-axis-rotation="0" large-arc-flag="1" sweep-flag="0" x="77.05" y="92"/>
                    <arc rx="60" ry="60" x-axis-rotation="0" large-arc-flag="0" sweep-flag="1" x="37.05" y="0"/>
                <close/>
            </path>
        </background>
        <foreground>
            <fillstroke/>
        </foreground>
    </shape>
</shapes>'''  # noqa

    stencil_file = tmpdir.mkdir("stencils").join("custom.xml")
    stencil_file.write(custom_stencil)
    stencils = [str(stencil_file)]

    styles = GraphStyles({
        'moon': {
            'shape': 'Moon',
            'fill_color': '#ffff00',
        },
    })

    def has_custom_shape():
        return bool(
            selenium.find_elements_by_css_selector('g>g>path[fill="#ffff00"]'))

    with server.host(port=port.get(), styles=styles,
                     stencils=stencils) as host:
        wait_graph_page_ready(host=host)
        assert not has_custom_shape()
        selenium.execute_script(
            "api.insertVertex(10, 10, 20, 20, 'custom', 'moon')")
        assert has_custom_shape()
Ejemplo n.º 3
0
def test_edge_with_style(port, mode, graph_cases_factory):
    """
    :type port: qmxgraph.tests.conftest.Port
    :type mode: str
    :type graph_cases_factory: callable
    """
    styles = GraphStyles({
        'edge': {
            'stroke_color': '#000000',
        },
    })

    with server.host(port=port.get(), styles=styles) as host:
        cases = graph_cases_factory(host)
        graph = cases('2v_1e' if mode == 'by_code' else '2v_1eDD')
        assert graph.get_edge(
            *graph.get_vertices()).get_attribute('stroke') == '#000000'
Ejemplo n.º 4
0
def host(port):
    """
    Hosts a graph page, with a series of simple default options and styles.

    :type port: Port
    :rtype: qmxgraph.host_graph.Host
    :return: Object with details about hosted graph page.
    """
    from qmxgraph.configuration import GraphStyles
    styles = GraphStyles({
        'group': {
            'shape': 'rectangle',
            'fill_color': '#ff93ba',
            'dashed': True,
        },
        'table': {
            'fill_color': '#ffffff',
            'stroke_opacity': 0,
            'fill_opacity': 0,
        },
        'yellow': {
            'fill_color': '#ffff00',
        },
        'purple': {
            'fill_color': '#ff00ff',
        },
    })

    from qmxgraph.configuration import GraphOptions
    options = GraphOptions(
        # Highlight disabled for this kind of test as interferes a lot with
        # some mouse events, preventing Selenium from clicking desired
        # HTML elements.
        show_highlight=False,
    )

    from qmxgraph import server
    with server.host(port=port.get(), styles=styles, options=options) as host_:
        yield host_