test_build_profile.py (2329B)
1 # This Source Code Form is subject to the terms of the Mozilla Public 2 # License, v. 2.0. If a copy of the MPL was not distributed with this 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 5 import json 6 import os 7 from argparse import Namespace 8 9 import mozunit 10 import pytest 11 from conftest import setup_args 12 from mozbuild.base import MozbuildObject 13 from mozprofile import Profile 14 from mozprofile.prefs import Preferences 15 16 here = os.path.abspath(os.path.dirname(__file__)) 17 18 19 @pytest.fixture 20 def build_profile(monkeypatch, setup_test_harness, parser): 21 setup_test_harness(*setup_args) 22 runtests = pytest.importorskip("runtests") 23 md = runtests.MochitestDesktop("plain", {"log_tbpl": "-"}) 24 monkeypatch.setattr(md, "fillCertificateDB", lambda *args, **kwargs: None) 25 26 options = parser.parse_args([]) 27 options = vars(options) 28 29 def inner(**kwargs): 30 opts = options.copy() 31 opts.update(kwargs) 32 33 return md, md.buildProfile(Namespace(**opts)) 34 35 return inner 36 37 38 @pytest.fixture 39 def profile_data_dir(): 40 build = MozbuildObject.from_environment(cwd=here) 41 return os.path.join(build.topsrcdir, "testing", "profiles") 42 43 44 def test_common_prefs_are_all_set(build_profile, profile_data_dir): 45 md, result = build_profile() 46 47 with open(os.path.join(profile_data_dir, "profiles.json")) as fh: 48 base_profiles = json.load(fh)["mochitest"] 49 50 # build the expected prefs 51 expected_prefs = {} 52 for profile in base_profiles: 53 for name in Profile.preference_file_names: 54 path = os.path.join(profile_data_dir, profile, name) 55 if os.path.isfile(path): 56 expected_prefs.update(Preferences.read_prefs(path)) 57 58 # read the actual prefs 59 actual_prefs = {} 60 for name in Profile.preference_file_names: 61 path = os.path.join(md.profile.profile, name) 62 if os.path.isfile(path): 63 actual_prefs.update(Preferences.read_prefs(path)) 64 65 # keep this in sync with the values in MochitestDesktop.merge_base_profiles 66 interpolation = { 67 "server": "127.0.0.1:8888", 68 } 69 for k, v in expected_prefs.items(): 70 if isinstance(v, str): 71 v = v.format(**interpolation) 72 73 assert k in actual_prefs 74 assert k and actual_prefs[k] == v 75 76 77 if __name__ == "__main__": 78 mozunit.main()