示例#1
0
def run_task(body):
    data = json.loads(body, encoding='utf-8')
    snapshot_id = data['id']
    source_location = data['sourceLocation']
    organization_id = data['organizationId']
    project_id = data['projectId']
    build_id = data['buildId']
    title = data['title']
    width = data['width']
    browser = data['browser']
    selector = data.get('selector', None)
    hide_selectors = data.get('hideSelectors', None)
    compare_snapshot = data.get('compareSnapshot', None)
    flake_sha_list = data.get('flakeShas', [])

    save_snapshot = compare_snapshot == None

    snapshop_image, image_location = render_snapshot(
        source_location,
        organization_id,
        project_id,
        build_id,
        title,
        width,
        browser,
        selector,
        hide_selectors,
        save_snapshot
    )
    message = {
        'id': data['id'],
    }
    if data.get('compareSnapshot'):
        diff_location, difference, image_location, diff_sha, flake_matched = diff_snapshot(
            snapshop_image,
            organization_id,
            project_id,
            build_id,
            browser,
            title,
            width,
            compare_snapshot,
            flake_sha_list,
            True
        )
        if not flake_matched:
            message['diffLocation'] = diff_location
            message['differenceAmount'] = str(difference)

        message['diffSha'] = diff_sha
        message['difference'] = not flake_matched and difference > 0.1
        message['flakeMatched'] = flake_matched

    message['imageLocation'] = image_location
    send_message(message)
示例#2
0
 def test_diff(self, get_sha1_mock, uuid_mock, upload_file_mock,
               get_file_mock, compare_mock):
     compare_mock.return_value = [b'', 0, 0]
     uuid_mock.return_value = Mock(hex="1234")
     diff_location, difference, image_location, diff_hash, flake_matched = diff.diff_snapshot(
         io.BytesIO(), 'organization_id', 'project_id', 'build_id',
         'browser', 'title', 1280, 'http://path/to/compare/snapshot', [])
     assert difference == 0
     assert image_location == 'http://path/to/compare/snapshot'
     assert compare_mock.called
     assert get_file_mock.called
     assert not upload_file_mock.called
     assert not get_sha1_mock.called
示例#3
0
 def test_snapshot_saved(self, get_sha1_mock, uuid_mock, upload_file_mock,
                         get_file_mock, compare_mock):
     get_file_mock.return_value = b''
     compare_mock.return_value = [b'', 0.2, 0.02]
     uuid_mock.return_value = Mock(hex="1234")
     get_sha1_mock.return_value = '1234ea'
     diff_location, difference, image_location, diff_hash, flake_matched = diff.diff_snapshot(
         io.BytesIO(), 'organization_id', 'project_id', 'build_id',
         'browser', 'title', 1280, 'http://path/to/compare/snapshot', [],
         True)
     assert image_location != 'http://path/to/compare/snapshot'
     assert flake_matched == False
     assert get_file_mock.called
     assert get_sha1_mock.called
     assert upload_file_mock.called
示例#4
0
文件: run.py 项目: timchunght/basset
def run_task(snapshot_id, organization_id, project_id, build_id,
             source_location, title, width, browser, selector, hide_selectors,
             compare_snapshot):
    title = ' '.join(title)
    snapshop_image, image_location = render_snapshot(source_location,
                                                     organization_id,
                                                     project_id, build_id,
                                                     title, width, browser,
                                                     selector, hide_selectors)

    message = {'id': snapshot_id, 'imageLocation': image_location}
    if compare_snapshot:
        diff_location, difference, image_location, diff_sha, flake_matched = diff_snapshot(
            snapshop_image, organization_id, project_id, build_id, browser,
            width, [], compare_snapshot)
        message['diffLocation'] = diff_location
        message['difference'] = 0 if difference == 0 else difference

    send_message(message)
示例#5
0
文件: sqs.py 项目: timchunght/basset
        compare_snapshot = data.get('compareSnapshot', None)
        flake_sha_list = data.get('flakeShas', [])

        try:
            save_snapshot = compare_snapshot == None

            snapshop_image, image_location = render_snapshot(
                source_location, organization_id, project_id, build_id, title,
                width, browser, selector, hide_selectors, save_snapshot)

            message_data = {
                'id': snapshot_id,
            }
            if compare_snapshot:
                diff_location, difference, image_location, diff_hash, flake_matched = diff_snapshot(
                    snapshop_image, organization_id, project_id, build_id,
                    browser, title, width, compare_snapshot, flake_sha_list,
                    True)

                if not flake_matched:
                    message_data['diffLocation'] = diff_location
                    message_data['differenceAmount'] = str(difference)

                message_data['diffSha'] = diff_hash
                message_data[
                    'difference'] = not flake_matched and difference > 0.1
                message_data['flakeMatched'] = flake_matched

            message_data['imageLocation'] = image_location

            send_message(message_data)
示例#6
0
def process_message(body):
    data = json.loads(body, encoding='utf-8')
    id = data['id']
    source_location = data['sourceLocation']
    organization_id = data['organizationId']
    project_id = data['projectId']
    build_id = data['buildId']
    title = data['title']
    width = data['width']
    browser = data['browser']
    selector = data.get('selector', None)
    hide_selectors = data.get('hideSelectors', None)
    compare_snapshot = data.get('compareSnapshot', None)
    flake_sha_list = data.get('flakeShas', [])

    save_snapshot = compare_snapshot is None

    try:
        snapshot_image, image_location = render_snapshot(
            source_location, organization_id, project_id, build_id, title,
            width, browser, selector, hide_selectors, save_snapshot)
        message = {
            'id': id,
        }
        if compare_snapshot:
            diff_location, difference, image_location, diff_sha, flake_matched, centers = diff_snapshot(
                snapshot_image, organization_id, project_id, build_id, browser,
                title, width, compare_snapshot, flake_sha_list, True)
            if not flake_matched:
                message['diffLocation'] = diff_location
                message['differenceAmount'] = str(difference)

            message['diffSha'] = diff_sha
            message['difference'] = not flake_matched and difference > 0.1
            message['flakeMatched'] = flake_matched
            message['centers'] = centers

        message['imageLocation'] = image_location

        return message
    except Exception as ex:
        print(''.join(
            traceback.format_exception(etype=type(ex),
                                       value=ex,
                                       tb=ex.__traceback__)))
        print('There was an error trying to render the snapshot {}'.format(
            title))
        return None