def analyze_test(self, test_contents=None, ref_contents=None): """ Analyzes a file to determine if it's a test, what type of test, and what reference or support files it requires. Returns all of the test info """ test_info = None if test_contents is None and self.test_doc is None: return test_info if test_contents is not None: self.test_doc = Parser(test_contents) if ref_contents is not None: self.ref_doc = Parser(ref_contents) # First check if it's a reftest matches = self.reference_links_of_type( 'match') + self.reference_links_of_type('mismatch') if matches: if len(matches) > 1: print 'Warning: Webkit does not support multiple references. Importing the first ref defined in ' + self.filesystem.basename( self.filename) ref_file = self.filesystem.join( self.filesystem.dirname(self.filename), matches[0]['href']) if self.ref_doc is None: self.ref_doc = self.load_file(ref_file) test_info = {'test': self.filename, 'reference': ref_file} # If the ref file path is relative, we need to check it for # relative paths also because when it lands in WebKit, it will be # moved down into the test dir. # # Note: The test files themselves are not checked for support files # outside their directories as the convention in the CSSWG is to # put all support files in the same dir or subdir as the test. # # All non-test files in the test's directory tree are normally # copied as part of the import as they are assumed to be required # support files. # # *But*, there is exactly one case in the entire css2.1 suite where # at test depends on a file that lives in a different directory, # which depends on another file that lives outside of its # directory. This code covers that case :) if matches[0]['href'].startswith('..'): support_files = self.support_files(self.ref_doc) test_info['refsupport'] = support_files elif self.is_jstest(): test_info = {'test': self.filename, 'jstest': True} elif self.options['all'] is True and not ( '-ref' in self.filename) and not ('reference' in self.filename): test_info = {'test': self.filename} return test_info
def load_file(self, filename): if self.filesystem.isfile(filename): try: self.test_doc = Parser( self.filesystem.read_binary_file(filename)) except: # FIXME: Figure out what to do if we can't parse the file. _log.error("Failed to parse %s", filename) self.test_doc is None else: if self.filesystem.isdir(filename): # FIXME: Figure out what is triggering this and what to do about it. _log.error("Trying to load %s, which is a directory", filename) self.test_doc = None self.ref_doc = None
def analyze_test(self, test_contents=None, ref_contents=None): """ Analyzes a file to determine if it's a test, what type of test, and what reference or support files it requires. Returns all of the test info """ test_info = None if test_contents is None and self.test_doc is None: return test_info if test_contents is not None: self.test_doc = Parser(test_contents) if ref_contents is not None: self.ref_doc = Parser(ref_contents) # First check if it's a reftest matches = self.reference_links_of_type( 'match') + self.reference_links_of_type('mismatch') if matches: if len(matches) > 1: # FIXME: Is this actually true? We should fix this. _log.warning( 'Multiple references are not supported. Importing the first ref defined in %s', self.filesystem.basename(self.filename)) try: href_match_file = matches[0]['href'].strip() if href_match_file.startswith('/'): ref_file = self.filesystem.join( self.source_root_directory, href_match_file.lstrip('/')) else: ref_file = self.filesystem.join( self.filesystem.dirname(self.filename), href_match_file) except KeyError as e: # FIXME: Figure out what to do w/ invalid test files. _log.error('%s has a reference link but is missing the "href"', self.filesystem) return None if (ref_file == self.filename): return {'referencefile': self.filename} if self.ref_doc is None: self.load_file(ref_file, True) test_info = {'test': self.filename, 'reference': ref_file} # If the ref file does not live in the same directory as the test file, check it for support files test_info['reference_support_info'] = {} if self.filesystem.dirname(ref_file) != self.filesystem.dirname( self.filename): reference_support_files = self.support_files(self.ref_doc) if len(reference_support_files) > 0: reference_relpath = self.filesystem.relpath( self.filesystem.dirname(self.filename), self.filesystem.dirname( ref_file)) + self.filesystem.sep test_info['reference_support_info'] = { 'reference_relpath': reference_relpath, 'files': reference_support_files } # not all reference tests have a <link rel='match'> element in WPT repo elif self.is_wpt_reftest(): test_info = { 'test': self.filename, 'reference': self.potential_ref_filename() } test_info['reference_support_info'] = {} # we check for wpt manual test before checking for jstest, as some WPT manual tests can be classified as CSS JS tests elif self.is_wpt_manualtest(): test_info = {'test': self.filename, 'manualtest': True} elif self.is_jstest(): test_info = {'test': self.filename, 'jstest': True} elif '-ref' in self.filename or 'reference' in self.filename: test_info = {'referencefile': self.filename} elif self.options['all'] is True: test_info = {'test': self.filename} if test_info and self.is_slow_test(): test_info['slow'] = True return test_info
def analyze_test(self, test_contents=None, ref_contents=None): """ Analyzes a file to determine if it's a test, what type of test, and what reference or support files it requires. Returns all of the test info """ test_info = None if test_contents is None and self.test_doc is None: return test_info if test_contents is not None: self.test_doc = Parser(test_contents) if ref_contents is not None: self.ref_doc = Parser(ref_contents) # First check if it's a reftest matches = self.reference_links_of_type( 'match') + self.reference_links_of_type('mismatch') if matches: if len(matches) > 1: # FIXME: Is this actually true? We should fix this. _log.warning( 'Multiple references are not supported. Importing the first ref defined in %s', self.filesystem.basename(self.filename)) try: ref_file = self.filesystem.join( self.filesystem.dirname(self.filename), matches[0]['href']) except KeyError as e: # FIXME: Figure out what to do w/ invalid test files. _log.error('%s has a reference link but is missing the "href"', self.filesystem) return None if self.ref_doc is None: self.load_file(ref_file, True) test_info = {'test': self.filename, 'reference': ref_file} # If the ref file does not live in the same directory as the test file, check it for support files test_info['reference_support_info'] = {} if self.filesystem.dirname(ref_file) != self.filesystem.dirname( self.filename): reference_support_files = self.support_files(self.ref_doc) if len(reference_support_files) > 0: reference_relpath = self.filesystem.relpath( self.filesystem.dirname(self.filename), self.filesystem.dirname( ref_file)) + self.filesystem.sep test_info['reference_support_info'] = { 'reference_relpath': reference_relpath, 'files': reference_support_files } elif self.is_jstest(): test_info = {'test': self.filename, 'jstest': True} elif self.options['all'] is True and not ( '-ref' in self.filename) and not ('reference' in self.filename): test_info = {'test': self.filename} return test_info
def load_file(self, filename): if self.filesystem.exists(filename): self.test_doc = Parser(self.filesystem.read_text_file(filename)) else: self.test_doc = None self.ref_doc = None