diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/raptor/test/test_utils.py | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/raptor/test/test_utils.py')
-rw-r--r-- | testing/raptor/test/test_utils.py | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/testing/raptor/test/test_utils.py b/testing/raptor/test/test_utils.py new file mode 100644 index 0000000000..1fcf755e0b --- /dev/null +++ b/testing/raptor/test/test_utils.py @@ -0,0 +1,79 @@ +import os +import sys +import tempfile + +import mozunit +import pytest +import yaml + +# need this so raptor imports work both from /raptor and via mach +here = os.path.abspath(os.path.dirname(__file__)) + +raptor_dir = os.path.join(os.path.dirname(here), "raptor") +sys.path.insert(0, raptor_dir) + +from utils import bool_from_str, transform_platform, write_yml_file + + +@pytest.mark.parametrize("platform", ["win", "mac", "linux64"]) +def test_transform_platform(platform): + transformed = transform_platform("mitmproxy-rel-bin-{platform}.manifest", platform) + assert "{platform}" not in transformed + if platform == "mac": + assert "osx" in transformed + else: + assert platform in transformed + + +def test_transform_platform_no_change(): + starting_string = "nothing-in-here-to-transform" + assert transform_platform(starting_string, "mac") == starting_string + + +@pytest.mark.parametrize("processor", ["x86_64", "other"]) +def test_transform_platform_processor(processor): + transformed = transform_platform( + "string-with-processor-{x64}.manifest", "win", processor + ) + assert "{x64}" not in transformed + if processor == "x86_64": + assert "_x64" in transformed + + +def test_write_yml_file(): + yml_file = os.path.join(tempfile.mkdtemp(), "utils.yaml") + + yml_data = dict(args=["--a", "apple", "--b", "banana"], env=dict(LOG_VERBOSE=1)) + + assert not os.path.exists(yml_file) + write_yml_file(yml_file, yml_data) + assert os.path.exists(yml_file) + + with open(yml_file, "r") as yml_in: + yml_loaded = yaml.unsafe_load(yml_in) + assert yml_loaded == yml_data + + +@pytest.mark.parametrize( + "value, expected_result", + [ + ("true", True), + ("TRUE", True), + ("True", True), + ("false", False), + ("FALSE", False), + ("False", False), + ], +) +def test_bool_from_str(value, expected_result): + assert expected_result == bool_from_str(value) + + +@pytest.mark.parametrize("invalid_value", ["invalid_str", ""]) +def test_bool_from_str_with_invalid_values(invalid_value): + with pytest.raises(ValueError): + bool_from_str(invalid_value) + + +if __name__ == "__main__": + mozunit.main() |