Exemple #1
0
def test_div():
    result = pt(8) / 2
    assert result == px(5)
    assert isinstance(result, pt)
    result = mm(30) / cm(3)
    assert result == 1
    assert isinstance(result, user)
    with raises(TypeError):
        3 / mm(30)
Exemple #2
0
from pytest import raises
from io import BytesIO

from svgast.ast import Svg, G, Rect, Circle, Text
from svgast.units import px
from svgast.xml import serialise, write


example_ast = Svg(
    G(
        Rect(x=1, y="2", width=px(3), height=4),
        Text('Hello', Rect(), 'World', cls='awesome')
    ),
    G(
        Circle(),
        Circle()
    )
)
expected_xml = '\n'.join((
    '<svg version="{}" xmlns="{}">'.format(
        example_ast.version, example_ast.xmlns),
    '  <g>',
    '    <rect height="4" width="3px" x="1" y="2" />',
    '    <text class="awesome">',
    '      Hello',
    '      <rect />',
    '      World',
    '    </text>',
    '  </g>',
    '  <g>',
    '    <circle />',
Exemple #3
0
def test_sub_different_type():
    result = in_(1) - px(48)
    assert result == user(42)
    assert isinstance(result, user)
Exemple #4
0
def test_add_different_type():
    result = in_(2) + px(-138)
    assert result == px(42)
    assert isinstance(result, user)
Exemple #5
0
def test_neq():
    assert mm(10) != px(10)
Exemple #6
0
def test_eq():
    assert in_(1) == 90
    assert px(42) == user(42)
    assert mm(10) == cm(1)