Пример #1
0
def init(names: str, *_args: Any, **_kwargs: Any) -> None:
    """Initialize additional image formats.

    Args:
        names: Names separated by a comma of the image formats to add.
    """
    for name in names.split(","):
        name = name.lower().strip()
        try:
            test = FORMATS[name]
            files.add_image_format(name, test)
            _logger.debug("Added image format '%s'", name)
        except KeyError:
            _logger.error("Ignoring unknown image format '%s'", name)
Пример #2
0
def add_external_format(
    file_format: str,
    test_func: Callable[[bytes, BinaryIO], bool],
    load_func: Callable[[str], QPixmap],
) -> None:
    """Add support for new fileformat.

    Args:
        file_format: String value of the file type
        test_func: Function returning True if load_func supports this type.
        load_func: Function to load a QPixmap from the passed path.
    """
    files.add_image_format(file_format, test_func)
    imagereader.external_handler[file_format] = load_func
def test_add_unsupported_format(mockimghdr, tmpfile):
    files.add_image_format("not_a_format", _test_dummy)
    assert imghdr.what(tmpfile) is None
    assert not mockimghdr, "Unsupported test not removed"
def test_add_supported_format(mockimghdr, tmpfile, name):
    files.add_image_format(name, _test_dummy)
    assert mockimghdr, "No test added by add image format"
    assert imghdr.what(tmpfile) == name