Example #1
0
def extract_VOP_test():  #XXX move if/when pushed to superclass
    block = Image.new("RGB", (100, 100), "#fff")
    ImageDraw.Draw(block).rectangle((20, 20, 60, 60), fill="#000")
    concho, all = CONCHO((0, 0, 100, 100, "prop", "description",
                          (20, 20, "vop", True, False, False)))
    hb = hart_ballot.HartBallot
    ballot = hb.__new__(hb)
    ballot.extensions = NilXtnz()
    ballot.dpi = 100
    ballot.oval_size = (40, 40)
    ballot.vote_target_horiz_offset = 20  #???
    const.vote_intensity_threshold = 200
    const.dark_pixel_threshold = 741
    page = Ballot.Page(dpi=ballot.dpi, image=block)
    page.as_template("prec", concho)

    x, y, ss, im, v, w, a = ballot.extract_VOP(
        page,
        lambda *a: a,
        1.0,
        all[0],
    )
    assert x == 20
    assert y == 26  #includes crop offset
    assert v
    assert not w
    assert not a
Example #2
0
def CapturePageInfo_test():
    #create fake ballot image
    im = Image.new("RGB", (100, 400), "white")
    d = ImageDraw.Draw(im)
    #list of ul, ur for boxes to pepper im with
    boxes = [(10, 10), (10, 70), (40, 130), (30, 200), (10, 300)]
    for x, y in boxes:
        d.rectangle((x, y, x + 50, y + 50), "black")

    #define faux template
    chos = tuple(
        b + (str(i), True, False, False) for i, b in enumerate(boxes)
    )
    tmpl, all = CONCHO((0, 0, 200, 400, "prop", "contest uno") + chos)

    #construct page, dpi only used in ratio, hence 1 vs default 0
    page = Ballot.Page(dpi=1, image=im)
    page.as_template("precinct", tmpl)

    results = ShillBallot().CapturePageInfo(page)

    assert concho_vs_vd(all, results)

    for ret in results:
        # getcolors returns None if there are more than the specifed colors
        # so we're verifying the monochromicity of the crops
        assert ret.image.getcolors(1) is not None