Ejemplo n.º 1
0
def test_constructor_empty():
    test = image_parse.TextImage()
    # The image array should be full of 255s (blank pixels)
    assert all(test.image)
    # Even a blank image should have width and height
    assert test.height
    assert test.width
Ejemplo n.º 2
0
def test_crop_border_blank_image():
    path = "./screenshots/blank_image.png"
    img = image_parse.TextImage(path)
    orig_height, orig_width = img.height, img.width
    orig_rows, orig_cols = img.empty_rows, img.empty_cols
    image_parse.TextImage.crop_border(img)
    # A blank image doesn't have anything to crop
    assert_equals(img.height, orig_height)
    assert_equals(img.width, orig_width)
    assert_equals(img.empty_rows, orig_rows)
    assert_equals(img.empty_cols, orig_cols)
Ejemplo n.º 3
0
def test_crop_border_already_cropped():
    path = "./screenshots/utsubo_bw_cropped.png"
    img = image_parse.TextImage(path)
    orig_height, orig_width = img.height, img.width
    orig_rows, orig_cols = img.empty_rows, img.empty_cols
    image_parse.TextImage.crop_border(img)
    # A cropped image shouldn't be cropped further
    assert_equals(img.height, orig_height)
    assert_equals(img.width, orig_width)
    assert_equals(img.empty_rows, orig_rows)
    assert_equals(img.empty_cols, orig_cols)
Ejemplo n.º 4
0
def test_crop_border_no_space_vertical_false():
    path = "./screenshots/utsubo_bw.png"
    img = image_parse.TextImage(path)
    orig_height, orig_width = img.height, img.width
    orig_rows, orig_cols = img.empty_rows, img.empty_cols
    image_parse.TextImage.crop_border(img, crop_vertical=False)
    # Vertical values should be unchanged
    assert_equals(img.height, orig_height)
    assert_equals(img.empty_rows, orig_rows)
    # Horizontal values should be changed
    assert_less(img.width, orig_width)
    assert_not_equal(img.empty_cols, orig_cols)
Ejemplo n.º 5
0
def test_crop_border_no_space_vertical_true():
    path = "./screenshots/utsubo_bw.png"
    img = image_parse.TextImage(path)
    orig_height, orig_width = img.height, img.width
    orig_rows, orig_cols = img.empty_rows, img.empty_cols
    image_parse.TextImage.crop_border(img)
    # The specific values may change, but for this image, it should
    #   be cropped both horizontally and vertically, changing the size
    #   and removing some of the empty spaces.
    assert_less(img.height, orig_height)
    assert_less(img.width, orig_width)
    assert_not_equal(img.empty_rows, orig_rows)
    assert_not_equal(img.empty_cols, orig_cols)
Ejemplo n.º 6
0
def test_split_row_not_a_row():
    path = "./screenshots/123816.jpg"
    img = image_parse.TextImage(path)
    # Should return some images, but they are probably not characters
    assert image_parse.TextImage.split_row(img)
Ejemplo n.º 7
0
def test_split_row_valid_row():
    path = "./screenshots/utsubo_bw_cropped.png"
    img = image_parse.TextImage(path)
    result = image_parse.TextImage.split_row(img)
    assert len(result) > 1
Ejemplo n.º 8
0
def test_constructor_filepath_bw_inverted_image():
    path = "./screenshots/utsubo_bw2.png"
    img = image_parse.TextImage(path)
    assert img is not None
    assert len(img.image)
Ejemplo n.º 9
0
def test_split_row_single_character():
    path = "./screenshots/temp_chr.jpg"
    img = image_parse.TextImage(path)
    assert image_parse.TextImage.split_row(img)
Ejemplo n.º 10
0
def test_split_row_blank_image():
    path = "./screenshots/blank_image.png"
    img = image_parse.TextImage(path)
    assert_raises(IndexError, image_parse.TextImage.split_row, img)