def test_timeout_reset_after_call(self): old_timeout = socket.getdefaulttimeout() self.stub_urlopen_with_timeout_check(30, None, "url") try: socket.setdefaulttimeout(1234) utils.urlopen("url", timeout=30) self.assertEquals(1234, socket.getdefaulttimeout()) finally: socket.setdefaulttimeout(old_timeout)
def get_results(results_files): """ Download the results if needed. Return results of each run in a numerically-indexed dictionary of dictionaries keyed on testnames. Return dictionary keyed on unique testnames across all runs. """ r = re.compile('(\S+\s+\S+)\s+(\S+)\s+:') i = 0 runs = {} testnames = {} for file in results_files: runs[i] = {} try: fh = utils.urlopen(file) results = fh.readlines() fh.close() except Exception: print "ERROR: reading results resource [%s]" % (file) usage() for line in results: try: s = r.match(line) testname = s.group(1) status = s.group(2) runs[i][testname] = status testnames[testname] = 1 except Exception: pass i += 1 return (runs, testnames)
def get_results(results_files): """ Download the results if needed. Return results of each run in a numerically-indexed dictionary of dictionaries keyed on testnames. Return dictionary keyed on unique testnames across all runs. @param results_files: list of result-file names (or url locations). """ r = re.compile('(\S+\s+\S+)\s+(\S+)\s+:') i = 0 runs = {} testnames = {} for file in results_files: runs[i] = {} try: fh = utils.urlopen(file) results = fh.readlines() fh.close() except: print "ERROR: reading results resource [%s]" % (file) usage() for line in results: try: s = r.match(line) testname = s.group(1) status = s.group(2) runs[i][testname] = status testnames[testname] = 1 except: pass i += 1 return (runs, testnames)
def get_sheriffs(lab_only=False): """ Polls the javascript file that holds the identity of the sheriff and parses it's output to return a list of chromium sheriff email addresses. The javascript file can contain the ldap of more than one sheriff, eg: document.write('sheriff_one, sheriff_two'). @param lab_only: if True, only pulls lab sheriff. @return: A list of chroium.org sheriff email addresses to cc on the bug. An empty list if failed to parse the javascript. """ sheriff_ids = [] sheriff_js_list = _LAB_SHERIFF_JS.split(',') if not lab_only: sheriff_js_list.extend(_SHERIFF_JS.split(',')) for sheriff_js in sheriff_js_list: try: url_content = utils.urlopen('%s%s'% ( _CHROMIUM_BUILD_URL, sheriff_js)).read() except (ValueError, IOError) as e: logging.warning('could not parse sheriff from url %s%s: %s', _CHROMIUM_BUILD_URL, sheriff_js, str(e)) except (urllib2.URLError, httplib.HTTPException) as e: logging.warning('unexpected error reading from url "%s%s": %s', _CHROMIUM_BUILD_URL, sheriff_js, str(e)) else: ldaps = re.search(r"document.write\('(.*)'\)", url_content) if not ldaps: logging.warning('Could not retrieve sheriff ldaps for: %s', url_content) continue sheriff_ids += ['*****@*****.**' % alias.replace(' ', '') for alias in ldaps.group(1).split(',')] return sheriff_ids
def test_args_are_untouched(self): self.stub_urlopen_with_timeout_check(30, None, "http://url", "POST data") utils.urlopen("http://url", timeout=30, data="POST data")
def test_timeout_set_by_default(self): def test_func(timeout): self.assertTrue(timeout is not None) self.stub_urlopen_with_timeout_comparison(test_func, None, "url") utils.urlopen("url")
def test_timeout_set_during_call(self): self.stub_urlopen_with_timeout_check(30, "retval", "url") retval = utils.urlopen("url", timeout=30) self.assertEquals(retval, "retval")