示例#1
0
def test_load_sprite_table_exceptions_1():
    """
    Test that exceptions are thrown as appropriate if bitmap_font is asked to
    load from a sprite table from a filename that does not exist, is not a
    PIL.Image file, or is damaged.
    """
    with pytest.raises(FileNotFoundError) as ex:
        filename = 'badfile'
        bitmap_font.load_sprite_table(filename, range(16, 256), 5, (5, 8), (5, 8), FONTDATA['mappings'][1])
    assert ex.value.filename == filename
示例#2
0
def test_load_sprite_table_exceptions_2():
    """
    Test that exceptions are thrown as appropriate if bitmap_font is asked to
    load from a sprite table from a filename that does not exist, is not a
    PIL.Image file, or is damaged.
    """
    with pytest.raises(ValueError) as ex:
        filename = get_reference_file(Path('font').joinpath('hd44780a02.pil'))
        bitmap_font.load_sprite_table(filename, range(16, 256), 5, (5, 8), (5, 8), FONTDATA['mappings'][1])
    assert str(ex.value) == f'File {filename} not a valid sprite table'

    with pytest.raises(ValueError) as ex:
        bitmap_font.load_sprite_table(1, range(16, 256), 5, (5, 8), (5, 8), FONTDATA['mappings'][1])
    assert str(ex.value) == 'Provided image is not an instance of PIL.Image'
示例#3
0
def test_load_sprite_table():
    """
    Test loading a font from a sprite_table
    """
    fnt = get_reference_pillow_font('hd44780a02.pil')
    filename = get_reference_file(Path('font').joinpath('hd44780a02.pbm'))
    bmf = bitmap_font.load_sprite_table(filename, range(16, 256), 5, (5, 8), (5, 8), FONTDATA['mappings'][1])

    img1 = make_sprite_table(fnt)
    img2 = make_sprite_table(bmf)

    assert img1 == img2
示例#4
0
def test_load_sprite_table_exceptions():
    """
    Test that exceptions are thrown as appropriate if bitmap_font is asked to
    load from a sprite table from a filename that does not exist, is not a
    PIL.Image file, or is damaged.
    """
    with pytest.raises(FileNotFoundError) as ex:
        filename = 'badfile'
        bitmap_font.load_sprite_table(filename, range(16, 256), 5, (5, 8),
                                      (5, 8), FONTDATA['mappings'][1])
    assert str(
        ex.value) == '[Errno 2] No such file or directory: \'{0}\''.format(
            filename)

    with pytest.raises(ValueError) as ex:
        filename = get_reference_file(os.path.join('font', 'hd44780a02.pil'))
        bitmap_font.load_sprite_table(filename, range(16, 256), 5, (5, 8),
                                      (5, 8), FONTDATA['mappings'][1])
    assert str(
        ex.value) == 'File {0} not a valid sprite table'.format(filename)

    with pytest.raises(ValueError) as ex:
        bitmap_font.load_sprite_table(1, range(16, 256), 5, (5, 8), (5, 8),
                                      FONTDATA['mappings'][1])
    assert str(ex.value) == 'Provided image is not an instance of PIL.Image'
示例#5
0
def bm_font(request):
    """
    Fixture which loads a ``bitmap_font`` persists it to disk
    The fixture removes the file when it is finished.
    """
    filename = get_reference_file(Path('font').joinpath('hd44780a02.pbm'))
    bmf = bitmap_font.load_sprite_table(filename, range(16, 256), 5, (5, 8),
        (5, 8), FONTDATA['mappings'][1])
    bmf.save('test.bmf')

    def tear_down():
        os.remove('test.bmf')
    request.addfinalizer(tear_down)

    return bmf
示例#6
0
def load_all_embedded(request):
    """
    Fixture which loads the two fonts contained within the test FONTDATA information
    """
    fnt_cnt = len(FONTDATA['metrics'])
    bmfs = [None] * fnt_cnt

    for i in range(fnt_cnt):
        m = FONTDATA['metrics'][i]
        sp_data = FONTDATA['fonts'][i]
        mappings = FONTDATA['mappings'][i]
        sprite_table = Image.frombytes('1', m['table_size'], sp_data)
        bmfs[i] = bitmap_font.load_sprite_table(sprite_table, m['index'], m['xwidth'],
            m['glyph_size'], m['cell_size'], mappings)
        sprite_table.close()
    return bmfs