☠☠ backed out by cda7c3e91ad7 ☠ ☠ | |
author | Gregory Szorc <gps@mozilla.com> |
Mon, 26 Sep 2016 15:51:32 -0700 | |
changeset 316397 | 6ed46e8ac86c2347c7f78d53cc04595b35f40752 |
parent 316396 | 604451ab58290450155779b6692a92f30d76717d |
child 316398 | 43df1e962f8e833babb0bf1d71fc33d77be9f0a9 |
push id | 30770 |
push user | kwierso@gmail.com |
push date | Wed, 05 Oct 2016 00:00:48 +0000 |
treeherder | mozilla-central@3470e326025c [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | ted |
bugs | 1286900 |
milestone | 52.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
testing/mozbase/mozinfo/mozinfo/mozinfo.py | file | annotate | diff | comparison | revisions | |
testing/mozbase/mozinfo/tests/test.py | file | annotate | diff | comparison | revisions |
--- a/testing/mozbase/mozinfo/mozinfo/mozinfo.py +++ b/testing/mozbase/mozinfo/mozinfo/mozinfo.py @@ -196,23 +196,30 @@ def update(new_info): if isLinux or isBsd: globals()['isUnix'] = True def find_and_update_from_json(*dirs): """ Find a mozinfo.json file, load it, and update the info with the contents. - :param dirs: Directories in which to look for the file. They will be - searched after first looking in the root of the objdir - if the current script is being run from a Mozilla objdir. + The search strategy is as follows. The first available file is used. + + 1) MOZINFO_PATH environment variable. + 2) objdir (via a build system context) + 3) Traversing directories ``dirs`` for a mozinfo.json file. Returns the full path to mozinfo.json if it was found, or None otherwise. """ - # First, see if we're in an objdir + env_path = _os.environ.get('MOZINFO_PATH', None) + if env_path: + # Will raise if path does not exist or can't be loaded. + update(env_path) + return env_path + try: from mozbuild.base import MozbuildObject, BuildEnvironmentNotFoundException build = MozbuildObject.from_environment() json_path = _os.path.join(build.topobjdir, "mozinfo.json") if _os.path.isfile(json_path): update(json_path) return json_path except ImportError:
--- a/testing/mozbase/mozinfo/tests/test.py +++ b/testing/mozbase/mozinfo/tests/test.py @@ -48,16 +48,31 @@ class TestMozinfo(unittest.TestCase): def test_update_file_invalid_json(self): """Test that mozinfo.update handles invalid JSON correctly""" j = os.path.join(self.tempdir,'test.json') with open(j, 'w') as f: f.write('invalid{"json":') self.assertRaises(ValueError,mozinfo.update,[j]) + def test_find_and_update_file_env(self): + """mozinfo.find_and_update_json finds path from environment variable.""" + j = os.path.join(self.tempdir, 'explicit_mozinfo.json') + with open(j, 'w') as fh: + json.dump({'foo': 'environment'}, fh) + + old_env = dict(os.environ) + try: + os.environ['MOZINFO_PATH'] = j + self.assertEqual(mozinfo.find_and_update_from_json(), j) + self.assertEqual(mozinfo.info['foo'], 'environment') + finally: + os.environ.clear() + os.environ.update(old_env) + def test_find_and_update_file(self): """Test that mozinfo.find_and_update_from_json can find mozinfo.json in a directory passed to it.""" j = os.path.join(self.tempdir, "mozinfo.json") with open(j, "w") as f: f.write(json.dumps({"foo": "abcdefg"})) self.assertEqual(mozinfo.find_and_update_from_json(self.tempdir), j) self.assertEqual(mozinfo.info["foo"], "abcdefg")