forked from lincolnloop/python-qrcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
172a172
commit cf66af6
Showing
3 changed files
with
78 additions
and
66 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import io | ||
import os | ||
import unittest | ||
from tempfile import mkdtemp | ||
|
||
import qrcode | ||
from qrcode.image import svg | ||
|
||
UNICODE_TEXT = "\u03b1\u03b2\u03b3" | ||
|
||
|
||
class SvgImageWhite(svg.SvgImage): | ||
background = "white" | ||
|
||
|
||
class QRCodeSvgTests(unittest.TestCase): | ||
def setUp(self): | ||
self.tmpdir = mkdtemp() | ||
|
||
def tearDown(self): | ||
os.rmdir(self.tmpdir) | ||
|
||
def test_render_svg(self): | ||
qr = qrcode.QRCode() | ||
qr.add_data(UNICODE_TEXT) | ||
img = qr.make_image(image_factory=svg.SvgImage) | ||
img.save(io.BytesIO()) | ||
|
||
def test_render_svg_path(self): | ||
qr = qrcode.QRCode() | ||
qr.add_data(UNICODE_TEXT) | ||
img = qr.make_image(image_factory=svg.SvgPathImage) | ||
img.save(io.BytesIO()) | ||
|
||
def test_render_svg_fragment(self): | ||
qr = qrcode.QRCode() | ||
qr.add_data(UNICODE_TEXT) | ||
img = qr.make_image(image_factory=svg.SvgFragmentImage) | ||
img.save(io.BytesIO()) | ||
|
||
def test_svg_string(self): | ||
qr = qrcode.QRCode() | ||
qr.add_data(UNICODE_TEXT) | ||
img = qr.make_image(image_factory=svg.SvgFragmentImage) | ||
file_like = io.BytesIO() | ||
img.save(file_like) | ||
file_like.seek(0) | ||
assert file_like.read() in img.to_string() | ||
|
||
def test_render_svg_with_background(self): | ||
qr = qrcode.QRCode() | ||
qr.add_data(UNICODE_TEXT) | ||
img = qr.make_image(image_factory=SvgImageWhite) | ||
img.save(io.BytesIO()) |