def test_smoke(self):
     """
     Smoke test to make sure tileify runs without errors
     REQUIRES photo named test_photo.jpg to be in current directory
     """
     image_data = Image.open("test_photo.jpg")
     num_tiles = 10
     max_shift = 30
     new_image_data = tileify(image_data, num_tiles, max_shift)
     assert new_image_data
def main():
    """Retrieves file entered, manipulates it and saves a copy with a new name"""
    # Parse options
    parser = optparse.OptionParser()
    parser.add_option(
        "-f",
        dest="filename",
        help="Picture to modify",
        metavar="FILE"
    )
    parser.add_option(
        "--max-shift",
        "-m",
        dest='max_shift',
        type="int",
        help='The max amount a block can randomly shift'
    )
    parser.add_option(
        "--num-tiles",
        "-n",
        dest='num_tiles',
        type="int",
        help='The number of tiles to break an image into'
    )
    (opts, args) = parser.parse_args()

    # Give user feedback if they forget an option and exit
    mandatory_options = ['filename']
    for option in mandatory_options:
        if not opts.__dict__[option]:
            print "Mandatory option is missing\n"
            parser.print_help()
            exit(-1)

    max_shift = opts.max_shift
    if max_shift == None:
        max_shift = 50

    num_tiles = opts.num_tiles
    if num_tiles == None:
        num_tiles = 20

    full_filename =  opts.filename
    if full_filename != None:
        try:
            image_data = Image.open(full_filename)
            new_image_data = tileify(image_data, num_tiles, max_shift)
            safe_save(full_filename, new_image_data)
        except IOError:
            print "Can not modify " + full_filename
    else:
        print 'Must enter photo in this directory'