korymath / talk-generator

talk-generator is capable of generating coherent slide decks based on a single topic suggestion.
MIT License
124 stars 9 forks source link

Test failing on generate talk from multiple topics #61

Closed korymath closed 3 years ago

korymath commented 4 years ago

Duplicate with standard test runners:

coverage run -m pytest; coverage html
_____________________________________________________________________ TestTalkGenerator.test_multiple_topics ______________________________________________________________________

self = <tests.test_talkgenerator.TestTalkGenerator testMethod=test_multiple_topics>

    def test_multiple_topics(self):
        self.default_args.configure_mock(topic="cat, dog, bread, house")
        self.default_args.configure_mock(num_slides=6)
        ppt, slide_deck, location = generator.generate_presentation_using_cli_arguments(
>           self.default_args
        )

tests/test_talkgenerator.py:63:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
talkgenerator/generator.py:44: in generate_presentation_using_cli_arguments
    open_ppt=args.open_ppt,
talkgenerator/generator.py:94: in generate_presentation
    save_ppt=save_ppt,
talkgenerator/schema/presentation_schema.py:109: in generate_presentation
    slide_deck.save_to_powerpoint(presentation)
talkgenerator/slide/slide_deck.py:29: in save_to_powerpoint
    return [slide.create_powerpoint_slide(prs_template) for slide in self._slides]
talkgenerator/slide/slide_deck.py:29: in <listcomp>
    return [slide.create_powerpoint_slide(prs_template) for slide in self._slides]
talkgenerator/slide/slides.py:30: in create_powerpoint_slide
    ppt_slide = self._ppt_slide_creator(prs, **self._arguments)
talkgenerator/slide/powerpoint_slide_creator.py:257: in create_two_column_images_slide
    _add_image_or_text(slide, 14, image_or_text_2, original_image_size)
talkgenerator/slide/powerpoint_slide_creator.py:179: in _add_image_or_text
    return _add_image(slide, placeholder_id, image_url_or_text, original_image_size)
talkgenerator/slide/powerpoint_slide_creator.py:129: in _add_image
    width, height = image_ref.image().size
talkgenerator/slide/powerpoint_slide_creator.py:71: in image
    return Image.open(self.get_bytes_io())
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

fp = <_io.BytesIO object at 0x125b5d308>, mode = 'r'

    def open(fp, mode="r"):
        """
        Opens and identifies the given image file.

        This is a lazy operation; this function identifies the file, but
        the file remains open and the actual image data is not read from
        the file until you try to process the data (or call the
        :py:meth:`~PIL.Image.Image.load` method).  See
        :py:func:`~PIL.Image.new`. See :ref:`file-handling`.

        :param fp: A filename (string), pathlib.Path object or a file object.
           The file object must implement :py:meth:`~file.read`,
           :py:meth:`~file.seek`, and :py:meth:`~file.tell` methods,
           and be opened in binary mode.
        :param mode: The mode.  If given, this argument must be "r".
        :returns: An :py:class:`~PIL.Image.Image` object.
        :exception FileNotFoundError: If the file cannot be found.
        :exception PIL.UnidentifiedImageError: If the image cannot be opened and
           identified.
        :exception ValueError: If the ``mode`` is not "r", or if a ``StringIO``
           instance is used for ``fp``.
        """

        if mode != "r":
            raise ValueError("bad mode %r" % mode)
        elif isinstance(fp, io.StringIO):
            raise ValueError(
                "StringIO cannot be used to open an image. "
                "Binary data must be used instead."
            )

        exclusive_fp = False
        filename = ""
        if isinstance(fp, Path):
            filename = str(fp.resolve())
        elif isPath(fp):
            filename = fp

        if filename:
            fp = builtins.open(filename, "rb")
            exclusive_fp = True

        try:
            fp.seek(0)
        except (AttributeError, io.UnsupportedOperation):
            fp = io.BytesIO(fp.read())
            exclusive_fp = True

        prefix = fp.read(16)

        preinit()

        accept_warnings = []

        def _open_core(fp, filename, prefix):
            for i in ID:
                try:
                    factory, accept = OPEN[i]
                    result = not accept or accept(prefix)
                    if type(result) in [str, bytes]:
                        accept_warnings.append(result)
                    elif result:
                        fp.seek(0)
                        im = factory(fp, filename)
                        _decompression_bomb_check(im.size)
                        return im
                except (SyntaxError, IndexError, TypeError, struct.error):
                    # Leave disabled by default, spams the logs with image
                    # opening failures that are entirely expected.
                    # logger.debug("", exc_info=True)
                    continue
                except BaseException:
                    if exclusive_fp:
                        fp.close()
                    raise
            return None

        im = _open_core(fp, filename, prefix)

        if im is None:
            if init():
                im = _open_core(fp, filename, prefix)

        if im:
            im._exclusive_fp = exclusive_fp
            return im

        if exclusive_fp:
            fp.close()
        for message in accept_warnings:
            warnings.warn(message)
        raise UnidentifiedImageError(
>           "cannot identify image file %r" % (filename if filename else fp)
        )
E       PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x125b5d308>

venv/lib/python3.6/site-packages/PIL/Image.py:2931: UnidentifiedImageError
korymath commented 4 years ago

Separated the test into it's own file for fast running:

coverage run -m pytest tests/test_talkgenerator_multipletopics.py; coverage html
korymath commented 3 years ago

No longer an issue.