Bug 1150818 - Part 1: Output mozinfo into a file. r=ted
authorHiroyuki Ikezoe <hiikezoe@mozilla-japan.org>
Thu, 20 Aug 2015 15:30:00 -0400
changeset 287145 a5c3c5566eecce1aaf5e8900f9bdd194e37d1754
parent 287144 329e51e19460c3a85d748041bf484878d7d2fbe5
child 287146 b0d464df0f0b9e22442bf157180d028b2b5a1c51
push id4660
push usermartin.thomson@gmail.com
push dateFri, 21 Aug 2015 22:37:38 +0000
reviewersted
bugs1150818
milestone43.0a1
Bug 1150818 - Part 1: Output mozinfo into a file. r=ted
testing/mozbase/mozinfo/mozinfo/mozinfo.py
testing/mozbase/mozinfo/tests/test.py
--- a/testing/mozbase/mozinfo/mozinfo/mozinfo.py
+++ b/testing/mozbase/mozinfo/mozinfo/mozinfo.py
@@ -210,28 +210,34 @@ def find_and_update_from_json(*dirs):
         d = _os.path.abspath(d)
         json_path = _os.path.join(d, "mozinfo.json")
         if _os.path.isfile(json_path):
             update(json_path)
             return json_path
 
     return None
 
+def output_to_file(path):
+    import json
+    with open(path, 'w') as f:
+        f.write(json.dumps(info));
+
 update({})
 
 # exports
 __all__ = info.keys()
 __all__ += ['is' + os_name.title() for os_name in choices['os']]
 __all__ += [
     'info',
     'unknown',
     'main',
     'choices',
     'update',
     'find_and_update_from_json',
+    'output_to_file',
     'StringVersion',
     ]
 
 def main(args=None):
 
     # parse the command line
     from optparse import OptionParser
     parser = OptionParser(description=__doc__)
--- a/testing/mozbase/mozinfo/tests/test.py
+++ b/testing/mozbase/mozinfo/tests/test.py
@@ -79,16 +79,22 @@ class TestMozinfo(unittest.TestCase):
             f.write(json.dumps({"foo": "123456"}))
         m = mock.MagicMock()
         # Mock the value of MozbuildObject.from_environment().topobjdir.
         m.MozbuildObject.from_environment.return_value.topobjdir = self.tempdir
         with mock.patch.dict(sys.modules, {"mozbuild": m, "mozbuild.base": m}):
             self.assertEqual(mozinfo.find_and_update_from_json(), j)
         self.assertEqual(mozinfo.info["foo"], "123456")
 
+    def test_output_to_file(self):
+        """Test that mozinfo.output_to_file works."""
+        path = os.path.join(self.tempdir, "mozinfo.json")
+        mozinfo.output_to_file(path)
+        self.assertEqual(open(path).read(), json.dumps(mozinfo.info))
+
 
 class TestStringVersion(unittest.TestCase):
     def test_os_version_is_a_StringVersion(self):
         self.assertIsInstance(mozinfo.os_version, mozinfo.StringVersion)
 
     def test_compare_to_string(self):
         version = mozinfo.StringVersion('10.10')