Exemple #1
0
    def test_ensure_file_exists(self):
        """download_utils.ensure_file: Check an existing file doesn't get overwritten"""

        os.makedirs(path.dirname(self.trace_file), exist_ok=True)
        self.trace_file.write("local")
        m = self.trace_file.mtime()
        download_utils.ensure_file(self.trace_path)
        TestDownloadUtils.check_same_file(self.trace_file, "local", m)
Exemple #2
0
    def test_ensure_file_exists_force_download(self):
        """download_utils.ensure_file: Check an existing file gets overwritten when forced"""

        OPTIONS.download['force'] = True
        os.makedirs(path.dirname(self.trace_file), exist_ok=True)
        self.trace_file.write("local")
        m = self.trace_file.mtime()
        download_utils.ensure_file(self.trace_path)
        TestDownloadUtils.check_same_file(self.trace_file, "remote")
Exemple #3
0
def _check_trace(trace_path, expected_checksum):
    ensure_file(trace_path)

    json_result = {}

    trace_dir = path.dirname(trace_path)
    dir_in_results = path.join('trace', OPTIONS.device_name, trace_dir)
    results_path = path.join(OPTIONS.results_path, dir_in_results)
    core.check_dir(results_path)

    checksum, image_file = _replay(path.join(OPTIONS.db_path, trace_path),
                                   results_path)

    print('[check_image]\n'
          '    actual: {}\n'
          '  expected: {}'.format(checksum or 'error', expected_checksum))

    json_result['images'] = [{
        'image_desc': trace_path,
        'image_ref': expected_checksum + '.png',
        'image_render': expected_checksum + '.png'
    }]

    if checksum is None:
        json_result['images'][0]['image_render'] = None
        return Result.FAILURE, json_result

    if checksum == expected_checksum:
        if not OPTIONS.keep_image:
            os.remove(image_file)
        print('[check_image] Images match for:\n  {}\n'.format(trace_path))
        result = Result.MATCH
    else:
        print('[check_image] Images differ for:\n  {}'.format(trace_path))
        print('[check_image] For more information see '
              'https://gitlab.freedesktop.org/'
              'mesa/piglit/blob/master/replayer/README.md\n')
        result = Result.DIFFER

    if result is not Result.MATCH or OPTIONS.keep_image:
        root, ext = path.splitext(image_file)
        image_file_dest = '{}-{}{}'.format(root, checksum, ext)
        shutil.move(image_file, image_file_dest)
        json_result['images'][0]['image_render'] = image_file_dest

    return result, json_result
Exemple #4
0
def _ensure_file(args):
    options.OPTIONS.set_download_url(args.download_url)
    options.OPTIONS.download['force'] = args.force_download
    options.OPTIONS.db_path = args.db_path

    return download_utils.ensure_file(args.file_path)
Exemple #5
0
    def test_ensure_file_not_exists_404(self, requests_mock):
        """download_utils.ensure_file: Check an exception raises when an URL returns a 404"""

        requests_mock.get(self.full_url, text='Not Found', status_code=404)
        assert not self.trace_file.check()
        download_utils.ensure_file(self.trace_path)
Exemple #6
0
    def test_ensure_file_not_exists_no_url(self):
        """download_utils.ensure_file: Check an exception raises when not passing an URL for a non existing file"""

        OPTIONS.set_download_url("")
        assert not self.trace_file.check()
        download_utils.ensure_file(self.trace_path)
Exemple #7
0
    def test_ensure_file_not_exists(self):
        """download_utils.ensure_file: Check a non existing file gets downloaded"""

        assert not self.trace_file.check()
        download_utils.ensure_file(self.trace_path)
        TestDownloadUtils.check_same_file(self.trace_file, "remote")
Exemple #8
0
    def test_ensure_file_not_exists_timeout(self, requests_mock):
        """download_utils.ensure_file: Check an exception raises when an URL returns a Connect Timeout"""

        requests_mock.get(self.full_url, exc=requests.exceptions.ConnectTimeout)
        assert not self.trace_file.check()
        download_utils.ensure_file(self.trace_path)