# Path: luma/core/device.py
# class dummy(device):
#     """
#     Pseudo-device that acts like a physical display, except that it does nothing
#     other than retain a copy of the displayed image. It is mostly useful for
#     testing. Supports 24-bit color depth.
#     """
# 
#     def __init__(self, width=128, height=64, rotate=0, mode="RGB", **kwargs):
#         super(dummy, self).__init__(serial_interface=noop())
#         self.capabilities(width, height, rotate, mode)
#         self.image = None
# 
#     def display(self, image):
#         """
#         Takes a :py:mod:`PIL.Image` and makes a copy of it for later
#         use/inspection.
# 
#         :param image: Image to display.
#         :type image: PIL.Image.Image
#         """
#         assert image.size == self.size
# 
#         self.image = self.preprocess(image).copy()
# 
# Path: luma/core/virtual.py
# class sevensegment(object):
#     """
#     Abstraction that wraps a device, this class provides a ``text`` property
#     which can be used to set and get a text value, which when combined with a
#     ``segment_mapper`` sets the correct bit representation for seven-segment
#     displays and propagates that onto the underlying device.
# 
#     :param device: A device instance.
#     :param segment_mapper: An optional function that maps strings into the
#         correct representation for the 7-segment physical layout. If not
#         provided, the default mapper from compatible devices is used instead.
#     :param undefined: The default character to substitute when an unrenderable
#         character is supplied to the text property.
#     :type undefined: char
#     """
#     def __init__(self, device, undefined="_", segment_mapper=None):
#         self.device = device
#         self.undefined = undefined
#         self.segment_mapper = segment_mapper or device.segment_mapper
#         self._bufsize = device.width * device.height // 8
#         self.text = ""
# 
#     @property
#     def text(self):
#         """
#         Returns the current state of the text buffer. This may not reflect
#         accurately what is displayed on the seven-segment device, as certain
#         alpha-numerics and most punctuation cannot be rendered on the limited
#         display.
#         """
#         return self._text_buffer
# 
#     @text.setter
#     def text(self, value):
#         """
#         Updates the seven-segment display with the given value. If there is not
#         enough space to show the full text, an ``OverflowException`` is raised.
# 
#         :param value: The value to render onto the device. Any characters which
#             cannot be rendered will be converted into the ``undefined``
#             character supplied in the constructor.
#         :type value: str
#         """
#         self._text_buffer = observable(mutable_string(value),
#             observer=self._flush)
# 
#     def _flush(self, buf):
#         data = bytearray(self.segment_mapper(buf, notfound=self.undefined)
#             ).ljust(self._bufsize, b'\0')
# 
#         if len(data) > self._bufsize:
#             raise OverflowError(
#                 f"Device's capabilities insufficient for value '{buf}'")
# 
#         with canvas(self.device) as draw:
#             for x, byte in enumerate(reversed(data)):
#                 for y in range(8):
#                     if byte & 0x01:
#                         draw.point((x, y), fill="white")
#                     byte >>= 1


import pytest
from PIL import Image
from luma.core.device import dummy
from luma.core.virtual import sevensegment
from helpers import get_reference_image, assert_identical_image
    undefined = _DIGITS[notfound]
    iterator = iter(text)
    try:
        last = _DIGITS.get(next(iterator), undefined)
    except StopIteration:
        # Catch exception from next() in py3.7 and return normally
        return

    try:
        while True:
            curr = _DIGITS.get(next(iterator), undefined)

            if curr == 0x80:
                yield curr | last
            elif last != 0x80:
                yield last

            last = curr
    except StopIteration:
        if last != 0x80:
            yield last


def test_init():
    device = dummy(width=24, height=8, mode="1")
    sevensegment(device, segment_mapper=dot_muncher)
    assert device.image == Image.new("1", (24, 8))


def test_overflow():

# Path: luma/core/device.py
# class dummy(device):
#     """
#     Pseudo-device that acts like a physical display, except that it does nothing
#     other than retain a copy of the displayed image. It is mostly useful for
#     testing. Supports 24-bit color depth.
#     """
# 
#     def __init__(self, width=128, height=64, rotate=0, mode="RGB", **kwargs):
#         super(dummy, self).__init__(serial_interface=noop())
#         self.capabilities(width, height, rotate, mode)
#         self.image = None
# 
#     def display(self, image):
#         """
#         Takes a :py:mod:`PIL.Image` and makes a copy of it for later
#         use/inspection.
# 
#         :param image: Image to display.
#         :type image: PIL.Image.Image
#         """
#         assert image.size == self.size
# 
#         self.image = self.preprocess(image).copy()
# 
# Path: luma/core/virtual.py
# class sevensegment(object):
#     """
#     Abstraction that wraps a device, this class provides a ``text`` property
#     which can be used to set and get a text value, which when combined with a
#     ``segment_mapper`` sets the correct bit representation for seven-segment
#     displays and propagates that onto the underlying device.
# 
#     :param device: A device instance.
#     :param segment_mapper: An optional function that maps strings into the
#         correct representation for the 7-segment physical layout. If not
#         provided, the default mapper from compatible devices is used instead.
#     :param undefined: The default character to substitute when an unrenderable
#         character is supplied to the text property.
#     :type undefined: char
#     """
#     def __init__(self, device, undefined="_", segment_mapper=None):
#         self.device = device
#         self.undefined = undefined
#         self.segment_mapper = segment_mapper or device.segment_mapper
#         self._bufsize = device.width * device.height // 8
#         self.text = ""
# 
#     @property
#     def text(self):
#         """
#         Returns the current state of the text buffer. This may not reflect
#         accurately what is displayed on the seven-segment device, as certain
#         alpha-numerics and most punctuation cannot be rendered on the limited
#         display.
#         """
#         return self._text_buffer
# 
#     @text.setter
#     def text(self, value):
#         """
#         Updates the seven-segment display with the given value. If there is not
#         enough space to show the full text, an ``OverflowException`` is raised.
# 
#         :param value: The value to render onto the device. Any characters which
#             cannot be rendered will be converted into the ``undefined``
#             character supplied in the constructor.
#         :type value: str
#         """
#         self._text_buffer = observable(mutable_string(value),
#             observer=self._flush)
# 
#     def _flush(self, buf):
#         data = bytearray(self.segment_mapper(buf, notfound=self.undefined)
#             ).ljust(self._bufsize, b'\0')
# 
#         if len(data) > self._bufsize:
#             raise OverflowError(
#                 f"Device's capabilities insufficient for value '{buf}'")
# 
#         with canvas(self.device) as draw:
#             for x, byte in enumerate(reversed(data)):
#                 for y in range(8):
#                     if byte & 0x01:
#                         draw.point((x, y), fill="white")
#                     byte >>= 1


# Path: tests/test_sevensegment.py
import pytest
from PIL import Image
from luma.core.device import dummy
from luma.core.virtual import sevensegment
from helpers import get_reference_image, assert_identical_image

    undefined = _DIGITS[notfound]
    iterator = iter(text)
    try:
        last = _DIGITS.get(next(iterator), undefined)
    except StopIteration:
        # Catch exception from next() in py3.7 and return normally
        return

    try:
        while True:
            curr = _DIGITS.get(next(iterator), undefined)

            if curr == 0x80:
                yield curr | last
            elif last != 0x80:
                yield last

            last = curr
    except StopIteration:
        if last != 0x80:
            yield last


def test_init():
    device = dummy(width=24, height=8, mode="1")
    sevensegment(device, segment_mapper=dot_muncher)
    assert device.image == Image.new("1", (24, 8))


def test_overflow():

    device = dummy(width=24, height=8, mode="1")