Exemple #1
0
def test_invalid_arc_not_enough_args(path):
    pen = ArcRecordingPen()
    with pytest.raises(ValueError, match="Invalid arc command") as e:
        parse_path(path, pen)

    assert isinstance(e.value.__cause__, ValueError)
    assert "Not enough arguments" in str(e.value.__cause__)
Exemple #2
0
def test_equivalent_paths(pathdef1, pathdef2):
    pen1 = RecordingPen()
    parse_path(pathdef1, pen1)

    pen2 = RecordingPen()
    parse_path(pathdef2, pen2)

    assert pen1.value == pen2.value
Exemple #3
0
def test_arc_pen_with_arcTo():
    pen = ArcRecordingPen()
    parse_path("M300,200 h-150 a150,150 0 1,0 150,-150 z", pen)
    expected = [('moveTo', ((300.0, 200.0), )), ('lineTo', ((150.0, 200.0), )),
                ('arcTo', (150.0, 150.0, 0.0, True, False, (300.0, 50.0))),
                ('lineTo', ((300.0, 200.0), )), ('closePath', ())]

    assert pen.value == expected
Exemple #4
0
def test_equivalent_paths(pathdef1, pathdef2):
    pen1 = RecordingPen()
    parse_path(pathdef1, pen1)

    pen2 = RecordingPen()
    parse_path(pathdef2, pen2)

    assert pen1.value == pen2.value
Exemple #5
0
def test_exponents():
    # It can be e or E, the plus is optional, and a minimum of +/-3.4e38 must be supported.
    pen = RecordingPen()
    parse_path("M-3.4e38 3.4E+38L-3.4E-38,3.4e-38", pen)
    expected = [
        ("moveTo", ((-3.4e+38, 3.4e+38), )),
        ("lineTo", ((-3.4e-38, 3.4e-38), )),
        ("endPath", ()),
    ]

    assert pen.value == expected
Exemple #6
0
def test_exponents():
    # It can be e or E, the plus is optional, and a minimum of +/-3.4e38 must be supported.
    pen = RecordingPen()
    parse_path("M-3.4e38 3.4E+38L-3.4E-38,3.4e-38", pen)
    expected = [
        ("moveTo", ((-3.4e+38, 3.4e+38),)),
        ("lineTo", ((-3.4e-38, 3.4e-38),)),
        ("endPath", ()),
    ]

    assert pen.value == expected
Exemple #7
0
    def __init__(self, name, d, advwidth, advheight, transform=Identity):
        self.name = name

        advwidth *= abs(transform[0])
        advheight *= abs(transform[3])
        self.advwidth = advwidth
        self.advheight = advheight

        pen = T2CharStringPen(advwidth, None)
        tpen = TransformPen(pen, transform)
        parse_path(d, tpen)
        self.charstring = pen.getCharString()
Exemple #8
0
def test_invalid_arc_argument_value():
    pen = ArcRecordingPen()
    with pytest.raises(ValueError, match="Invalid arc command") as e:
        parse_path("M0,0 A0,0,0,2,0,0,0", pen)

    cause = e.value.__cause__
    assert isinstance(cause, ValueError)
    assert "Invalid argument for 'large-arc-flag' parameter: '2'" in str(cause)

    pen = ArcRecordingPen()
    with pytest.raises(ValueError, match="Invalid arc command") as e:
        parse_path("M0,0 A0,0,0,0,-2.0,0,0", pen)

    cause = e.value.__cause__
    assert isinstance(cause, ValueError)
    assert "Invalid argument for 'sweep-flag' parameter: '-2.0'" in str(cause)
Exemple #9
0
def test_arc_to_cubic_bezier():
    pen = RecordingPen()
    parse_path("M300,200 h-150 a150,150 0 1,0 150,-150 z", pen)
    expected = [
        ('moveTo', ((300.0, 200.0), )), ('lineTo', ((150.0, 200.0), )),
        ('curveTo', ((150.0, 282.842), (217.157, 350.0), (300.0, 350.0))),
        ('curveTo', ((382.842, 350.0), (450.0, 282.842), (450.0, 200.0))),
        ('curveTo', ((450.0, 117.157), (382.842, 50.0), (300.0, 50.0))),
        ('lineTo', ((300.0, 200.0), )), ('closePath', ())
    ]

    result = list(pen.value)
    assert len(result) == len(expected)
    for (cmd1, points1), (cmd2, points2) in zip(result, expected):
        assert cmd1 == cmd2
        assert len(points1) == len(points2)
        for pt1, pt2 in zip(points1, points2):
            assert pt1 == pytest.approx(pt2, rel=1e-5)
Exemple #10
0
def test_parse_path(pathdef, expected):
    pen = RecordingPen()
    parse_path(pathdef, pen)

    assert pen.value == expected
Exemple #11
0
 def drawPoints(pointPen):
     pen = TransformPen(SegmentToPointPen(pointPen), transform)
     parse_path(path, pen)
Exemple #12
0
def test_arc_not_implemented():
    pathdef = "M300,200 h-150 a150,150 0 1,0 150,-150 z"
    with pytest.raises(NotImplementedError) as exc_info:
        parse_path(pathdef, RecordingPen())
    assert exc_info.match("arcs are not supported")
Exemple #13
0
def test_invalid_implicit_command():
    with pytest.raises(ValueError) as exc_info:
        parse_path("M 100 100 L 200 200 Z 100 200", RecordingPen())
    assert exc_info.match("Unallowed implicit command")
Exemple #14
0
def test_invalid_implicit_command():
    with pytest.raises(ValueError) as exc_info:
        parse_path("M 100 100 L 200 200 Z 100 200", RecordingPen())
    assert exc_info.match("Unallowed implicit command")
Exemple #15
0
def test_arc_flags_without_spaces(path, expected):
    pen = ArcRecordingPen()
    parse_path(path, pen)
    assert pen.value == expected
Exemple #16
0
def test_arc_not_implemented():
    pathdef = "M300,200 h-150 a150,150 0 1,0 150,-150 z"
    with pytest.raises(NotImplementedError) as exc_info:
        parse_path(pathdef, RecordingPen())
    assert exc_info.match("arcs are not supported")
Exemple #17
0
def test_parse_path(pathdef, expected):
    pen = RecordingPen()
    parse_path(pathdef, pen)

    assert pen.value == expected