def test_bit_image_black():
    """
    Test printing solid black bit image (raster)
    """
    instance = printer.Dummy()
    instance.image('test/resources/canvas_black.png', impl="bitImageRaster")
    assert (instance.output == b'\x1dv0\x00\x01\x00\x01\x00\x80')
    # Same thing w/ object created on the fly, rather than a filename
    instance = printer.Dummy()
    im = Image.new("RGB", (1, 1), (0, 0, 0))
    instance.image(im, impl="bitImageRaster")
    assert (instance.output == b'\x1dv0\x00\x01\x00\x01\x00\x80')
def test_model():
    """Test QR model"""
    instance = printer.Dummy()
    instance.qr("1234", native=True, model=QR_MODEL_1)
    expected = b'\x1d(k\x04\x001A1\x00\x1d(k\x03\x001C\x03\x1d(k\x03\x001E0\x1d' \
        b'(k\x07\x001P01234\x1d(k\x03\x001Q0'
    assert(instance.output == expected)
def test_bit_image_transparent():
    """
    Test printing black/transparent bit image (raster)
    """
    instance = printer.Dummy()
    instance.image("test/resources/black_transparent.png", impl="bitImageRaster")
    assert instance.output == b"\x1dv0\x00\x01\x00\x02\x00\xc0\x00"
def test_bit_image_both():
    """
    Test printing black/white bit image (raster)
    """
    instance = printer.Dummy()
    instance.image('test/resources/black_white.png', impl="bitImageRaster")
    assert (instance.output == b'\x1dv0\x00\x01\x00\x02\x00\xc0\x00')
def test_bit_image_colfmt_black():
    """
    Test printing solid black bit image (column format)
    """
    instance = printer.Dummy()
    instance.image("test/resources/canvas_black.png", impl="bitImageColumn")
    assert instance.output == b"\x1b3\x10\x1b*!\x01\x00\x80\x00\x00\x0a\x1b2"
def test_bit_image_colfmt_white():
    """
    Test printing solid white bit image (column format)
    """
    instance = printer.Dummy()
    instance.image('test/resources/canvas_white.png', impl="bitImageColumn")
    assert (instance.output == b'\x1b3\x10\x1b*!\x01\x00\x00\x00\x00\x0a\x1b2')
示例#7
0
def testCutPaper():
    p = printer.Dummy()
    p.cut()
    if str(p.output) != r"b'\n\n\n\n\n\n\x1dV\x00'":
        raise escpos.Error(
            "Could not successfully complete dummy cut or produced incorrect output on dummy cut"
        )
def test_defaults():
    """Test QR code with defaults"""
    instance = printer.Dummy()
    instance.qr("1234", native=True)
    expected = b'\x1d(k\x04\x001A2\x00\x1d(k\x03\x001C\x03\x1d(k\x03\x001E0\x1d' \
        b'(k\x07\x001P01234\x1d(k\x03\x001Q0'
    assert(instance.output == expected)
def test_graphics_black():
    """
    Test printing solid black graphics
    """
    instance = printer.Dummy()
    instance.image('test/resources/canvas_black.png', impl="graphics")
    assert(instance.output == b'\x1d(L\x0b\x000p0\x01\x011\x01\x00\x01\x00\x80\x1d(L\x02\x0002')
def test_ec():
    """Test QR error correction setting"""
    instance = printer.Dummy()
    instance.qr("1234", native=True, ec=QR_ECLEVEL_H)
    expected = b'\x1d(k\x04\x001A2\x00\x1d(k\x03\x001C\x03\x1d(k\x03\x001E3\x1d' \
        b'(k\x07\x001P01234\x1d(k\x03\x001Q0'
    assert(instance.output == expected)
def test_size():
    """Test QR box size"""
    instance = printer.Dummy()
    instance.qr("1234", native=True, size=7)
    expected = b'\x1d(k\x04\x001A2\x00\x1d(k\x03\x001C\x07\x1d(k\x03\x001E0\x1d' \
        b'(k\x07\x001P01234\x1d(k\x03\x001Q0'
    assert(instance.output == expected)
def test_bit_image_colfmt_transparent():
    """
    Test printing black/transparent bit image (column format)
    """
    instance = printer.Dummy()
    instance.image('test/resources/black_transparent.png', impl="bitImageColumn")
    assert(instance.output == b'\x1b3\x10\x1b*!\x02\x00\x80\x00\x00\x80\x00\x00\x0a\x1b2')
def test_graphics_transparent():
    """
    Test printing black/transparent graphics
    """
    instance = printer.Dummy()
    instance.image('test/resources/black_transparent.png', impl="graphics")
    assert(instance.output == b'\x1d(L\x0c\x000p0\x01\x011\x02\x00\x02\x00\xc0\x00\x1d(L\x02\x0002')
def test_large_graphics():
    """
    Test whether 'large' graphics that induce a fragmentation are handled correctly.
    """
    instance = printer.Dummy()
    instance.image('test/resources/black_white.png', impl="bitImageRaster", fragment_height=1)
    assert(instance.output == b'\x1dv0\x00\x01\x00\x01\x00\xc0\x1dv0\x00\x01\x00\x01\x00\x00')
def test_raise_CashDrawerError():
    """should raise an error if the sequence is invalid.
    """
    instance = printer.Dummy()
    with pytest.raises(CashDrawerError):
        # call with sequence that is too long
        instance.cashdraw([1, 1, 1, 1, 1, 1])
def test_code_check(bctype, data):
    """should raise an error if the barcode code is invalid."""
    instance = printer.Dummy()
    with pytest.raises(BarcodeCodeError):
        instance.barcode(data, bctype)

    assert instance.output == b""
def test_bit_image_white():
    """
    Test printing solid white bit image (raster)
    """
    instance = printer.Dummy()
    instance.image('test/resources/canvas_white.png', impl="bitImageRaster")
    assert (instance.output == b'\x1dv0\x00\x01\x00\x01\x00\x00')
示例#18
0
def testPrintText():
    p = printer.Dummy()
    p.text("Test print")
    if str(p.output) != r"b'Test print'":
        raise escpos.Error(
            "Could not successfully complete dummy print of text or produced incorrect output on dummy print"
        )
def test_lacks_support(bctype, supports_b):
    """should raise an error if the barcode type is not supported."""
    profile = Profile(features={BARCODE_B: supports_b})
    instance = printer.Dummy(profile=profile)
    with pytest.raises(BarcodeTypeError):
        instance.barcode("test", bctype)

    assert instance.output == b""
def test_bit_image_colfmt_both():
    """
    Test printing black/white bit image (column format)
    """
    instance = printer.Dummy()
    instance.image("test/resources/black_white.png", impl="bitImageColumn")
    assert (
        instance.output == b"\x1b3\x10\x1b*!\x02\x00\x80\x00\x00\x80\x00\x00\x0a\x1b2"
    )
示例#21
0
def testSetFont():
    p = printer.Dummy()
    p.set("LEFT", "B", "B", 2, 2)
    if str(
            p.output
    ) != r"b'\x1b!\x00\x1b!0\x1b{\x00\x1db\x00\x1bE\x01\x1b-\x00\x1bM\x01\x1ba\x00\x1dB\x00'":
        raise escpos.Error(
            "Could not successfully complete dummy setting of font or produced incorrect output on dummy set"
        )
示例#22
0
def test_image():
    """Test QR as image"""
    instance = printer.Dummy()
    instance.qr("1", native=False, size=1)
    print(instance.output)
    expected = b'\x1dv0\x00\x03\x00\x17\x00\x00\x00\x00\x7f]\xfcA\x19\x04]it]et' \
        b']ItA=\x04\x7fU\xfc\x00\x0c\x00y~t4\x7f =\xa84j\xd9\xf0\x05\xd4\x90\x00' \
        b'i(\x7f<\xa8A \xd8]\'\xc4]y\xf8]E\x80Ar\x94\x7fR@\x00\x00\x00'
    assert (instance.output == expected)
def test_graphics_white():
    """
    Test printing solid white graphics
    """
    instance = printer.Dummy()
    instance.image("test/resources/canvas_white.png", impl="graphics")
    assert (
        instance.output
        == b"\x1d(L\x0b\x000p0\x01\x011\x01\x00\x01\x00\x00\x1d(L\x02\x0002"
    )
def test_graphics_both():
    """
    Test printing black/white graphics
    """
    instance = printer.Dummy()
    instance.image("test/resources/black_white.png", impl="graphics")
    assert (
        instance.output
        == b"\x1d(L\x0c\x000p0\x01\x011\x02\x00\x02\x00\xc0\x00\x1d(L\x02\x0002"
    )
def dummy_with_width():
    instance = printer.Dummy()
    instance.profile.profile_data = {
        'media': {
            'width': {
                'pixels': 384
            }
        }
    }
    return instance
def test_width_too_large():
    """
    Test printing an image that is too large in width.
    """
    instance = printer.Dummy()
    instance.profile.profile_data = {'media': {'width': {'pixels': 384}}}

    with pytest.raises(ImageWidthError):
        instance.image(Image.new("RGB", (385, 200)))

    instance.image(Image.new("RGB", (384, 200)))
示例#27
0
def testPrintImage():
    p = printer.Dummy()
    p.image(
        os.path.join(
            os.path.realpath('resources/plugins/weather/images') +
            os.path.sep + "cloudy.png"))
    if str(
            p.output
    ) != r"b'\x1dv0\x00\t\x006\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x0f\xfc\x00\x00\x00\x00\x00\x00\x00?\xff\x00\x00\x00\x00\x00\x00\x00\xff\xff\xc0\x00\x00\x00\x00\x00\x01\xfe\xbf\xe0\x00\x00\x00\x00\x00\x03\xf0\x03\xf0\x00\x00\x00\x00\x00/\xe0\x01\xfe\x80\x00\x00\x00\x01\xff\x80\x00\x7f\xe0\x00\x00\x00\x03\xff\x00\x00\x7f\xf0\x00\x00\x00\x0f\xff\x00\x00?\xfc\x00\x00\x00\x0f\xc4\x00\x00\x01|\x00\x00\x00\x1f\x02\xa0\x00\x00>\x00\x00\x00>?\xfe\x00\x00\x1f\x00\x00\x00<\xff\xff\xc0\x00\x0f\x00\x00\x00}\xff\xff\xe0\x00\x0f\x80\x00\x00\x7f\xfd_\xf8\x00\x07\x80\x00\x00\x7f\xe0\x01\xfc\x00\x07\x80\x00\x00\x7f\x80\x00~\x00\x07\x80\x00\x00~\x00\x00?\x00\x07\x80\x00\x05|\x00\x00\x0f\xb4\x07\x80\x00?\xf8\x00\x00\x07\xff\x0f\x00\x00\xff\xf0\x00\x00\x07\xff\xdf\x00\x03\xff\xf0\x00\x00\x03\xff\xff\x00\x07\xfa\xa0\x00\x00\x01\xab\xfe\x00\x0f\xc0\x00\x00\x00\x00\x01\xfc\x00\x0f\x80\x00\x00\x00\x00\x00|\x00\x1e\x00\x00\x00\x00\x00\x00>\x00>\x00\x00\x00\x00\x00\x00\x1f\x00<\x00\x00\x00\x00\x00\x00\x0f\x00<\x00\x00\x00\x00\x00\x00\x0f\x00x\x00\x00\x00\x00\x00\x00\x07\x80x\x00\x00\x00\x00\x00\x00\x07\x80x\x00\x00\x00\x00\x00\x00\x07\x80x\x00\x00\x00\x00\x00\x00\x07\x80x\x00\x00\x00\x00\x00\x00\x07\x80x\x00\x00\x00\x00\x00\x00\x07\x80<\x00\x00\x00\x00\x00\x00\x0f\x00|\x00\x00\x00\x00\x00\x00\x0f\x00<\x00\x00\x00\x00\x00\x00\x0f\x00\x1e\x00\x00\x00\x00\x00\x00\x1e\x00\x1f\x00\x00\x00\x00\x00\x00>\x00\x0f\x80\x00\x00\x00\x00\x00|\x00\x0f\xe0\x1c\x00\x00\x0e\x01\xfc\x00\x07\xfe\xfe\x00\x00\x1f\xdf\xf0\x00\x01\xff\xff\x00\x00?\xff\xe0\x00\x00\xff\xff\x80\x00\xff\xff\xc0\x00\x00?\xef\xf0\x03\xfd\xfe\x00\x00\x00\x00\x07\xff\x7f\xf0\x00\x00\x00\x00\x00\x01\xff\xff\xe0\x00\x00\x00\x00\x00\x00\x7f\xff\x80\x00\x00\x00\x00\x00\x00\x1f\xfc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'":
        raise escpos.Error(
            "Could not successfully complete dummy print of image or produced incorrect output on dummy print"
        )
示例#28
0
def main():
    dummy = printer.Dummy()

    dummy.hw("init")

    for codepage in sys.argv[1:] or ["USA"]:
        dummy.set(height=2, width=2)
        dummy._raw(codepage + "\n\n\n")
        print_codepage(dummy, codepage)
        dummy._raw("\n\n")

    dummy.cut()

    print(dummy.output)
示例#29
0
def main():
    dummy = printer.Dummy()

    dummy.hw('init')

    for codepage in sys.argv[1:] or ['USA']:
        dummy.set(height=2, width=2)
        dummy.text(codepage + "\n\n\n")
        print_codepage(dummy, codepage)
        dummy.text("\n\n")

    dummy.cut()

    print dummy.output
示例#30
0
def get_printer(dummy=False):

    if dummy:
        return ep.Dummy()

    db = get_db()
    c = db.cursor()
    c.execute("select conf_value from printer_conf where conf_key='usb_major';")
    major = int(c.fetchone()[0], 16)

    c.execute("select conf_value from printer_conf where conf_key='usb_minor';")
    minor = int(c.fetchone()[0], 16)

    c.close()
    p = ep.Usb(major, minor)
    return p