当前位置: 首页>>代码示例>>Python>>正文


Python BeautifulSoup.findAll方法代码示例

本文整理汇总了Python中webkitpy.thirdparty.BeautifulSoup.BeautifulSoup.findAll方法的典型用法代码示例。如果您正苦于以下问题:Python BeautifulSoup.findAll方法的具体用法?Python BeautifulSoup.findAll怎么用?Python BeautifulSoup.findAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在webkitpy.thirdparty.BeautifulSoup.BeautifulSoup的用法示例。


在下文中一共展示了BeautifulSoup.findAll方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_convert_vendor_prefix_js_paths

# 需要导入模块: from webkitpy.thirdparty.BeautifulSoup import BeautifulSoup [as 别名]
# 或者: from webkitpy.thirdparty.BeautifulSoup.BeautifulSoup import findAll [as 别名]
    def test_convert_vendor_prefix_js_paths(self):
        test_html = """<head>
<script src="/common/vendor-prefix.js">
</head>
"""
        fake_dir_path = self.fake_dir_path('adapterjspaths')
        converter = _W3CTestConverter(fake_dir_path, DUMMY_FILENAME)

        oc = OutputCapture()
        oc.capture_output()
        try:
            converter.feed(test_html)
            converter.close()
            converted = converter.output()
        finally:
            oc.restore_output()

        new_html = BeautifulSoup(converted[1])

        # Verify the original paths are gone, and the new paths are present.
        orig_path_pattern = re.compile('\"/common/vendor-prefix.js')
        self.assertEquals(len(new_html.findAll(src=orig_path_pattern)), 0, 'vendor-prefix.js path was not converted')

        resources_dir = converter.path_from_webkit_root("LayoutTests", "resources")
        new_relpath = os.path.relpath(resources_dir, fake_dir_path)
        relpath_pattern = re.compile(new_relpath)
        self.assertEquals(len(new_html.findAll(src=relpath_pattern)), 1, 'vendor-prefix.js relative path not correct')
开发者ID:smil-in-javascript,项目名称:blink,代码行数:29,代码来源:test_converter_unittest.py

示例2: verify_test_harness_paths

# 需要导入模块: from webkitpy.thirdparty.BeautifulSoup import BeautifulSoup [as 别名]
# 或者: from webkitpy.thirdparty.BeautifulSoup.BeautifulSoup import findAll [as 别名]
    def verify_test_harness_paths(self, converter, converted, test_path, num_src_paths, num_href_paths):
        if isinstance(converted, basestring):
            converted = BeautifulSoup(converted)

        resources_dir = converter.path_from_webkit_root("LayoutTests", "resources")

        # Verify the original paths are gone, and the new paths are present.
        orig_path_pattern = re.compile('\"/resources/testharness')
        self.assertEquals(len(converted.findAll(src=orig_path_pattern)), 0, 'testharness src path was not converted')
        self.assertEquals(len(converted.findAll(href=orig_path_pattern)), 0, 'testharness href path was not converted')

        new_relpath = os.path.relpath(resources_dir, test_path)
        relpath_pattern = re.compile(new_relpath)
        self.assertEquals(len(converted.findAll(src=relpath_pattern)), num_src_paths, 'testharness src relative path not correct')
        self.assertEquals(len(converted.findAll(href=relpath_pattern)), num_href_paths, 'testharness href relative path not correct')
开发者ID:,项目名称:,代码行数:17,代码来源:

示例3: _parse_attachment_ids_request_query

# 需要导入模块: from webkitpy.thirdparty.BeautifulSoup import BeautifulSoup [as 别名]
# 或者: from webkitpy.thirdparty.BeautifulSoup.BeautifulSoup import findAll [as 别名]
    def _parse_attachment_ids_request_query(self, page, since=None):
        # Formats
        digits = re.compile("\d+")
        attachment_href = re.compile("attachment.cgi\?id=\d+&action=review")
        # if no date is given, return all ids
        if not since:
            attachment_links = SoupStrainer("a", href=attachment_href)
            return [int(digits.search(tag["href"]).group(0))
                for tag in BeautifulSoup(page, parseOnlyThese=attachment_links)]

        # Parse the main table only
        date_format = re.compile("\d{4}-\d{2}-\d{2} \d{2}:\d{2}")
        mtab = SoupStrainer("table", {"class": "requests"})
        soup = BeautifulSoup(page, parseOnlyThese=mtab)
        patch_ids = []

        for row in soup.findAll("tr"):
            patch_tag = row.find("a", {"href": attachment_href})
            if not patch_tag:
                continue
            patch_id = int(digits.search(patch_tag["href"]).group(0))
            date_tag = row.find("td", text=date_format)
            if date_tag and datetime.strptime(date_format.search(date_tag).group(0), "%Y-%m-%d %H:%M") < since:
                _log.info("Patch is old: %d (%s)" % (patch_id, date_tag))
                continue
            patch_ids.append(patch_id)
        return patch_ids
开发者ID:chenbk85,项目名称:webkit2-wincairo,代码行数:29,代码来源:bugzilla.py

示例4: _parse_bug_page

# 需要导入模块: from webkitpy.thirdparty.BeautifulSoup import BeautifulSoup [as 别名]
# 或者: from webkitpy.thirdparty.BeautifulSoup.BeautifulSoup import findAll [as 别名]
 def _parse_bug_page(self, page):
     soup = BeautifulSoup(page)
     bug = {}
     bug["id"] = int(soup.find("bug_id").string)
     bug["title"] = unicode(soup.find("short_desc").string)
     bug["reporter_email"] = str(soup.find("reporter").string)
     bug["assigned_to_email"] = str(soup.find("assigned_to").string)
     bug["cc_emails"] = [str(element.string)
                         for element in soup.findAll('cc')]
     bug["attachments"] = [self._parse_attachment_element(element, bug["id"]) for element in soup.findAll('attachment')]
     return bug
开发者ID:mikezit,项目名称:Webkit_Code,代码行数:13,代码来源:bugzilla.py

示例5: _parse_bug_dictionary_from_xml

# 需要导入模块: from webkitpy.thirdparty.BeautifulSoup import BeautifulSoup [as 别名]
# 或者: from webkitpy.thirdparty.BeautifulSoup.BeautifulSoup import findAll [as 别名]
 def _parse_bug_dictionary_from_xml(self, page):
     soup = BeautifulSoup(page)
     bug = {}
     bug["id"] = int(soup.find("bug_id").string)
     bug["title"] = self._string_contents(soup.find("short_desc"))
     bug["bug_status"] = self._string_contents(soup.find("bug_status"))
     dup_id = soup.find("dup_id")
     if dup_id:
         bug["dup_id"] = self._string_contents(dup_id)
     bug["reporter_email"] = self._string_contents(soup.find("reporter"))
     bug["assigned_to_email"] = self._string_contents(soup.find("assigned_to"))
     bug["cc_emails"] = [self._string_contents(element) for element in soup.findAll('cc')]
     bug["attachments"] = [self._parse_attachment_element(element, bug["id"]) for element in soup.findAll('attachment')]
     return bug
开发者ID:,项目名称:,代码行数:16,代码来源:

示例6: _parse_bug_page

# 需要导入模块: from webkitpy.thirdparty.BeautifulSoup import BeautifulSoup [as 别名]
# 或者: from webkitpy.thirdparty.BeautifulSoup.BeautifulSoup import findAll [as 别名]
 def _parse_bug_page(self, page):
     soup = BeautifulSoup(page)
     bug = {}
     bug["id"] = int(soup.find("bug_id").string)
     bug["title"] = self._string_contents(soup.find("short_desc"))
     bug["reporter_email"] = self._string_contents(soup.find("reporter"))
     bug["assigned_to_email"] = self._string_contents(soup.find("assigned_to"))
     bug["cc_emails"] = [self._string_contents(element)
                         for element in soup.findAll('cc')]
     bug["attachments"] = [self._parse_attachment_element(element, bug["id"]) for element in soup.findAll('attachment')]
     bug["platform"] = self._string_contents(soup.find("rep_platform"))
     bug["os"] = self._string_contents(soup.find("op_sys"))
     bug["long_description"] = self._string_contents(soup.find("long_desc").findNext("thetext"))
     bug["keywords"] = self._string_contents(soup.find("keywords"))
     bug["component"] = self._string_contents(soup.find("component"))
     return bug
开发者ID:,项目名称:,代码行数:18,代码来源:

示例7: TestParser

# 需要导入模块: from webkitpy.thirdparty.BeautifulSoup import BeautifulSoup [as 别名]
# 或者: from webkitpy.thirdparty.BeautifulSoup.BeautifulSoup import findAll [as 别名]
class TestParser(object):
    def __init__(self, options, filename):
        self.options = options
        self.filename = filename
        self.host = Host()
        self.filesystem = self.host.filesystem

        self.test_doc = None
        self.ref_doc = None
        self.load_file(filename)

    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:
                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.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
            # a 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 reference_links_of_type(self, reftest_type):
        return self.test_doc.findAll(rel=reftest_type)

    def is_jstest(self):
        """Returns whether the file appears to be a jstest, by searching for usage of W3C-style testharness paths."""
        return bool(self.test_doc.find(src=re.compile("['\"/]?/resources/testharness")))

    def support_files(self, doc):
        """ Searches the file for all paths specified in url()'s, href or src attributes."""
        support_files = []
#.........这里部分代码省略.........
开发者ID:venkatarajasekhar,项目名称:Qt,代码行数:103,代码来源:test_parser.py

示例8: TestParser

# 需要导入模块: from webkitpy.thirdparty.BeautifulSoup import BeautifulSoup [as 别名]
# 或者: from webkitpy.thirdparty.BeautifulSoup.BeautifulSoup import findAll [as 别名]
class TestParser(object):

    def __init__(self, options, filename, host=Host()):
        self.options = options
        self.filename = filename
        self.host = host
        self.filesystem = self.host.filesystem

        self.test_doc = None
        self.ref_doc = None
        self.load_file(filename)

    def load_file(self, filename, is_ref=False):
        if self.filesystem.isfile(filename):
            try:
                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)
                doc = 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)
            doc = None

        if is_ref:
            self.ref_doc = doc
        else:
            self.test_doc = doc

    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 (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 reference_links_of_type(self, reftest_type):
        return self.test_doc.findAll(rel=reftest_type)

    def is_jstest(self):
        """Returns whether the file appears to be a jstest, by searching for usage of W3C-style testharness paths."""
        return bool(self.test_doc.find(src=re.compile('[\'\"/]?/resources/testharness')))

#.........这里部分代码省略.........
开发者ID:eocanha,项目名称:webkit,代码行数:103,代码来源:test_parser.py

示例9: TestParser

# 需要导入模块: from webkitpy.thirdparty.BeautifulSoup import BeautifulSoup [as 别名]
# 或者: from webkitpy.thirdparty.BeautifulSoup.BeautifulSoup import findAll [as 别名]
class TestParser(object):

    def __init__(self, filename, host):
        self.filename = filename
        self.host = host
        self.filesystem = self.host.filesystem

        self.test_doc = None
        self.ref_doc = None
        self.load_file(filename)

    def load_file(self, filename, is_ref=False):
        if self.filesystem.isfile(filename):
            try:
                doc = BeautifulSoup(self.filesystem.read_binary_file(filename))
            except IOError:
                _log.error("IOError: Failed to read %s", filename)
                doc = None
            except HTMLParser.HTMLParseError:
                # FIXME: Figure out what to do if we can't parse the file.
                _log.error("HTMLParseError: Failed to parse %s", filename)
                doc = 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)
            doc = None

        if is_ref:
            self.ref_doc = doc
        else:
            self.test_doc = doc

    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: A dict which can have the properties:
            "test": test file name.
            "reference": related reference test file name if this is a reference test.
            "reference_support_info": extra information about the related reference test and any support files.
            "jstest": A boolean, whether this is a JS test.
            If the path doesn't look a test or the given contents are empty,
            then None is returned.
        """
        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 = BeautifulSoup(test_contents)

        if ref_contents is not None:
            self.ref_doc = BeautifulSoup(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:
                # 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 'csswg-test' in self.filename:
            # In csswg-test, all other files should be manual tests.
            # This function isn't called for non-test files in support/.
            test_info = {'test': self.filename}

        elif '-manual.' in self.filesystem.basename(self.filename):
            # WPT has a naming convention for manual tests.
            test_info = {'test': self.filename}

        return test_info

    def reference_links_of_type(self, reftest_type):
        return self.test_doc.findAll(rel=reftest_type)
#.........这里部分代码省略.........
开发者ID:mirror,项目名称:chromium,代码行数:103,代码来源:test_parser.py

示例10: TestParser

# 需要导入模块: from webkitpy.thirdparty.BeautifulSoup import BeautifulSoup [as 别名]
# 或者: from webkitpy.thirdparty.BeautifulSoup.BeautifulSoup import findAll [as 别名]
class TestParser(object):

    def __init__(self, options, filename):
        self.options = options
        self.filename = filename
        self.host = Host()
        self.filesystem = self.host.filesystem

        self.test_doc = None
        self.ref_doc = None
        self.load_file(filename)

    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

    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 reference_links_of_type(self, reftest_type):
        return self.test_doc.findAll(rel=reftest_type)

    def is_jstest(self):
        """Returns whether the file appears to be a jstest, by searching for usage of W3C-style testharness paths."""
        return bool(self.test_doc.find(src=re.compile('[\'\"/]?/resources/testharness')))

    def support_files(self, doc):
        """ Searches the file for all paths specified in url()'s, href or src attributes."""
        support_files = []

        if doc is None:
            return support_files

        elements_with_src_attributes = doc.findAll(src=re.compile('.*'))
        elements_with_href_attributes = doc.findAll(href=re.compile('.*'))

        url_pattern = re.compile('url\(.*\)')
        urls = []
        for url in doc.findAll(text=url_pattern):
            url = re.search(url_pattern, url)
            url = re.sub('url\([\'\"]', '', url.group(0))
            url = re.sub('[\'\"]\)', '', url)
            urls.append(url)

        src_paths = [src_tag['src'] for src_tag in elements_with_src_attributes]
        href_paths = [href_tag['href'] for href_tag in elements_with_href_attributes]
#.........这里部分代码省略.........
开发者ID:Anthony-Biget,项目名称:openjfx,代码行数:103,代码来源:test_parser.py

示例11: TestParser

# 需要导入模块: from webkitpy.thirdparty.BeautifulSoup import BeautifulSoup [as 别名]
# 或者: from webkitpy.thirdparty.BeautifulSoup.BeautifulSoup import findAll [as 别名]
class TestParser(object):

    def __init__(self, options, filename):
        self.options = options
        self.filename = filename
        self.host = Host()
        self.filesystem = self.host.filesystem

        self.test_doc = None
        self.ref_doc = None
        self.load_file(filename)

    def load_file(self, filename, is_ref=False):
        if self.filesystem.isfile(filename):
            try:
                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)
                doc = 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)
            doc = None

        if is_ref:
            self.ref_doc = doc
        else:
            self.test_doc = doc

    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 reference_links_of_type(self, reftest_type):
        return self.test_doc.findAll(rel=reftest_type)

    def is_jstest(self):
        """Returns whether the file appears to be a jstest, by searching for usage of W3C-style testharness paths."""
        return bool(self.test_doc.find(src=re.compile('[\'\"/]?/resources/testharness')))

    def support_files(self, doc):
        """ Searches the file for all paths specified in url()'s or src attributes."""
        support_files = []

        if doc is None:
            return support_files

        elements_with_src_attributes = doc.findAll(src=re.compile('.*'))
        elements_with_href_attributes = doc.findAll(href=re.compile('.*'))

        url_pattern = re.compile('url\(.*\)')
        urls = []
#.........这里部分代码省略.........
开发者ID:aobzhirov,项目名称:ChromiumGStreamerBackend,代码行数:103,代码来源:test_parser.py


注:本文中的webkitpy.thirdparty.BeautifulSoup.BeautifulSoup.findAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。