Example #1
0
 def run_assertion(self):
   query_job = self._client.query(self._query)
   iterator = query_job.result(timeout=60)
   rows = list(iterator)
   if len(rows) != 1:
     raise run_tests_common.TestCaseFailure(
         'Expected one row in query result, got {} in test {}'.format(
             len(rows), self._test_name))
   row = rows[0]
   if len(self._expected_result) != len(row):
     raise run_tests_common.TestCaseFailure(
         'Expected {} columns in the query result, got {} in test {}'.format(
             len(self._expected_result), len(row), self._test_name))
   for key in self._expected_result.keys():
     if self._expected_result[key] != row.get(key):
       raise run_tests_common.TestCaseFailure(
           'Column {} mismatch: expected {}, got {} in test {}'.format(
               key, self._expected_result[key], row.get(key), self._test_name))
    def run_assertion(self):
        query_job = self._client.query(self._query)
        num_retries = 0
        while True:
            try:
                results = query_job.result(timeout=300)
            except ConcurrentTimeoutError as e:
                print('WARNING: Time out waiting for query: {}'.format(
                    self._query))
                if num_retries < _NUM_QUERY_RETIRES:
                    num_retries += 1
                    time.sleep(90)
                else:
                    raise e
            else:
                if results.total_rows == 1:
                    break
                print('ERROR: Query `{}` did not return expected num rows: {}'.
                      format(self._query, results.total_rows))
                if num_retries < _NUM_QUERY_RETIRES:
                    num_retries += 1
                    time.sleep(90)
                else:
                    raise run_tests_common.TestCaseFailure(
                        'Expected 1 row query results instead got {} in test {}'
                        .format(results.total_rows, self._test_name))

        row = list(results)[0]
        col_names = list(row.keys())
        if set(self._expected_result.keys()) != set(col_names):
            raise run_tests_common.TestCaseFailure(
                'Expected {} columns in the query result, got {} in test {}'.
                format(list(self._expected_result.keys()), col_names,
                       self._test_name))
        for key in self._expected_result.keys():
            if self._expected_result.get(key) != row.get(key):
                raise run_tests_common.TestCaseFailure(
                    'Column {} mismatch: expected {}, got {} in test {}'.
                    format(key, self._expected_result[key], row.get(key),
                           self._test_name))
  def validate_result(self):
    """Validates the results.

    - Checks that the VCF file is generated.
    - Validates VCF contents are the same as expected.
    """
    if not filesystems.FileSystems.exists(self._output_file):
      raise run_tests_common.TestCaseFailure(
          'The VCF is not generated in {} in test {}'.format(self._output_file,
                                                             self._name))
    lines = filesystems.FileSystems.open(self._output_file).readlines()
    expected_lines = filesystems.FileSystems.open(
        self._expected_output_file).readlines()
    if len(lines) != len(expected_lines):
      raise run_tests_common.TestCaseFailure(
          'Expected {} lines for file {} , got {} in test {}'.format(
              len(expected_lines), self._output_file, len(lines), self._name))
    for line, expected_line in zip(lines, expected_lines):
      if line != expected_line:
        raise run_tests_common.TestCaseFailure(
            'The contents of the VCF generated in {} in test {} is different '
            'from the expected: {} vs {}'.format(
                self._output_file, self._name, line, expected_line))