Skip to content

Commit

Permalink
Add some more tests. Bump version to 1.2.
Browse files Browse the repository at this point in the history
----------------
real    0m0.326s
user    0m0.275s
sys     0m0.035s
  • Loading branch information
dustmop committed Oct 13, 2016
1 parent f526732 commit a0249ce
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 5 deletions.
1 change: 0 additions & 1 deletion makechr/image_processor.py
Expand Up @@ -295,7 +295,6 @@ def make_palette(self, palette_text, bg_color, is_sprite):
if self.img.palette:
# If the image uses indexed color, try to extract a palette.
extractor = extract_indexed_image_palette.ExtractIndexedImagePalette(self)
# TODO: Add a test for this.
pal = extractor.extract_palette(self.img.palette, self.img.format)
if pal:
return pal
Expand Down
9 changes: 7 additions & 2 deletions makechr/makechr.py
Expand Up @@ -2,11 +2,12 @@
import argparse
import bg_color_spec
import errno
import errors
from PIL import Image
import sys


__version__ = '1.1'
__version__ = '1.2'


def run():
Expand Down Expand Up @@ -133,7 +134,11 @@ def run():
elif e.errno == errno.ENOENT:
sys.stderr.write('Input file not found: "%s"\n' % args.input)
sys.exit(1)
if not application.run(img, args):
try:
if not application.run(img, args):
sys.exit(1)
except errors.CommandLineArgError, e:
sys.stderr.write('Command-line error: %s\n' % e)
sys.exit(1)
else:
parser.print_usage()
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Expand Up @@ -3,14 +3,14 @@
long_description = """Makechr is a tool for generating NES graphics from pixel art images. It creates the NES graphical components as separate files, letting you easily include these are binaries into homebrew ROMs. There are many options for handling different types of input images, check the README for more information."""

setup(name='Makechr',
version='1.1',
version='1.2',
description='Makechr tool for generating NES graphics',
long_description=long_description,
author='Dustin Long',
author_email='me@dustmop.io',
scripts=['bin/makechr'],
url='http://dustmop.io/software/makechr',
download_url='https://github.com/dustmop/makechr/tarball/1.1',
download_url='https://github.com/dustmop/makechr/tarball/1.2',
license='GPL3',
packages=['makechr'],
keywords='NES graphics gamedev',
Expand Down
22 changes: 22 additions & 0 deletions tests/extract_indexed_image_palette_test.py
@@ -0,0 +1,22 @@
import unittest

from PIL import Image

import context
from makechr import extract_indexed_image_palette, image_processor


class ExtractIndexedImagePaletteTests(unittest.TestCase):
def test_extract(self):
"""Extract a palette from a 16-color indexed image."""
img = Image.open('testdata/full-image-16color.png')
processor = image_processor.ImageProcessor()
extractor = extract_indexed_image_palette.ExtractIndexedImagePalette(
processor)
pal = extractor.extract_palette(img.palette, img.format)
self.assertEqual(str(pal),
'P/16-30-01-0f/16-30-01-38/16-30-19-28/16-23-23-28/')


if __name__ == '__main__':
unittest.main()
16 changes: 16 additions & 0 deletions tests/integration_test.py
Expand Up @@ -81,6 +81,14 @@ def test_import_memory_produce_view(self):
self.assert_file_eq(reuse_view_name, self.golden('reuse', 'png'))
self.assertEqual(self.out, '')

def test_sprite_8x16(self):
self.output_name = os.path.join(self.tmpdir, 'reticule.o')
self.golden_file_prefix = 'reticule'
args = ['testdata/reticule.png', '-o', self.output_name, '-t', '8x16', '-s']
self.makechr(args)
self.assert_file_eq(self.output_name, self.golden('8x16', 'o'))
self.assertEqual(self.out, '')

def test_error_too_many_tiles(self):
args = ['testdata/257tiles.png', '-o', self.output_name]
self.makechr(args, is_expect_fail=True)
Expand Down Expand Up @@ -109,6 +117,14 @@ def test_error_input_and_import(self):
self.assertEquals(self.err, """Cannot both import memory and process input file""")
self.assertEquals(self.returncode, 1)

def test_error_8x16_without_sprite(self):
self.output_name = os.path.join(self.tmpdir, 'reticule.o')
self.golden_file_prefix = 'reticule'
args = ['testdata/reticule.png', '-o', self.output_name, '-t', '8x16']
self.makechr(args, is_expect_fail=True)
self.assertEquals(self.err, """Command-line error: Traversal strategy \'8x16\' requires -s flag\n""")
self.assertEquals(self.returncode, 1)

def golden(self, name, ext):
if name:
return 'testdata/%s-%s.%s' % (self.golden_file_prefix, name, ext)
Expand Down
Binary file added tests/testdata/reticule-8x16.o
Binary file not shown.

0 comments on commit a0249ce

Please sign in to comment.