This repository has been archived by the owner on Aug 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
104 lines (86 loc) · 2.61 KB
/
tests.py
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016 -- Lars Heuer - Semagia <http://www.semagia.com/>.
# All rights reserved.
#
# License: BSD License
#
"""\
Tests against Segno Quark.
:author: Lars Heuer (heuer[at]semagia.com)
:organization: Semagia - http://www.semagia.com/
:license: BSD License
"""
from __future__ import absolute_import, unicode_literals
import xml.etree.ElementTree as etree
import io
import segno
_SVG_NS = 'http://www.w3.org/2000/svg'
def _parse_xml(buff):
"""\
Parses XML and returns the root element.
"""
buff.seek(0)
return etree.parse(buff).getroot()
def _find_svg_el(root, name):
return root.find('{{{0}}}{1}'.format(_SVG_NS, name))
def test_to_etree():
qr = segno.make_qr('Segno')
tree = qr.to_etree(scale=10, border=0, color='red')
assert tree is not None
root = tree.getroot()
assert root is not None
path = _find_svg_el(root, 'path')
assert path is not None
assert 'red' == path.attrib['stroke']
assert 'scale(10)' == path.attrib['transform']
def test_to_pacman_zero_ghosts():
qr = segno.make_qr('Segno')
out = io.BytesIO()
qr.to_pacman(out, color='red', ghosts=0)
root = _parse_xml(out)
print(etree.tostring(root))
assert root is not None
defs = _find_svg_el(root, 'defs')
assert defs is not None
# Assume that pacman is there if a cicle is there
circle = _find_svg_el(defs, 'circle')
assert circle is not None
ghosts = [el for el in defs if el.attrib.get('id') == 'ghost']
assert 0 == len(ghosts)
def test_to_pacman_ghosts():
qr = segno.make_qr('Segno')
out = io.BytesIO()
qr.to_pacman(out, color='red', ghosts=5)
root = _parse_xml(out)
assert root is not None
defs = _find_svg_el(root, 'defs')
assert defs is not None
# Assume that pacman is there if a cicle is there
circle = _find_svg_el(defs, 'circle')
assert circle is not None
ghosts = [el for el in defs if el.attrib.get('id') == 'ghost']
assert 1 == len(ghosts)
def test_to_glow():
qr = segno.make_qr('Segno')
out = io.BytesIO()
qr.to_glow(out)
root = _parse_xml(out)
assert root is not None
defs = _find_svg_el(root, 'defs')
assert defs is not None
filters = [el for el in defs]
assert 1 == len(filters)
def test_to_blur():
qr = segno.make_qr('Segno')
out = io.BytesIO()
qr.to_glow(out)
root = _parse_xml(out)
assert root is not None
defs = _find_svg_el(root, 'defs')
assert defs is not None
filters = [el for el in defs]
assert 1 == len(filters)
if __name__ == '__main__':
import pytest
pytest.main(['-x', __file__])