From 43a97878ce14b72f0981164f87f2e35e14151312 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:22:09 +0200 Subject: Adding upstream version 110.0.1. Signed-off-by: Daniel Baumann --- .../test/test_mozilla_building_buildbase.py | 146 +++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 testing/mozharness/test/test_mozilla_building_buildbase.py (limited to 'testing/mozharness/test/test_mozilla_building_buildbase.py') diff --git a/testing/mozharness/test/test_mozilla_building_buildbase.py b/testing/mozharness/test/test_mozilla_building_buildbase.py new file mode 100644 index 0000000000..483196d094 --- /dev/null +++ b/testing/mozharness/test/test_mozilla_building_buildbase.py @@ -0,0 +1,146 @@ +import os +import unittest + +from mozharness.base.log import LogMixin +from mozharness.base.script import ScriptMixin +from mozharness.mozilla.building.buildbase import MozconfigPathError, get_mozconfig_path + + +class FakeLogger(object): + def log_message(self, *args, **kwargs): + pass + + +class FakeScriptMixin(LogMixin, ScriptMixin, object): + def __init__(self): + self.script_obj = self + self.log_obj = FakeLogger() + + +class TestMozconfigPath(unittest.TestCase): + """ + Tests for :func:`get_mozconfig_path`. + """ + + def test_path(self): + """ + Passing just ``src_mozconfig`` gives that file in ``abs_src_dir``. + """ + script = FakeScriptMixin() + + abs_src_path = get_mozconfig_path( + script, + config={"src_mozconfig": "path/to/mozconfig"}, + dirs={"abs_src_dir": "/src"}, + ) + self.assertEqual(abs_src_path, "/src/path/to/mozconfig") + + def test_composite(self): + """ + Passing ``app_name``, ``mozconfig_platform``, and ``mozconfig_variant`` + find the file in the ``config/mozconfigs`` subdirectory of that app + directory. + """ + script = FakeScriptMixin() + + config = { + "app_name": "the-app", + "mozconfig_variant": "variant", + "mozconfig_platform": "platform9000", + } + abs_src_path = get_mozconfig_path( + script, + config=config, + dirs={"abs_src_dir": "/src"}, + ) + self.assertEqual( + abs_src_path, + "/src/the-app/config/mozconfigs/platform9000/variant", + ) + + def test_manifest(self): + """ + Passing just ``src_mozconfig_manifest`` looks in that file in + ``abs_work_dir``, and finds the mozconfig file specified there in + ``abs_src_dir``. + """ + script = FakeScriptMixin() + + test_dir = os.path.dirname(__file__) + config = {"src_mozconfig_manifest": "helper_files/mozconfig_manifest.json"} + abs_src_path = get_mozconfig_path( + script, + config=config, + dirs={ + "abs_src_dir": "/src", + "abs_work_dir": test_dir, + }, + ) + self.assertEqual(abs_src_path, "/src/path/to/mozconfig") + + def test_errors(self): + script = FakeScriptMixin() + + configs = [ + # Not specifying any parts of a mozconfig path + {}, + # Specifying both src_mozconfig and src_mozconfig_manifest + {"src_mozconfig": "path", "src_mozconfig_manifest": "path"}, + # Specifying src_mozconfig with some or all of a composite + # mozconfig path + { + "src_mozconfig": "path", + "app_name": "app", + "mozconfig_platform": "platform", + "mozconfig_variant": "variant", + }, + { + "src_mozconfig": "path", + "mozconfig_platform": "platform", + "mozconfig_variant": "variant", + }, + { + "src_mozconfig": "path", + "app_name": "app", + "mozconfig_variant": "variant", + }, + { + "src_mozconfig": "path", + "app_name": "app", + "mozconfig_platform": "platform", + }, + # Specifying src_mozconfig_manifest with some or all of a composite + # mozconfig path + { + "src_mozconfig_manifest": "path", + "app_name": "app", + "mozconfig_platform": "platform", + "mozconfig_variant": "variant", + }, + { + "src_mozconfig_manifest": "path", + "mozconfig_platform": "platform", + "mozconfig_variant": "variant", + }, + { + "src_mozconfig_manifest": "path", + "app_name": "app", + "mozconfig_variant": "variant", + }, + { + "src_mozconfig_manifest": "path", + "app_name": "app", + "mozconfig_platform": "platform", + }, + # Specifying only some parts of a compsite mozconfig path + {"mozconfig_platform": "platform", "mozconfig_variant": "variant"}, + {"app_name": "app", "mozconfig_variant": "variant"}, + {"app_name": "app", "mozconfig_platform": "platform"}, + {"app_name": "app"}, + {"mozconfig_variant": "variant"}, + {"mozconfig_platform": "platform"}, + ] + + for config in configs: + with self.assertRaises(MozconfigPathError): + get_mozconfig_path(script, config=config, dirs={}) -- cgit v1.2.3