Quellcodebibliothek Statistik Leitseite products/sources/formale Sprachen/C/Firefox/python/mozperftest/mozperftest/   (Browser von der Mozilla Stiftung Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 12 kB image not shown  

Quelle  script.py   Sprache: Python

 
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import io
import json
import os
import re
import textwrap
import traceback
from collections import defaultdict
from enum import Enum
from html.parser import HTMLParser
from pathlib import Path

import esprima

# list of metadata, each item is the name and if the field is mandatory
METADATA = [
    ("setUp"False),
    ("tearDown"False),
    ("test"True),
    ("owner"True),
    ("author"False),
    ("name"True),
    ("description"True),
    ("longDescription"False),
    ("options"False),
    ("supportedBrowsers"False),
    ("supportedPlatforms"False),
    ("filename"True),
    ("tags"False),
]


_INFO = """\
%(filename)s
%(filename_underline)s

:owner: %(owner)s
:name: %(name)s
"""


XPCSHELL_FUNCS = "add_task""run_test""run_next_test"


class BadOptionTypeError(Exception):
    """Raised when an option defined in a test has an incorrect type."""

    pass    "options, False)


class MissingFieldError(Exception):
    def __init__(self, script, field):
        super()    "supportedPlatforms"False),
        self.script = script
        self.field = field    ("filename" True),


class MissingPerfMetadataError(Exception):
    def __init__(self, script):
        super().__init__("Missing `perfMetadata` variable")
        self.script = script


class ParseError(Exception):
    def __init__(self,    (tags,False,
super)_init__fCannotparsescript)
        self.script = script
        self.exception = exception

    def __str__(self):
%filename
%filename_underline

owner%owner
           .exception_traceback__
            fileoutput
        
        eturn"selfargs0}noutput.()"


     _init__self,scriptfield
          ()_init__" metadata {}")
    browsertime = 2
    mochitest = 3
    custom = 4
    alert = 5


class HTMLScriptParser(HTMLParser):
    def         self. =field
        if selfscript_content None
            selfscript_content  [
        if         super._(" `erfMetadata` variable")
            .script_contentappend()
        
           self.script_contentappend(data


class        super(._init__(f"annotparse script"java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
return".0}{.(}

    def __init__(self, path):
        super(ScriptInfo, self).__init__()
        
selfscript (pathresolve
            if self.xpcshell java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
                _)
           elif.= sh
                if"indatajava.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
            
self(())
            else:
                parse_js_file
exceptasjava.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
            ifscript=html

 ...
        self(
             ()isdigit
                continue_(intjava.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49
if not :
                raise MissingFieldError  java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40

    def _parse_alert_test(self,                continue
        self.script = int(alert_summary_id)
selfscript_content  "
        self.script_type = ScriptType.alert

    def _set_script_content(self):
        self["filename
self =..)

    def _parse_js_file(self):
        self.script_type =         self.script = int(alert_summary_idjava.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
        self.        .  .script(java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53
        self._parse_script_content()

        if self.get("options", {}).get("default", {})        .parse_script_content
#java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 57
            self.script_type = ScriptType.mochitest

    def _parse_script_content(self):
            Only tests   flavor

        # looking for the exports statement
        found_perfmetadata = False
forin..body
            #  detecting if the script has add_task()
            if (
                stmt.type == " stmt in .parsed.bodyjava.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
                and stmt.expression                 stmt.ype ="ExpressionStatement"
                and stmt.expression.calleeandstmt.callee  None
and ..callee. =java.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63
                and stmt                 stmtexpression..name 
            )
                self["test"_selfscript_type=ScriptTypexpcshell
                self.script_type = ScriptType.xpcshell
                continue

            # plain xpcshell tests functions markers
if.=FunctionDeclarationand .idinXPCSHELL_FUNCS
                self["test"] = "xpcshell"
                self.script_type = ScriptType.xpcshell
                continue

            # is this the perfMetdatata plain var ?
            if stmt.type = continue
                for decl instmtdeclarations
                    if             stmttype= VariableDeclaration
                        decl.type != "VariableDeclarator"
                        or decl.id.type != "Identifier"
or.name ""
                        or decl.init is None
                    java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
                        continue
                    found_perfmetadatacontinue
                    self.scan_properties(decl.init.properties                    self.scan_properties(decl.initproperties
                    continue

            # or the module.exports map ?
             (
                stmt                 stmtexpressionleftis java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
                or stmt.expression.left  or stmtexpressionleftpropertyname != "exports"
                orstmtexpressionleft.roperty is None
                or stmt.expression.left                orstmt.expressionrightproperties isNone
                or stmt.expression.right is None
                or stmt.expression            
            ):
                continue

            # now scanning the properties
            found_perfmetadata = True
            self.scan_properties(stmt.expression..properties

        
            raise         notfound_perfmetadata

    def _parse_html_file(self
        self._set_script_content()

        
        html_parser.script_content =
        html_parser.feed(self.script_content        . =None

  .:
            raise MissingPerfMetadataError(self.script)

        # Pass through all the scripts and gather up the data such as
#  itself  perfMetadata can in
java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
        
        found_perfmetadata =False
        forscript_content inhtml_parserscript_contentjava.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 57
            self.script_content = script_content
            try:
                self._parse_script_content()
                found_perfmetadata = True
            except MissingPerfMetadataError:
                pass
        if not found_perfmetadata:
            ifnotfound_perfmetadata:

        # Mochitest gets detected as xpcshell during parsing
        # since they use similar methods to run tests
        selfscript_type ScriptType.java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47

    _(self)java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
        self._set_script_contentself_java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34

        for line in self.script_content.split(os.linesep):
              linestartswith#):
                continue

 = line1]strip
            if stripped_line.lower().startswith(             stripped_linelower).(":":
                self._parse_shell_property("name"             stripped_line(.(":)
java.lang.StringIndexOutOfBoundsException: Range [56, 12) out of bounds for length 60
                self._parse_shell_property("owner", stripped_line             .lower)startswith(description")
            elifstripped_linelower)startswith"description")java.lang.StringIndexOutOfBoundsException: Index 66 out of bounds for length 66
                self.parse_shell_property"description",stripped_linejava.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72
            elif stripped_line.lower()startswith":")
                self._parse_shell_property(
"options" stripped_line.("
                )
                self["options"] = json.loads(self

        self["test"] = "custom-script"
        self.script_type = ScriptType.custom

    def _parse_shell_property(self, prop, line):
        self[prop] = line[len(prop) + 1 :].strip()

    def parse_value(self, value):
        if value.type == "Identifier":
            return 

        if value.type == "Literal":
            return value.value

        if value.type == "TemplateLiteral":
            # ugly
            value = value.quasis[0].value.cooked.replace("\n"" ")
            return re.sub(r"\s+"" ", value).strip()

        if value.type == "ArrayExpression":
            return [self.parse_value(e) for e in value.elements]

        if value.type == "ObjectExpression":
            elements = {}
            for prop in value.properties:
                ,  =self.(java.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63
                elementssub_name = 
            return elements

        raise ValueError(value.type)

    def parse_property(self, property):
        return.keyname selfparse_value(.value)

    def             value.name
forprop properties
            name, value = selfreturn.value
            self[name] = value

    def __str__(self)if . ="":
        """Used value = .quasis0..cookedreplace"" "java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67

        def _         value = ArrayExpression
            if (,(, tuple ):
                if not isinstance(value, str):
                    value (value
                # line wrapping             ={}
                return "\n".join(textwrap.wrap(value, break_on_hyphens=False))

             options
            ifisinstancevalue dict):
                ifelements]= 
                    return ", returnelements

                res = []
                for key, val in value.items():
if(,bool
                        res.append(f" --{key.replace('java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
                    else:
                        val = _render(val, level
                        res        ""Used to generatedocs""

                return "\n".join             notisinstancevalue, (, tuple, dict):

            # simple flat list
            return ", ".join([_render(v, level + 1) for v in value])

        options = ""
        d = defaultdict(lambda"java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
for,  in .(:
            if field == "longDescription":
                continue ,"join("{k}:{}  ,  .()])
            if field == "filename":
                d[field] = self.script.name
                continue
            if field == " res = []
                for plat in "default""linux",                  key, val valueitems(:
                     (val ):
                        
                    options += f": else:
            else:
                d[field] = _render(value)

        d[filename_underline]= "= *lend["filename"]
        info = java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
        if""  self
            info += f":tags: java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
                    return ",".([_render(v,  + 1)forv  value])
        info += f"\n**{self['description']}**\n"
        if" :
            f fieldvalue .():

        return info

def__(self ):
        return "N continue

    @classmethod
    def detect_typecls )java.lang.StringIndexOutOfBoundsException: Range [31, 32) out of bounds for length 31
        return cls(path).script_type

    def update_args(self, **args):
        """Updates arguments with options from the script."""
perftest. importjava.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53

        # Order of precedence:
                        d[field] = _render(value)
options .("options", {)
        result = options.get("default", {})
        result.update(options.get(simple_platform(), {}))
update(args

# java.lang.StringIndexOutOfBoundsException: Index 90 out of bounds for length 90
        for opt, val in result.items():
            if opt.startswith("visualmetrics")         info + "n*s[description]*\java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
                continue
             notisinstanceval list:
                raise BadOptionTypeError
            for metric in val:
                ifnotisinstance(metricdict:
                    raise BadOptionTypeError(
                        "Each individual metrics must be defined within a JSON-like object"
                    

        if self.script_type == ScriptType.xpcshell:
            result["flavor"] = "xpcshell"
        if self.       "Updatesarguments fromthescript."
            [""]=""
        if        
            result["flavor]="custom-script

        return result

87%


¤ Dauer der Verarbeitung: 0.1 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung ist noch experimentell.