Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/testing/mozbase/manifestparser/tests/   (Browser von der Mozilla Stiftung Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 2 kB image not shown  

Quelle  test_util.py   Sprache: Python

 
#!/usr/bin/env python

"""
Test how our utility functions are working.
"""

from io import StringIO
from textwrap import dedent

import mozunit
import pytest
from manifestparser import read_ini
from manifestparser.util import evaluate_list_from_string


@pytest.fixture(scope="module")
def parse_manifest():
    def inner(string, **kwargs):
        buf = StringIO()
        buf.write(dedent(string))
        buf.seek(0)
        return read_ini(buf, **kwargs)[0]

    return inner


@pytest.mark.parametrize(
    "test_manifest, expected_list",
    [
        [
            """
            [test_felinicity.py]
            kittens = true
            cats =
                "I",
                "Am",
                "A",
                "Cat",
            """,
            ["I""Am""A""Cat"],
        ],
        [
            """
            [test_felinicity.py]
            kittens = true
            cats =
                ["I", 1],
                ["Am", 2],
                ["A", 3],
                ["Cat", 4],
            """,
            [
                ["I", 1],
                ["Am", 2],
                ["A", 3],
                ["Cat", 4],
            ],
        ],
    ],
)
def test_string_to_list_conversion(test_manifest, expected_list, parse_manifest):
    parsed_tests = parse_manifest(test_manifest)
    assert evaluate_list_from_string(parsed_tests[0][1]["cats"]) == expected_list


@pytest.mark.parametrize(
    "test_manifest, failure",
    [
        [
            """
            # This will fail since the elements are not enlosed in quotes
            [test_felinicity.py]
            kittens = true
            cats =
                I,
                Am,
                A,
                Cat,
            """,
            ValueError,
        ],
        [
            """
            # This will fail since the syntax is incorrect
            [test_felinicity.py]
            kittens = true
            cats =
                ["I", 1,
                ["Am", 2,
                ["A", 3],
                ["Cat", 4],
            """,
            SyntaxError,
        ],
    ],
)
def test_string_to_list_conversion_failures(test_manifest, failure, parse_manifest):
    parsed_tests = parse_manifest(test_manifest)
    with pytest.raises(failure):
        evaluate_list_from_string(parsed_tests[0][1]["cats"])


if __name__ == "__main__":
    mozunit.main()

Messung V0.5
C=98 H=95 G=96

¤ Dauer der Verarbeitung: 0.3 Sekunden  ¤

*© 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 und die Messung sind noch experimentell.