diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:29 +0000 |
commit | 59203c63bb777a3bacec32fb8830fba33540e809 (patch) | |
tree | 58298e711c0ff0575818c30485b44a2f21bf28a0 /testing/mozbase/manifestparser | |
parent | Adding upstream version 126.0.1. (diff) | |
download | firefox-59203c63bb777a3bacec32fb8830fba33540e809.tar.xz firefox-59203c63bb777a3bacec32fb8830fba33540e809.zip |
Adding upstream version 127.0.upstream/127.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/mozbase/manifestparser')
4 files changed, 10 insertions, 9 deletions
diff --git a/testing/mozbase/manifestparser/manifestparser/ini.py b/testing/mozbase/manifestparser/manifestparser/ini.py index b5ffe7a2f0..68f6023244 100644 --- a/testing/mozbase/manifestparser/manifestparser/ini.py +++ b/testing/mozbase/manifestparser/manifestparser/ini.py @@ -30,6 +30,7 @@ def read_ini( strict=True, handle_defaults=True, document=False, + add_line_no=False, ): """ read an .ini file and return a list of [(section, values)] @@ -40,6 +41,7 @@ def read_ini( - separators : strings that denote key, value separation in order - strict : whether to be strict about parsing - handle_defaults : whether to incorporate defaults into each section + - add_line_no: whether to include the line number that points to the test in the generated ini file. """ # variables diff --git a/testing/mozbase/manifestparser/manifestparser/manifestparser.py b/testing/mozbase/manifestparser/manifestparser/manifestparser.py index 63eaeefe05..d8df2baf36 100644 --- a/testing/mozbase/manifestparser/manifestparser/manifestparser.py +++ b/testing/mozbase/manifestparser/manifestparser/manifestparser.py @@ -56,6 +56,7 @@ class ManifestParser(object): handle_defaults=True, use_toml=True, document=False, + add_line_no=False, ): """Creates a ManifestParser from the given manifest files. @@ -82,6 +83,7 @@ class ManifestParser(object): variable in this case. :param use_toml: If True *.toml configration files will be used iff present in the same location as *.ini files (applies to included files as well). If False only *.ini files will be considered. (defaults to True) :param document: If True *.toml configration will preserve the parsed document from `tomlkit` in self.source_documents[filename] (defaults to False) + :param add_line_no: If True, the *.toml configuration will add the line number where the test name appears in the file to the parsed document. Also, the document should be set to True. (defaults to False) """ self._defaults = defaults or {} self.tests = [] @@ -95,6 +97,7 @@ class ManifestParser(object): self._handle_defaults = handle_defaults self.use_toml = use_toml self.document = document + self.add_line_no = add_line_no self.logger = Logger() if manifests: self.read(*manifests) @@ -229,6 +232,7 @@ class ManifestParser(object): strict=self.strict, handle_defaults=self._handle_defaults, document=self.document, + add_line_no=self.add_line_no, ) if filename is not None: self.source_documents[filename] = document diff --git a/testing/mozbase/manifestparser/manifestparser/toml.py b/testing/mozbase/manifestparser/manifestparser/toml.py index 4defd99156..a3e9511994 100644 --- a/testing/mozbase/manifestparser/manifestparser/toml.py +++ b/testing/mozbase/manifestparser/manifestparser/toml.py @@ -82,6 +82,7 @@ def read_toml( strict=True, handle_defaults=True, document=False, + add_line_no=False, ): """ read a .toml file and return a list of [(section, values)] @@ -93,6 +94,7 @@ def read_toml( - strict : whether to be strict about parsing - handle_defaults : whether to incorporate defaults into each section - document: read TOML with tomlkit and return source in test["document"] + - add_line_no: add the line number where the test name appears in the file to the source. Also, the document variable must be set to True for this flag to work. (This is used only to generate the documentation) """ # variables @@ -163,12 +165,12 @@ def read_toml( # merge combined defaults into each section sections = [(i, combine_fields(defaults, j)) for i, j in sections] - if document: + if document and add_line_no: # Take the line where the test name appears in the file. for i, _ in enumerate(sections): line = contents.split(sections[i][0])[0].count(os.linesep) + 1 manifest.setdefault(sections[i][0], {})["lineno"] = str(line) - else: + elif not document: manifest = None return sections, defaults, manifest diff --git a/testing/mozbase/manifestparser/tests/test_manifestparser.py b/testing/mozbase/manifestparser/tests/test_manifestparser.py index ddbc6ecc79..f1774cfffb 100755 --- a/testing/mozbase/manifestparser/tests/test_manifestparser.py +++ b/testing/mozbase/manifestparser/tests/test_manifestparser.py @@ -5,7 +5,6 @@ # You can obtain one at http://mozilla.org/MPL/2.0/. import os -import re import shutil import tempfile import unittest @@ -621,12 +620,6 @@ yellow = submarine after = "edit-manifest-after.toml" after_path = os.path.join(here, after) after_str = open(after_path, "r", encoding="utf-8").read() - - # Define the regex pattern to match lines containing 'lineno' - pattern = re.compile(r"^.*lineno.*$\n?", re.MULTILINE) - # Remove lines containing 'lineno' - manifest_str = re.sub(pattern, "", manifest_str) - assert manifest_str == after_str |