File: test_transformlistparser.py

package info (click to toggle)
svgwrite 1.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 2,092 kB
  • sloc: python: 12,603; makefile: 117; sh: 5
file content (68 lines) | stat: -rw-r--r-- 2,628 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
#coding:utf-8
# Author:  mozman --<mozman@gmx.at>
# Purpose: transform list parser
# Created: 10.10.2010
# Copyright (C) 2010, Manfred Moitzi
# License: MIT License

import unittest

from svgwrite.data.svgparser import is_valid_transferlist

class TestTransformListParser(unittest.TestCase):
    def test_matrix_1(self):
        self.assertTrue(is_valid_transferlist("matrix(1 2 3 4 5 6)"))

    def test_matrix_2(self):
        self.assertTrue(is_valid_transferlist("matrix(1, 2, 3, 4, 5, 6)"))

    def test_translate_1(self):
        self.assertTrue(is_valid_transferlist("translate(1)"))
    def test_translate_2(self):
        self.assertTrue(is_valid_transferlist("translate(1 2)"))
    def test_translate_3(self):
        self.assertTrue(is_valid_transferlist("translate(1,2)"))

    def test_rotate_1(self):
        self.assertTrue(is_valid_transferlist("rotate(1)"))
    def test_rotate_3(self):
        self.assertTrue(is_valid_transferlist("rotate(1 2 3)"))

    def test_scale_1(self):
        self.assertTrue(is_valid_transferlist("scale(1)"))
    def test_scale_2(self):
        self.assertTrue(is_valid_transferlist("scale(2)"))

    def test_skewX(self):
        self.assertTrue(is_valid_transferlist("skewX(30)"))

    def test_skewY(self):
        self.assertTrue(is_valid_transferlist("skewY(30)"))

    def test_parse_skewX_errors(self):
        self.assertFalse(is_valid_transferlist("skewX()"))
        self.assertFalse(is_valid_transferlist("skewX(30 30)"))
        self.assertFalse(is_valid_transferlist("skewX(30,30)"))

    def test_parse_skewY_errors(self):
        self.assertFalse(is_valid_transferlist("skewY()"))
        self.assertFalse(is_valid_transferlist("skewY(30 30)"))
        self.assertFalse(is_valid_transferlist("skewY(30,30)"))

    def test_parse_matrix_errors(self):
        self.assertFalse(is_valid_transferlist("matrix()"))
        self.assertFalse(is_valid_transferlist("matrix(1, 2, 3, 4, 5, 6,)"))
        self.assertFalse(is_valid_transferlist("matrix(1, 2, 3, 4, 5, )"))
        self.assertFalse(is_valid_transferlist("matrix(1, 2, 3, 4)"))

    def test_multi_command(self):
        self.assertTrue(is_valid_transferlist("matrix(1 2 3 4 5 6) skewX(30)"))
        self.assertTrue(is_valid_transferlist("skewY(15), matrix(1 2 3 4 5 6) skewX(30)"))

    def test_multi_command_errors(self):
        self.assertFalse(is_valid_transferlist("skewX(15),, skewY(15)"))
        self.assertFalse(is_valid_transferlist("skewX(15), skewY(15) ,"))

if __name__ == '__main__':
    unittest.main()