Bug 1431024 - Modified error criterion check in prefs.py. r=wlach
authorVedant Chakravadhanula <vedantc98@gmail.com>
Fri, 26 Jan 2018 01:33:39 +0530
changeset 400981 a33edd4d85295696add792bdccd1626bc242f0a3
parent 400980 1edfa7376a6fa28282be22fa84e7d9ca3cd7d76e
child 400982 176a681a1788f12b17dbf66e04579564b2defc9b
push id99272
push userapavel@mozilla.com
push dateFri, 26 Jan 2018 17:52:07 +0000
treeherdermozilla-inbound@1ee8edcdd50d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswlach
bugs1431024
milestone60.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
Bug 1431024 - Modified error criterion check in prefs.py. r=wlach MozReview-Commit-ID: 6nEXiIQ7awD
testing/mozbase/mozprofile/mozprofile/prefs.py
testing/mozbase/mozprofile/tests/test_preferences.py
--- a/testing/mozbase/mozprofile/mozprofile/prefs.py
+++ b/testing/mozbase/mozprofile/mozprofile/prefs.py
@@ -143,17 +143,17 @@ class Preferences(object):
             if [i for i in prefs if type(i) != list or len(i) != 2]:
                 raise PreferencesReadError("Malformed preferences: %s" % path)
             values = [i[1] for i in prefs]
         elif isinstance(prefs, dict):
             values = prefs.values()
         else:
             raise PreferencesReadError("Malformed preferences: %s" % path)
         types = (bool, string_types, int)
-        if [i for i in values if not [isinstance(i, j) for j in types]]:
+        if [i for i in values if not any([isinstance(i, j) for j in types])]:
             raise PreferencesReadError("Only bool, string, and int values allowed")
         return prefs
 
     @classmethod
     def read_prefs(cls, path, pref_setter='user_pref', interpolation=None):
         """
         Read preferences from (e.g.) prefs.js
 
--- a/testing/mozbase/mozprofile/tests/test_preferences.py
+++ b/testing/mozbase/mozprofile/tests/test_preferences.py
@@ -11,17 +11,17 @@ import mozhttpd
 import os
 import shutil
 import tempfile
 import unittest
 
 import mozunit
 
 from mozprofile.cli import MozProfileCLI
-from mozprofile.prefs import Preferences
+from mozprofile.prefs import Preferences, PreferencesReadError
 from mozprofile.profile import Profile
 
 here = os.path.dirname(os.path.abspath(__file__))
 
 
 class PreferencesTest(unittest.TestCase):
     """test mozprofile preference handling"""
 
@@ -300,16 +300,27 @@ user_pref("webgl.force-enabled", true);
         # just repr it...could use the json module but we don't need it here
         with mozfile.NamedTemporaryFile(suffix='.json') as f:
             f.write(json)
             f.flush()
 
             commandline = ["--preferences", f.name]
             self.compare_generated(_prefs, commandline)
 
+    def test_json_datatypes(self):
+        # minPercent is at 30.1 to test if non-integer data raises an exception
+        json = """{"zoom.minPercent": 30.1, "zoom.maxPercent": 300}"""
+
+        with mozfile.NamedTemporaryFile(suffix='.json') as f:
+            f.write(json)
+            f.flush()
+
+            with self.assertRaises(PreferencesReadError):
+                Preferences.read_json(f._path)
+
     def test_prefs_write(self):
         """test that the Preferences.write() method correctly serializes preferences"""
 
         _prefs = {'browser.startup.homepage': "http://planet.mozilla.org",
                   'zoom.minPercent': 30,
                   'zoom.maxPercent': 300}
 
         # make a Preferences manager with the testing preferences