Example #1
0
def check_size(backend, bbox):
#    BackendLoader().force(backend)

    for childprocess in [0, 1]:
        im = pyscreenshot.grab(
            bbox=bbox,
            backend=backend,
            childprocess=childprocess,
        )
        img_debug(im, backend + str(bbox))

        if bbox:
            width = bbox[2] - bbox[0]
            height = bbox[3] - bbox[1]
        else:
            width, height = display_size()

        eq_(width, im.size[0])
        eq_(height, im.size[1])

        # it fails sometimes
        # eq_('RGB', im.mode, 'wrong mode! %s' % (backend))

        f = tempfile.NamedTemporaryFile(
            suffix='.png', prefix='pyscreenshot_test_')
        filename = f.name
        pyscreenshot.grab_to_file(
            backend=backend,
            childprocess=childprocess,
            filename=filename,
        )
Example #2
0
def check_size(backend, bbox, childprocess=True):
    im = pyscreenshot.grab(bbox=bbox, backend=backend, childprocess=childprocess,)
    img_debug(im, str(backend) + str(bbox))

    if bbox:
        width = bbox[2] - bbox[0]
        height = bbox[3] - bbox[1]
    else:
        width, height = display_size()
    if width and height:
        assert width == im.size[0]
        assert height == im.size[1]
Example #3
0
def check_size(backend, bbox):
    BackendLoader().force(backend)

    im = pyscreenshot.grab(bbox=bbox)
    img_debug(im, backend + str(bbox))

    if bbox:
        width = bbox[2] - bbox[0]
        height = bbox[3] - bbox[1]
    else:
        width, height = display_size()

    eq_(width, im.size[0], 'wrong width! %s' % (backend))
    eq_(height, im.size[1], 'wrong height! %s' % (backend))
Example #4
0
def check_size(backend, bbox):
    BackendLoader().force(backend)

    im = pyscreenshot.grab(bbox=bbox)
    img_debug(im, backend + str(bbox))

    if bbox:
        width = bbox[2] - bbox[0]
        height = bbox[3] - bbox[1]
    else:
        width, height = display_size()

    eq_(width, im.size[0], 'wrong width! %s' % (backend))
    eq_(height, im.size[1], 'wrong height! %s' % (backend))
Example #5
0
def check_size(backend, bbox):
    for childprocess in [True]:
        im = pyscreenshot.grab(
            bbox=bbox,
            backend=backend,
            childprocess=childprocess,
        )
        img_debug(im, backend + str(bbox))

        if bbox:
            width = bbox[2] - bbox[0]
            height = bbox[3] - bbox[1]
        else:
            width, height = display_size()

        eq_(width, im.size[0])
        eq_(height, im.size[1])
Example #6
0
def check_size(backend, bbox):
    for childprocess in [True]:
        im = pyscreenshot.grab(
            bbox=bbox,
            backend=backend,
            childprocess=childprocess,
        )
        img_debug(im, backend + str(bbox))

        if bbox:
            width = bbox[2] - bbox[0]
            height = bbox[3] - bbox[1]
        else:
            width, height = display_size()

        eq_(width, im.size[0])
        eq_(height, im.size[1])
Example #7
0
def check_ref(backend, bbox, childprocess, refimgpath):
    img_ref = Image.open(refimgpath)
    if bbox:
        img_ref = img_ref.crop(bbox)

    im = pyscreenshot.grab(bbox=bbox,
                           backend=backend,
                           childprocess=childprocess)

    img_ref = img_ref.convert("RGB")
    im = im.convert("RGB")

    eq_("RGB", img_ref.mode)
    eq_("RGB", im.mode)

    img_debug(img_ref, "ref" + str(bbox))
    img_debug(im, str(backend) + str(bbox))

    img_diff = ImageChops.difference(img_ref, im)
    ex = img_diff.getextrema()
    logging.debug("diff getextrema: %s", ex)
    diff_bbox = img_diff.getbbox()
    if diff_bbox:
        img_debug(img_diff, "img_diff" + str(diff_bbox))
    eq_(
        diff_bbox,
        None,
        "different image data %s bbox=%s extrema:%s diff_bbox=%s" %
        (backend, bbox, ex, diff_bbox),
    )
Example #8
0
def check_ref(backend, bbox):
        # some tests fail -> disable
    return

    img_ref = pyscreenshot.grab(bbox=bbox, backend=ref)
    img_debug(img_ref, ref + str(bbox))

    im = pyscreenshot.grab(bbox=bbox, backend=backend)
    img_debug(im, backend + str(bbox))

    eq_('RGB', img_ref.mode)
    eq_('RGB', im.mode)

    img_diff = ImageChops.difference(img_ref, im)
    bbox = img_diff.getbbox()
    if bbox:
        img_debug(img_diff, 'img_diff' + str(bbox))
    eq_(bbox, None, 'different image data %s!=%s bbox=%s' % (ref,
        backend, bbox))
Example #9
0
def check_ref(backend, bbox):
    ref = 'scrot'
    img_ref = pyscreenshot.grab(bbox=bbox, backend=ref, childprocess=True)
    im = pyscreenshot.grab(bbox=bbox, backend=backend, childprocess=True)

    img_ref = img_ref.convert('RGB')
    im = im.convert('RGB')

    eq_('RGB', img_ref.mode)
    eq_('RGB', im.mode)

    img_debug(img_ref, ref + str(bbox))
    img_debug(im, backend + str(bbox))

    img_diff = ImageChops.difference(img_ref, im)
    bbox = img_diff.getbbox()
    if bbox:
        img_debug(img_diff, 'img_diff' + str(bbox))
    eq_(bbox, None, 'different image data %s!=%s bbox=%s' %
        (ref,        backend, bbox))
Example #10
0
def check_ref(backend, bbox):
    ref = 'scrot'
    img_ref = pyscreenshot.grab(bbox=bbox, backend=ref, childprocess=True)
    im = pyscreenshot.grab(bbox=bbox, backend=backend, childprocess=True)

    img_ref = img_ref.convert('RGB')
    im = im.convert('RGB')

    eq_('RGB', img_ref.mode)
    eq_('RGB', im.mode)

    img_debug(img_ref, ref + str(bbox))
    img_debug(im, backend + str(bbox))

    img_diff = ImageChops.difference(img_ref, im)
    bbox = img_diff.getbbox()
    if bbox:
        img_debug(img_diff, 'img_diff' + str(bbox))
    eq_(bbox, None, 'different image data %s!=%s bbox=%s' %
        (ref,        backend, bbox))
Example #11
0
def check_ref(backend, bbox):
        # some tests fail -> disable
    return

    BackendLoader().force(ref)
    img_ref = pyscreenshot.grab(bbox=bbox)
    img_debug(img_ref, ref + str(bbox))

    BackendLoader().force(backend)
    im = pyscreenshot.grab(bbox=bbox)
    img_debug(im, backend + str(bbox))

    eq_('RGB', img_ref.mode)
    eq_('RGB', im.mode)

    img_diff = ImageChops.difference(img_ref, im)
    bbox = img_diff.getbbox()
    if bbox:
        img_debug(img_diff, 'img_diff' + str(bbox))
    eq_(bbox, None, 'different image data %s!=%s bbox=%s' % (ref,
        backend, bbox))
Example #12
0
def check_ref(backend, bbox, childprocess, refimgpath):
    img_ref = Image.open(refimgpath)
    logging.debug("ref full getextrema: %s", img_ref.getextrema())
    if bbox:
        img_ref = img_ref.crop(bbox)

    im = pyscreenshot.grab(bbox=bbox,
                           backend=backend,
                           childprocess=childprocess)

    img_ref = img_ref.convert("RGB")
    logging.debug("ref  getextrema: %s", img_ref.getextrema())
    im = im.convert("RGB")
    logging.debug("shot getextrema: %s", im.getextrema())

    eq_("RGB", img_ref.mode)
    eq_("RGB", im.mode)

    img_debug(img_ref, "ref" + str(bbox))
    img_debug(im, str(backend) + str(bbox))

    img_diff = ImageChops.difference(img_ref, im)
    ex = img_diff.getextrema()
    logging.debug("diff getextrema: %s", ex)
    diff_bbox = img_diff.getbbox()
    if diff_bbox:
        img_debug(img_diff, "img_diff" + str(diff_bbox))
    if (platform_is_osx() and backend
            and backend in ["qtpy", "pyqt", "pyqt5", "pyside", "pyside2"]):
        # TODO: qt color problem on osx
        color_diff_max = max([b for (_, b) in ex])
        ok_(color_diff_max < 70)
    else:
        eq_(
            diff_bbox,
            None,
            "different image data %s bbox=%s extrema:%s diff_bbox=%s" %
            (backend, bbox, ex, diff_bbox),
        )
Example #13
0
def check_ref(backend, bbox, childprocess, refimgpath):
    img_ref = Image.open(refimgpath)
    logging.debug("ref full getextrema: %s", img_ref.getextrema())
    if bbox:
        img_ref = img_ref.crop(bbox)

    im = pyscreenshot.grab(bbox=bbox,
                           backend=backend,
                           childprocess=childprocess)

    img_ref = img_ref.convert("RGB")
    logging.debug("ref  getextrema: %s", img_ref.getextrema())
    im = im.convert("RGB")
    logging.debug("shot getextrema: %s", im.getextrema())

    assert "RGB" == img_ref.mode
    assert "RGB" == im.mode

    img_debug(img_ref, "ref" + str(bbox))
    img_debug(im, str(backend) + str(bbox))

    img_diff = ImageChops.difference(img_ref, im)
    ex = img_diff.getextrema()
    logging.debug("diff getextrema: %s", ex)
    diff_bbox = img_diff.getbbox()
    if diff_bbox:
        img_debug(img_diff, "img_diff" + str(diff_bbox))
    # if (
    #     platform_is_osx()
    #     and backend
    #     and backend in ["qtpy", "pyqt", "pyqt5", "pyside", "pyside2"]
    # ):
    #     color_diff_max = max([b for (_, b) in ex])
    #     assert color_diff_max < 70
    # else:
    if not diff_bbox is None:
        print("different image data %s bbox=%s extrema:%s diff_bbox=%s" %
              (backend, bbox, ex, diff_bbox))
    assert diff_bbox is None