Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_save_eps_filename():
qr = segno.make_qr('test')
with tempfile.NamedTemporaryFile('w', suffix='.eps', delete=False) as f:
fn = f.name
qr.save(fn)
expected = '%!PS-Adobe-3.0 EPSF-3.0'
with open(fn, mode='r') as f:
val = f.read(len(expected))
os.unlink(fn)
assert expected == val
def test_save_png_filestream():
qr = segno.make_qr('test')
with tempfile.NamedTemporaryFile('wb', suffix='.png', delete=False) as f:
fn = f.name
qr.save(f)
expected = b'\211PNG\r\n\032\n' # PNG magic number
with open(fn, mode='rb') as f:
val = f.read(len(expected))
os.unlink(fn)
assert expected == val
def test_color_rgba2():
qr = segno.make_qr('test')
out = io.BytesIO()
qr.save(out, kind='png', dark='#000', light='#0000ffcc')
assert _has_palette(out.getvalue())
assert _has_transparency(out.getvalue())
def test_illegal_color_float():
color = (.1, 1.1, .1)
qr = segno.make_qr('test')
out = io.BytesIO()
with pytest.raises(ValueError):
qr.save(out, kind='pdf', dark=color)
def test_write_svg_color_rgb():
qr = segno.make_qr('test')
out = io.BytesIO()
qr.save(out, kind='svg', dark=(76, 131, 205))
xml_str = out.getvalue()
assert xml_str.startswith(b'
def test_write_tex_omit_url2():
qr = segno.make_qr('test', error='m', boost_error=False)
out = io.StringIO()
qr.save(out, kind='tex', border=4)
assert r'\href' not in out.getvalue()
def test_viewbox():
qr = segno.make_qr('test')
out = io.BytesIO()
qr.save(out, kind='svg', omitsize=True)
root = _parse_xml(out)
assert 'viewBox' in root.attrib
assert 'height' not in root.attrib
assert 'width' not in root.attrib
def test_greyscale_trans2():
qr = segno.make_qr('test')
out = io.BytesIO()
qr.save(out, kind='png', dark=None, light='white')
assert not _has_palette(out.getvalue())
assert _has_transparency(out.getvalue())
def png_segno(data='QR Code Symbol'):
"""Segno PNG 1-M"""
segno.make_qr(data, error='m').save('out/segno_%s.png' % data, scale=10, addad=False)
def make_geo(lat, lng):
"""\
Returns a QR Code which encodes geographic location using the ``geo`` URI
scheme.
:param float lat: Latitude
:param float lng: Longitude
:rtype: segno.QRCode
"""
return segno.make_qr(make_geo_data(lat, lng))