| 1 |
import os |
| 2 |
import unittest |
| 3 |
|
| 4 |
import mozunit |
| 5 |
from mozharness.base.log import LogMixin |
| 6 |
from mozharness.base.script import ScriptMixin |
| 7 |
from mozharness.mozilla.building.buildbase import MozconfigPathError, get_mozconfig_path |
| 8 |
|
| 9 |
|
| 10 |
class FakeLogger: |
| 11 |
def log_message(self, *args, **kwargs): |
| 12 |
pass |
| 13 |
|
| 14 |
|
| 15 |
class FakeScriptMixin(LogMixin, ScriptMixin): |
| 16 |
def __init__(self): |
| 17 |
self.script_obj = self |
| 18 |
self.log_obj = FakeLogger() |
| 19 |
|
| 20 |
|
| 21 |
class TestMozconfigPath(unittest.TestCase): |
| 22 |
""" |
| 23 |
Tests for :func:`get_mozconfig_path`. |
| 24 |
""" |
| 25 |
|
| 26 |
def test_path(self): |
| 27 |
""" |
| 28 |
Passing just ``src_mozconfig`` gives that file in ``abs_src_dir``. |
| 29 |
""" |
| 30 |
script = FakeScriptMixin() |
| 31 |
|
| 32 |
abs_src_path = get_mozconfig_path( |
| 33 |
script, |
| 34 |
config={"src_mozconfig": "path/to/mozconfig"}, |
| 35 |
dirs={"abs_src_dir": "/src"}, |
| 36 |
) |
| 37 |
self.assertEqual(abs_src_path, "/src/path/to/mozconfig") |
| 38 |
|
| 39 |
def test_composite(self): |
| 40 |
""" |
| 41 |
Passing ``app_name``, ``mozconfig_platform``, and ``mozconfig_variant`` |
| 42 |
find the file in the ``config/mozconfigs`` subdirectory of that app |
| 43 |
directory. |
| 44 |
""" |
| 45 |
script = FakeScriptMixin() |
| 46 |
|
| 47 |
config = { |
| 48 |
"app_name": "the-app", |
| 49 |
"mozconfig_variant": "variant", |
| 50 |
"mozconfig_platform": "platform9000", |
| 51 |
} |
| 52 |
abs_src_path = get_mozconfig_path( |
| 53 |
script, |
| 54 |
config=config, |
| 55 |
dirs={"abs_src_dir": "/src"}, |
| 56 |
) |
| 57 |
self.assertEqual( |
| 58 |
abs_src_path, |
| 59 |
"/src/the-app/config/mozconfigs/platform9000/variant", |
| 60 |
) |
| 61 |
|
| 62 |
def test_manifest(self): |
| 63 |
""" |
| 64 |
Passing just ``src_mozconfig_manifest`` looks in that file in |
| 65 |
``abs_work_dir``, and finds the mozconfig file specified there in |
| 66 |
``abs_src_dir``. |
| 67 |
""" |
| 68 |
script = FakeScriptMixin() |
| 69 |
|
| 70 |
test_dir = os.path.dirname(__file__) |
| 71 |
config = {"src_mozconfig_manifest": "helper_files/mozconfig_manifest.json"} |
| 72 |
abs_src_path = get_mozconfig_path( |
| 73 |
script, |
| 74 |
config=config, |
| 75 |
dirs={ |
| 76 |
"abs_src_dir": "/src", |
| 77 |
"abs_work_dir": test_dir, |
| 78 |
}, |
| 79 |
) |
| 80 |
self.assertEqual(abs_src_path, "/src/path/to/mozconfig") |
| 81 |
|
| 82 |
def test_errors(self): |
| 83 |
script = FakeScriptMixin() |
| 84 |
|
| 85 |
configs = [ |
| 86 |
# Not specifying any parts of a mozconfig path |
| 87 |
{}, |
| 88 |
# Specifying both src_mozconfig and src_mozconfig_manifest |
| 89 |
{"src_mozconfig": "path", "src_mozconfig_manifest": "path"}, |
| 90 |
# Specifying src_mozconfig with some or all of a composite |
| 91 |
# mozconfig path |
| 92 |
{ |
| 93 |
"src_mozconfig": "path", |
| 94 |
"app_name": "app", |
| 95 |
"mozconfig_platform": "platform", |
| 96 |
"mozconfig_variant": "variant", |
| 97 |
}, |
| 98 |
{ |
| 99 |
"src_mozconfig": "path", |
| 100 |
"mozconfig_platform": "platform", |
| 101 |
"mozconfig_variant": "variant", |
| 102 |
}, |
| 103 |
{ |
| 104 |
"src_mozconfig": "path", |
| 105 |
"app_name": "app", |
| 106 |
"mozconfig_variant": "variant", |
| 107 |
}, |
| 108 |
{ |
| 109 |
"src_mozconfig": "path", |
| 110 |
"app_name": "app", |
| 111 |
"mozconfig_platform": "platform", |
| 112 |
}, |
| 113 |
# Specifying src_mozconfig_manifest with some or all of a composite |
| 114 |
# mozconfig path |
| 115 |
{ |
| 116 |
"src_mozconfig_manifest": "path", |
| 117 |
"app_name": "app", |
| 118 |
"mozconfig_platform": "platform", |
| 119 |
"mozconfig_variant": "variant", |
| 120 |
}, |
| 121 |
{ |
| 122 |
"src_mozconfig_manifest": "path", |
| 123 |
"mozconfig_platform": "platform", |
| 124 |
"mozconfig_variant": "variant", |
| 125 |
}, |
| 126 |
{ |
| 127 |
"src_mozconfig_manifest": "path", |
| 128 |
"app_name": "app", |
| 129 |
"mozconfig_variant": "variant", |
| 130 |
}, |
| 131 |
{ |
| 132 |
"src_mozconfig_manifest": "path", |
| 133 |
"app_name": "app", |
| 134 |
"mozconfig_platform": "platform", |
| 135 |
}, |
| 136 |
# Specifying only some parts of a compsite mozconfig path |
| 137 |
{"mozconfig_platform": "platform", "mozconfig_variant": "variant"}, |
| 138 |
{"app_name": "app", "mozconfig_variant": "variant"}, |
| 139 |
{"app_name": "app", "mozconfig_platform": "platform"}, |
| 140 |
{"app_name": "app"}, |
| 141 |
{"mozconfig_variant": "variant"}, |
| 142 |
{"mozconfig_platform": "platform"}, |
| 143 |
] |
| 144 |
|
| 145 |
for config in configs: |
| 146 |
with self.assertRaises(MozconfigPathError): |
| 147 |
get_mozconfig_path(script, config=config, dirs={}) |
| 148 |
|
| 149 |
|
| 150 |
if __name__ == "__main__": |
| 151 |
mozunit.main() |