summaryrefslogtreecommitdiffstats
path: root/testing/mozbase/manifestparser/tests/test_util.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /testing/mozbase/manifestparser/tests/test_util.py
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/mozbase/manifestparser/tests/test_util.py')
-rw-r--r--testing/mozbase/manifestparser/tests/test_util.py104
1 files changed, 104 insertions, 0 deletions
diff --git a/testing/mozbase/manifestparser/tests/test_util.py b/testing/mozbase/manifestparser/tests/test_util.py
new file mode 100644
index 0000000000..f2b37de43c
--- /dev/null
+++ b/testing/mozbase/manifestparser/tests/test_util.py
@@ -0,0 +1,104 @@
+#!/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()