# Buggy code
def save(self, targetdir, filename, meta_formats=None):
    """
    Store the image data into the target directory path,
    with given filename="dir/out.png"
    If metaformats are requested, export e.g. as "dir/out.docx".
    """
    if not isinstance(targetdir, Path):
        raise ValueError("util.fslike Path expected as targetdir")
    if not isinstance(filename, str):
        raise ValueError("str expected as filename, not %s" % type(filename))

    basename, ext = os.path.splitext(filename)

    if ext != ".png":
        raise ValueError("Texture must be saved as name.png. got: %s" % filename)

    # without the dot
    ext = ext[1:]

    # generate PNG file
    with targetdir[filename].open("wb") as imagefile:
        self.image_data.get_pil_image().save(imagefile, ext)

    if meta_formats:
        # generate formatted texture metadata
        formatter = data_formatter.DataFormatter()
        formatter.add_data(self.dump(basename))
        formatter.export(targetdir, meta_formats)


# Traceback (ValueError)
dev@openage:~/openage$ python3 -m openage convert-file /home/dev/aoe1/data/Border.drs 20000.slp /home/dev/aoe1/data/test.png
INFO opening slp in drs '/home/dev/aoe1/data/Border.drs:20000.slp'...
INFO parsing slp image...
INFO opening palette in drs '/home/dev/aoe1/data/interfac.drs:50500.bin'...
INFO parsing palette data...
INFO packing texture...
Traceback (most recent call last):
File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/dev/openage/openage/__main__.py", line 128, in <module>
exit(main())
File "/home/dev/openage/openage/__main__.py", line 121, in main
return args.entrypoint(args, cli.error)
File "/home/dev/openage/openage/convert/singlefile.py", line 72, in main
tex.save(Directory(path).root, filename)
File "/home/dev/openage/openage/convert/texture.py", line 170, in save
raise ValueError("Texture must be saved as name.png. got: %s" % filename)
ValueError: Texture must be saved as name.png. got: test

# Fixed code
def save(self, targetdir, filename, meta_formats=None):
    """
    Store the image data into the target directory path,
    with given filename="dir/out.png"
    If metaformats are requested, export e.g. as "dir/out.docx".
    """
    if not isinstance(targetdir, Path):
        raise ValueError("util.fslike Path expected as targetdir")
    if not isinstance(filename, str):
        raise ValueError("str expected as filename, not %s" % type(filename))

    basename, ext = os.path.splitext(filename)

    # only allow png, although PIL could of course
    # do other formats.
    if ext != ".png":
        raise ValueError(
            "Filename invalid, a texture must be saved"
            "as 'filename.png', not '%s'" % (filename)
        )

    # without the dot
    ext = ext[1:]

    # generate PNG file
    with targetdir[filename].open("wb") as imagefile:
        self.image_data.get_pil_image().save(imagefile, ext)

    if meta_formats:
        # generate formatted texture metadata
        formatter = data_formatter.DataFormatter()
        formatter.add_data(self.dump(basename))
        formatter.export(targetdir, meta_formats)