Skip to content

Commit

Permalink
Merge branch 'docs'
Browse files Browse the repository at this point in the history
  • Loading branch information
heuer committed Aug 19, 2016
2 parents ef5a801 + 5e6a357 commit aa0fbd4
Show file tree
Hide file tree
Showing 25 changed files with 663 additions and 650 deletions.
9 changes: 9 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Changes
=======

0.1.3 -- 2016-mm-dd
-------------------
* Registered new file extension "ans" which serializes the QR Code as
ANSI escape code (same output as QRCode.terminal())
* Removed deprecated methods "eps", "svg", "png", "pdf", and "txt" from
segno.QRCode
* Switched from nose tests to py.test


0.1.2 -- 2016-08-17
-------------------
* Updated docs
Expand Down
4 changes: 0 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ Use ``pip`` to install segno from PyPI::
Usage
-----

Segno provides several, specific methods which serialize the QR Code (like
``svg``, ``png``), but it also provides a general ``save()`` method which could
be used to save a QR Code in the desired format.

.. code-block:: python
>>> import segno
Expand Down
7 changes: 4 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# All configuration values have a default; values that are commented out
# serve to show the default.
from __future__ import unicode_literals
import sphinx_rtd_theme
import segno

# If extensions (or modules to document with autodoc) are in another directory,
Expand Down Expand Up @@ -89,7 +90,7 @@

# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
show_authors = False

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
Expand All @@ -108,15 +109,15 @@

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'classic' #'alabaster'
html_theme = "sphinx_rtd_theme" #'classic' #'alabaster'

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#html_theme_options = {}

# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = []
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]

# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
Expand Down
4 changes: 2 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Welcome to Segno's documentation!
=================================
Segno - Python QR Code and Micro QR Code generator
==================================================

Segno generates QR Codes and Micro QR Codes according to ``ISO/IEC 18004:2015(E)``.
Aside from other Pyhton QR Code generators, Segno has no 3rd party dependencies
Expand Down
48 changes: 17 additions & 31 deletions segno/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
VersionError, DataOverflowError
from . import writers, utils

__version__ = '0.1.2'
__version__ = '0.1.3'

__all__ = ('make', 'make_qr', 'make_micro', 'QRCode', 'QRCodeError',
'ErrorLevelError', 'ModeError', 'MaskError', 'VersionError',
Expand Down Expand Up @@ -299,8 +299,8 @@ def delete_file(name):

f = tempfile.NamedTemporaryFile('wb', suffix='.png', delete=False)
try:
self.png(f, scale=scale, color=color, background=background,
border=border)
self.save(f, scale=scale, color=color, background=background,
border=border)
except:
f.close()
os.unlink(f.name)
Expand Down Expand Up @@ -370,31 +370,6 @@ def terminal(self, out=None, border=None):
writers.write_terminal(self.matrix, self._version, out or sys.stdout,
border)

def svg(self, out, **kw):
import warnings
warnings.warn('Deprecated, use QRCode.save()')
self.save(out, kind='svg', **kw)

def png(self, out, **kw):
import warnings
warnings.warn('Deprecated, use QRCode.save()')
self.save(out, kind='png', **kw)

def txt(self, out, **kw):
import warnings
warnings.warn('Deprecated, use QRCode.save()')
self.save(out, kind='txt', **kw)

def eps(self, out, **kw):
import warnings
warnings.warn('Deprecated, use QRCode.save()')
self.save(out, kind='eps', **kw)

def pdf(self, out, **kw):
import warnings
warnings.warn('Deprecated, use QRCode.save()')
self.save(out, kind='pdf', **kw)

def save(self, out, kind=None, **kw):
"""\
Serializes the QR Code in one of the supported formats.
Expand Down Expand Up @@ -463,7 +438,7 @@ def save(self, out, kind=None, **kw):
xmldecl Boolean value (default: ``True``) indicating whether the
document should have an XML declaration header.
Set to ``False`` to omit the header.
svgns Boolean value (default: True) indicating whether the
svgns Boolean value (default: ``True``) indicating whether the
document should have an explicit SVG namespace declaration.
Set to ``False`` to omit the namespace declaration.
The latter might be useful if the document should be
Expand Down Expand Up @@ -562,12 +537,23 @@ def save(self, out, kind=None, **kw):
============= ==============================================================
**ANSI escape code**
Supports the "border" keyword, only!
============= ==============================================================
Name Description
============= ==============================================================
kind "ans"
============= ==============================================================
:param out: A filename or a writable file-like object with a
``name`` attribute. Use the `kind` parameter if `out` is
a :py:class:`io.ByteIO` or :py:class:`io.StringIO` stream which
don't have a ``name`` attribute.
:param kind: If the desired output format cannot be extracted from
the filename, this parameter can be used to indicate the
:param kind: If the desired output format cannot be determined from
the ``out`` parameter, this parameter can be used to indicate the
serialization format (i.e. "svg" to enforce SVG output)
:param kw: Any of the supported keywords by the specific serialization
method.
Expand Down
11 changes: 6 additions & 5 deletions segno/writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,12 @@ def write_svg_debug(matrix, version, out, scale=15, border=None,
x = j + border
bit = matrix[i][j]
if add_legend and bit not in (0x0, 0x1):
legend.append((y, x, bit))
legend.append((x, y, bit))
fill = clr_mapping.get(bit, fallback_color)
write('<rect x="{0}" y="{1}" width="1" height="1" fill="{2}"/>'.format(x, y, fill))
if add_legend:
for y, x, val in legend:
write('<text x="{0}" y="{1}">{2}</text>'.format(x+.2, y+.9, val))
# legend may be empty if add_legend == False
for x, y, val in legend:
write('<text x="{0}" y="{1}">{2}</text>'.format(x+.2, y+.9, val))
write('</g></svg>\n')
if must_close:
f.close()
Expand Down Expand Up @@ -694,7 +694,8 @@ def write_terminal(matrix, version, out, border=None):
'png': write_png,
'eps': write_eps,
'txt': write_txt,
'pdf': write_pdf
'pdf': write_pdf,
'ans': write_terminal
}

def save(matrix, version, out, kind=None, **kw):
Expand Down
5 changes: 2 additions & 3 deletions tests/alltests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
:organization: Semagia - http://www.semagia.com/
:license: BSD License
"""
import nose

if __name__ == '__main__':
nose.run()
import pytest
pytest.main()
55 changes: 27 additions & 28 deletions tests/test_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,33 @@
:license: BSD License
"""
from __future__ import absolute_import, unicode_literals
from nose.tools import eq_, raises, nottest
import pytest
from segno import colors


@raises(ValueError)
def test_illegal():
colors.color_to_rgb('unknown')
with pytest.raises(ValueError):
colors.color_to_rgb('unknown')


@raises(ValueError)
def test_illegal2():
colors.color_to_rgb((1, 2, 3, 256))
with pytest.raises(ValueError):
colors.color_to_rgb((1, 2, 3, 256))


@raises(ValueError)
def test_illegal3():
colors.color_to_rgb((300, 300, 300))
with pytest.raises(ValueError):
colors.color_to_rgb((300, 300, 300))


@raises(ValueError)
def test_illegal4():
colors.color_to_rgb((0, 0, 256))
with pytest.raises(ValueError):
colors.color_to_rgb((0, 0, 256))


@raises(ValueError)
def test_illegal5():
colors.color_to_rgb((256, 0, 0))
with pytest.raises(ValueError):
colors.color_to_rgb((256, 0, 0))


def test_color_is_black():
Expand All @@ -57,7 +57,7 @@ def test_color_is_black():
)

def check(expected, clr):
return eq_(expected, colors.color_is_black(clr))
assert expected == colors.color_is_black(clr)

for clr, expected in data:
yield check, expected, clr
Expand All @@ -82,7 +82,7 @@ def test_color_is_white():
)

def check(expected, clr):
return eq_(expected, colors.color_is_white(clr))
assert expected == colors.color_is_white(clr)

for clr, expected in data:
yield check, expected, clr
Expand All @@ -107,7 +107,7 @@ def test_color_to_webcolor():
)

def check(expected, clr):
return eq_(expected, colors.color_to_webcolor(clr))
assert expected == colors.color_to_webcolor(clr)

for clr, expected in data:
yield check, expected, clr
Expand All @@ -124,7 +124,7 @@ def test_color_to_webcolor_dont_optimize():
)

def check(expected, clr):
return eq_(expected, colors.color_to_webcolor(clr, optimize=False))
assert expected == colors.color_to_webcolor(clr, optimize=False)

for clr, expected in data:
yield check, expected, clr
Expand All @@ -133,8 +133,8 @@ def check(expected, clr):
def test_valid_colornames():
def check(name, expected):
rgb = colors.color_to_rgb(name)
eq_(3, len(rgb))
eq_(expected, rgb)
assert 3 == len(rgb)
assert expected == rgb
data = (
('red', (255, 0, 0)),
('green', (0, 128, 0)),
Expand All @@ -158,7 +158,7 @@ def test_hex_to_rgba():
)

def check(expected, color):
eq_(expected, colors._hex_to_rgb_or_rgba(color))
assert expected == colors._hex_to_rgb_or_rgba(color)

for color, expected in data:
yield check, expected, color
Expand All @@ -171,7 +171,7 @@ def test_hex_to_rgba_alpha_int():
)

def check(expected, color):
eq_(expected, colors._hex_to_rgb_or_rgba(color, alpha_float=False))
assert expected == colors._hex_to_rgb_or_rgba(color, alpha_float=False)

for color, expected in data:
yield check, expected, color
Expand All @@ -180,8 +180,8 @@ def check(expected, color):
def test_valid_hexcodes_rgb():
def check(name, expected):
rgb = colors.color_to_rgb(name)
eq_(3, len(rgb))
eq_(expected, rgb)
assert 3 == len(rgb)
assert expected == rgb
data = (
('#000', (0, 0, 0)),
('#FF1493', (255, 20, 147)),
Expand All @@ -200,8 +200,8 @@ def check(name, expected):
def test_valid_hexcodes_rgba():
def check(name, expected):
rgba = colors.color_to_rgba(name)
eq_(4, len(rgba))
eq_(expected, rgba)
assert 4 == len(rgba)
assert expected == rgba
data = (
('#808000', (128, 128, 0, 1.0)),
('red', (255, 0, 0, 1.0)),
Expand All @@ -216,7 +216,7 @@ def check(name, expected):
def test_tuple_to_rgba():
def check(t, expected):
rgba = colors.color_to_rgba(t)
eq_(expected, rgba)
assert expected == rgba

data = (
('#808000', (128, 128, 0, 1.0)),
Expand All @@ -231,7 +231,7 @@ def check(t, expected):
def test_tuple_to_rgba_int():
def check(t, expected):
rgba = colors.color_to_rgba(t, alpha_float=False)
eq_(expected, rgba)
assert expected == rgba

data = (
('#808000', (128, 128, 0, 255)),
Expand All @@ -245,7 +245,7 @@ def check(t, expected):

def test_invert_color():
def check(color, expected_color):
eq_(expected_color, colors.invert_color(color))
assert expected_color == colors.invert_color(color)
data = (
((0, 0, 0), (255, 255, 255)),
((255, 255, 255), (0, 0, 0)),
Expand All @@ -257,5 +257,4 @@ def check(color, expected_color):


if __name__ == '__main__':
import nose
nose.core.runmodule()
pytest.main(['-x', __file__])

0 comments on commit aa0fbd4

Please sign in to comment.