Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get coverage to 100%; fix a trivial bug in the CLI #14

Open
wants to merge 5 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ show_missing = True
exclude_lines =
pragma: no cover
assert False, 'Should not be reachable'
fail_under = 100
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

v0.3.1 - 2019-04-07
*******************

Fix a bug in the CLI tool that would error out with `new style getargs format but argument is not a tuple`.

v0.3.0 - 2019-04-07
*******************

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def local_file(name):

setup(
name='specktre',
version='0.3.0',
version='0.3.1',
description='A tool for creating wallpapers with Python',
long_description=long_description,
url='https://github.com/alexwlchan/specktre',
Expand Down
3 changes: 3 additions & 0 deletions src/specktre/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class RGBColor(object):
green = attr.ib()
blue = attr.ib()

def as_tuple(self):
return (self.red, self.green, self.blue)


def random_color(start, end):
d_red = (start.red - end.red)
Expand Down
6 changes: 3 additions & 3 deletions src/specktre/specktre.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def draw_speckled_wallpaper(settings):
squares = settings.generator(settings.width, settings.height)
colors = random_color(settings.start_color, settings.end_color)
for sq, color in zip(squares, colors):
ImageDraw.Draw(im).polygon(sq, fill=color)
ImageDraw.Draw(im).polygon(tuple(sq), fill=color.as_tuple())

return im

Expand All @@ -29,6 +29,6 @@ def save_speckled_wallpaper(settings):
print('Saved new wallpaper as %s' % filename)


def main():
settings = cli.parse_args(sys.argv)
def main(): # pragma: no cover
settings = cli.parse_args(sys.argv[1:])
save_speckled_wallpaper(settings)
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_non_positive_integers_are_valueerror(self, value):
def test_non_integers_are_valuerror(self, value):
"""Values that cannot be coerced to an integer are rejected with a
`ValueError`."""
assume(not value.strip().isdigit())
assume(not all(c in '-0123456789 ' for c in value))
with pytest.raises(ValueError) as exc:
cli.check_positive_integer(name='test', value=value)
assert 'should be an integer' in exc.value.args[0]
Expand Down
61 changes: 61 additions & 0 deletions tests/test_specktre.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# -*- encoding: utf-8

import os

from PIL import Image

from specktre.cli import Settings
from specktre.colors import RGBColor
from specktre.specktre import draw_speckled_wallpaper, save_speckled_wallpaper
from specktre.tilings import generate_hexagons, generate_triangles


def test_draw_speckled_wallpaper():
s = Settings(
generator=generate_triangles,
width=200,
height=300,
start_color=RGBColor(0, 0, 256),
end_color=RGBColor(0, 0, 0),
name="output.jpg"
)

im = draw_speckled_wallpaper(s)
assert im.size == (200, 300)


def test_save_speckled_wallpaper(tmpdir):
name = tmpdir / "output.jpg"
s = Settings(
generator=generate_hexagons,
width=200,
height=300,
start_color=RGBColor(0, 0, 256),
end_color=RGBColor(0, 0, 0),
name=str(name)
)

save_speckled_wallpaper(s)
assert name.exists()
im = Image.open(name)
assert im.size == (200, 300)


def test_save_speckled_wallpaper_generates_name(tmpdir):
os.chdir(str(tmpdir))
s = Settings(
generator=generate_hexagons,
width=200,
height=300,
start_color=RGBColor(0, 0, 256),
end_color=RGBColor(0, 0, 0),
name=None
)

assert tmpdir.listdir() == []
save_speckled_wallpaper(s)

assert len(tmpdir.listdir()) == 1
name = tmpdir.listdir()[0]
im = Image.open(name)
assert im.size == (200, 300)